diff --git a/airflow/providers/oracle/hooks/oracle.py b/airflow/providers/oracle/hooks/oracle.py index 2b6bfdb00904c..bbf98fb405f83 100644 --- a/airflow/providers/oracle/hooks/oracle.py +++ b/airflow/providers/oracle/hooks/oracle.py @@ -275,9 +275,9 @@ def insert_rows( :param replace: Whether to replace instead of insert """ try: - import numpy + import numpy as np except ImportError: - numpy = None # type: ignore + np = None # type: ignore if target_fields: target_fields = ", ".join(target_fields) @@ -297,7 +297,7 @@ def insert_rows( lst.append("'" + str(cell).replace("'", "''") + "'") elif cell is None or isinstance(cell, float) and math.isnan(cell): # coerce numpy NaN to NULL lst.append("NULL") - elif numpy and isinstance(cell, numpy.datetime64): + elif np and isinstance(cell, np.datetime64): lst.append("'" + str(cell) + "'") elif isinstance(cell, datetime): lst.append(f"to_date('{cell:%Y-%m-%d %H:%M:%S}','YYYY-MM-DD HH24:MI:SS')") diff --git a/tests/providers/oracle/hooks/test_oracle.py b/tests/providers/oracle/hooks/test_oracle.py index 9f49618b45435..fa40ffcccb5cf 100644 --- a/tests/providers/oracle/hooks/test_oracle.py +++ b/tests/providers/oracle/hooks/test_oracle.py @@ -21,7 +21,7 @@ from datetime import datetime from unittest import mock -import numpy +import numpy as np import oracledb import pytest @@ -290,8 +290,8 @@ def test_insert_rows_with_fields(self): ( "'basestr_with_quote", None, - numpy.NAN, - numpy.datetime64("2019-01-24T01:02:03"), + np.NAN, + np.datetime64("2019-01-24T01:02:03"), datetime(2019, 1, 24), 1, 10.24, @@ -321,8 +321,8 @@ def test_insert_rows_without_fields(self): ( "'basestr_with_quote", None, - numpy.NAN, - numpy.datetime64("2019-01-24T01:02:03"), + np.NAN, + np.datetime64("2019-01-24T01:02:03"), datetime(2019, 1, 24), 1, 10.24, diff --git a/tests/providers/salesforce/hooks/test_salesforce.py b/tests/providers/salesforce/hooks/test_salesforce.py index b670856a4a7d8..2c437fdcb23cf 100644 --- a/tests/providers/salesforce/hooks/test_salesforce.py +++ b/tests/providers/salesforce/hooks/test_salesforce.py @@ -21,9 +21,9 @@ from unittest import mock from unittest.mock import Mock, patch +import numpy as np import pandas as pd import pytest -from numpy import nan from pytest import param from requests import Session as request_session from simple_salesforce import Salesforce, api @@ -340,7 +340,7 @@ def test_write_object_to_file_invalid_format(self): @patch( "pandas.DataFrame.from_records", - return_value=pd.DataFrame({"test": [1, 2, 3], "dict": [nan, nan, {"foo": "bar"}]}), + return_value=pd.DataFrame({"test": [1, 2, 3], "dict": [np.nan, np.nan, {"foo": "bar"}]}), ) def test_write_object_to_file_csv(self, mock_data_frame): mock_data_frame.return_value.to_csv = Mock() diff --git a/tests/serialization/serializers/test_serializers.py b/tests/serialization/serializers/test_serializers.py index 66f142e0ac0d3..62ec8f3d9fc62 100644 --- a/tests/serialization/serializers/test_serializers.py +++ b/tests/serialization/serializers/test_serializers.py @@ -19,7 +19,7 @@ import datetime import decimal -import numpy +import numpy as np import pendulum.tz import pytest from pendulum import DateTime @@ -81,7 +81,7 @@ def test_encode_k8s_v1pod(self): } def test_numpy(self): - i = numpy.int16(10) + i = np.int16(10) e = serialize(i) d = deserialize(e) assert i == d