Skip to content

CI: Check for inconsistent pandas namespace usage #37188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Oct 21, 2020
Merged
11 changes: 11 additions & 0 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ function invgrep {
return $((! $EXIT_STATUS))
}

function check_namespace {
local -r CLASS="${1}"
grep -R -l --include "*.py" " ${CLASS}(" pandas/tests | xargs grep -n "pd\.${CLASS}("
test $? -gt 0
}

if [[ "$GITHUB_ACTIONS" == "true" ]]; then
FLAKE8_FORMAT="##[error]%(path)s:%(row)s:%(col)s:%(code)s:%(text)s"
INVGREP_PREPEND="##[error]"
Expand Down Expand Up @@ -195,6 +201,11 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
MSG='Check code for instances of os.remove' ; echo $MSG
invgrep -R --include="*.py*" --exclude "common.py" --exclude "test_writers.py" --exclude "test_store.py" -E "os\.remove" pandas/tests/
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Check for inconsistent use of pandas namespace in tests' ; echo $MSG
check_namespace "Series"
RET=$(($RET + $?))
echo $MSG "DONE"
fi

### CODE ###
Expand Down
26 changes: 12 additions & 14 deletions pandas/tests/arithmetic/test_datetime64.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ def test_dt64arr_nat_comparison(self, tz_naive_fixture, box_with_array):
xbox = box if box not in [pd.Index, pd.array] else np.ndarray

ts = pd.Timestamp.now(tz)
ser = pd.Series([ts, pd.NaT])
ser = Series([ts, pd.NaT])

obj = tm.box_expected(ser, box)

expected = pd.Series([True, False], dtype=np.bool_)
expected = Series([True, False], dtype=np.bool_)
expected = tm.box_expected(expected, xbox)

result = obj == ts
Expand Down Expand Up @@ -278,7 +278,7 @@ def test_series_comparison_scalars(self, val):
def test_timestamp_compare_series(self, left, right):
# see gh-4982
# Make sure we can compare Timestamps on the right AND left hand side.
ser = pd.Series(pd.date_range("20010101", periods=10), name="dates")
ser = Series(pd.date_range("20010101", periods=10), name="dates")
s_nat = ser.copy(deep=True)

ser[0] = pd.Timestamp("nat")
Expand Down Expand Up @@ -313,7 +313,7 @@ def test_dt64arr_timestamp_equality(self, box_with_array):
box_with_array if box_with_array not in [pd.Index, pd.array] else np.ndarray
)

ser = pd.Series([pd.Timestamp("2000-01-29 01:59:00"), "NaT"])
ser = Series([pd.Timestamp("2000-01-29 01:59:00"), "NaT"])
ser = tm.box_expected(ser, box_with_array)

result = ser != ser
Expand Down Expand Up @@ -973,7 +973,7 @@ def test_dt64arr_sub_timestamp(self, box_with_array):

ser = tm.box_expected(ser, box_with_array)

delta_series = pd.Series([np.timedelta64(0, "D"), np.timedelta64(1, "D")])
delta_series = Series([np.timedelta64(0, "D"), np.timedelta64(1, "D")])
expected = tm.box_expected(delta_series, box_with_array)

tm.assert_equal(ser - ts, expected)
Expand All @@ -985,15 +985,15 @@ def test_dt64arr_sub_NaT(self, box_with_array):
ser = tm.box_expected(dti, box_with_array)

result = ser - pd.NaT
expected = pd.Series([pd.NaT, pd.NaT], dtype="timedelta64[ns]")
expected = Series([pd.NaT, pd.NaT], dtype="timedelta64[ns]")
expected = tm.box_expected(expected, box_with_array)
tm.assert_equal(result, expected)

dti_tz = dti.tz_localize("Asia/Tokyo")
ser_tz = tm.box_expected(dti_tz, box_with_array)

result = ser_tz - pd.NaT
expected = pd.Series([pd.NaT, pd.NaT], dtype="timedelta64[ns]")
expected = Series([pd.NaT, pd.NaT], dtype="timedelta64[ns]")
expected = tm.box_expected(expected, box_with_array)
tm.assert_equal(result, expected)

Expand Down Expand Up @@ -1606,7 +1606,7 @@ def test_dt64_series_arith_overflow(self):
dt = pd.Timestamp("1700-01-31")
td = pd.Timedelta("20000 Days")
dti = pd.date_range("1949-09-30", freq="100Y", periods=4)
ser = pd.Series(dti)
ser = Series(dti)
msg = "Overflow in int64 addition"
with pytest.raises(OverflowError, match=msg):
ser - dt
Expand All @@ -1618,7 +1618,7 @@ def test_dt64_series_arith_overflow(self):
td + ser

ser.iloc[-1] = pd.NaT
expected = pd.Series(
expected = Series(
["2004-10-03", "2104-10-04", "2204-10-04", "NaT"], dtype="datetime64[ns]"
)
res = ser + td
Expand All @@ -1627,9 +1627,7 @@ def test_dt64_series_arith_overflow(self):
tm.assert_series_equal(res, expected)

ser.iloc[1:] = pd.NaT
expected = pd.Series(
["91279 Days", "NaT", "NaT", "NaT"], dtype="timedelta64[ns]"
)
expected = Series(["91279 Days", "NaT", "NaT", "NaT"], dtype="timedelta64[ns]")
res = ser - dt
tm.assert_series_equal(res, expected)
res = dt - ser
Expand Down Expand Up @@ -1830,8 +1828,8 @@ def test_dt64tz_series_sub_dtitz(self):
# GH#19071 subtracting tzaware DatetimeIndex from tzaware Series
# (with same tz) raises, fixed by #19024
dti = pd.date_range("1999-09-30", periods=10, tz="US/Pacific")
ser = pd.Series(dti)
expected = pd.Series(pd.TimedeltaIndex(["0days"] * 10))
ser = Series(dti)
expected = Series(pd.TimedeltaIndex(["0days"] * 10))

res = dti - ser
tm.assert_series_equal(res, expected)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arithmetic/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,6 @@ def test_index_series_compat(self, op, constructor, expected_type, assert_func):
def test_comparison_operations(self, scalars):
# GH #28981
expected = Series([False, False])
s = pd.Series([pd.Interval(0, 1), pd.Interval(1, 2)], dtype="interval")
s = Series([pd.Interval(0, 1), pd.Interval(1, 2)], dtype="interval")
result = s == scalars
tm.assert_series_equal(result, expected)
Loading