Skip to content

Commit

Permalink
Make numpy effectively an optional dependency for Oracle provider
Browse files Browse the repository at this point in the history
Better fix to apache#23132
  • Loading branch information
potiuk committed Jun 7, 2022
1 parent c3a9ef1 commit 6988b56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions airflow/providers/oracle/hooks/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
# specific language governing permissions and limitations
# under the License.

import math
import warnings
from datetime import datetime
from typing import Dict, List, Optional, Union

import cx_Oracle
import numpy

try:
import numpy
except ImportError:
numpy = None # type: ignore

from airflow.hooks.dbapi import DbApiHook

Expand Down Expand Up @@ -211,9 +216,9 @@ def insert_rows(
lst.append("'" + str(cell).replace("'", "''") + "'")
elif cell is None:
lst.append('NULL')
elif isinstance(cell, float) and numpy.isnan(cell): # coerce numpy NaN to NULL
elif isinstance(cell, float) and math.isnan(cell): # coerce numpy NaN to NULL
lst.append('NULL')
elif isinstance(cell, numpy.datetime64):
elif numpy and isinstance(cell, numpy.datetime64):
lst.append("'" + str(cell) + "'")
elif isinstance(cell, datetime):
lst.append(
Expand Down
3 changes: 3 additions & 0 deletions airflow/providers/oracle/provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ integrations:
logo: /integration-logos/oracle/Oracle.png
tags: [software]

additional-extras:
numpy: numpy

operators:
- integration-name: Oracle
python-modules:
Expand Down

0 comments on commit 6988b56

Please sign in to comment.