Skip to content

Commit

Permalink
Refactor: Consolidate "import numpy as np" (apache#34111)
Browse files Browse the repository at this point in the history
  • Loading branch information
eumiro authored Sep 7, 2023
1 parent 4fa66d1 commit f47a2a8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions airflow/providers/oracle/hooks/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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')")
Expand Down
10 changes: 5 additions & 5 deletions tests/providers/oracle/hooks/test_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from datetime import datetime
from unittest import mock

import numpy
import numpy as np
import oracledb
import pytest

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/providers/salesforce/hooks/test_salesforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/serialization/serializers/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import datetime
import decimal

import numpy
import numpy as np
import pendulum.tz
import pytest
from pendulum import DateTime
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f47a2a8

Please sign in to comment.