Skip to content

Commit ef65e6c

Browse files
dsaxtonKevin D Smith
authored and
Kevin D Smith
committed
CI: Check for inconsistent pandas namespace usage (pandas-dev#37188)
* CI: Check for inconsistent pandas namespace usage * Make a function * Remove * Try making it fail * Add message * Fix * Make pass * Try something * Remove sed * Edit * Switch file * Revert * Global Series fix * More * Remove
1 parent 68f5a8a commit ef65e6c

File tree

136 files changed

+1231
-1251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+1231
-1251
lines changed

ci/code_checks.sh

+11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ function invgrep {
3737
return $((! $EXIT_STATUS))
3838
}
3939

40+
function check_namespace {
41+
local -r CLASS="${1}"
42+
grep -R -l --include "*.py" " ${CLASS}(" pandas/tests | xargs grep -n "pd\.${CLASS}("
43+
test $? -gt 0
44+
}
45+
4046
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
4147
FLAKE8_FORMAT="##[error]%(path)s:%(row)s:%(col)s:%(code)s:%(text)s"
4248
INVGREP_PREPEND="##[error]"
@@ -195,6 +201,11 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
195201
MSG='Check code for instances of os.remove' ; echo $MSG
196202
invgrep -R --include="*.py*" --exclude "common.py" --exclude "test_writers.py" --exclude "test_store.py" -E "os\.remove" pandas/tests/
197203
RET=$(($RET + $?)) ; echo $MSG "DONE"
204+
205+
MSG='Check for inconsistent use of pandas namespace in tests' ; echo $MSG
206+
check_namespace "Series"
207+
RET=$(($RET + $?))
208+
echo $MSG "DONE"
198209
fi
199210

200211
### CODE ###

pandas/tests/arithmetic/test_datetime64.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ def test_dt64arr_nat_comparison(self, tz_naive_fixture, box_with_array):
140140
xbox = box if box not in [pd.Index, pd.array] else np.ndarray
141141

142142
ts = pd.Timestamp.now(tz)
143-
ser = pd.Series([ts, pd.NaT])
143+
ser = Series([ts, pd.NaT])
144144

145145
obj = tm.box_expected(ser, box)
146146

147-
expected = pd.Series([True, False], dtype=np.bool_)
147+
expected = Series([True, False], dtype=np.bool_)
148148
expected = tm.box_expected(expected, xbox)
149149

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

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

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

319319
result = ser != ser
@@ -973,7 +973,7 @@ def test_dt64arr_sub_timestamp(self, box_with_array):
973973

974974
ser = tm.box_expected(ser, box_with_array)
975975

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

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

987987
result = ser - pd.NaT
988-
expected = pd.Series([pd.NaT, pd.NaT], dtype="timedelta64[ns]")
988+
expected = Series([pd.NaT, pd.NaT], dtype="timedelta64[ns]")
989989
expected = tm.box_expected(expected, box_with_array)
990990
tm.assert_equal(result, expected)
991991

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

995995
result = ser_tz - pd.NaT
996-
expected = pd.Series([pd.NaT, pd.NaT], dtype="timedelta64[ns]")
996+
expected = Series([pd.NaT, pd.NaT], dtype="timedelta64[ns]")
997997
expected = tm.box_expected(expected, box_with_array)
998998
tm.assert_equal(result, expected)
999999

@@ -1606,7 +1606,7 @@ def test_dt64_series_arith_overflow(self):
16061606
dt = pd.Timestamp("1700-01-31")
16071607
td = pd.Timedelta("20000 Days")
16081608
dti = pd.date_range("1949-09-30", freq="100Y", periods=4)
1609-
ser = pd.Series(dti)
1609+
ser = Series(dti)
16101610
msg = "Overflow in int64 addition"
16111611
with pytest.raises(OverflowError, match=msg):
16121612
ser - dt
@@ -1618,7 +1618,7 @@ def test_dt64_series_arith_overflow(self):
16181618
td + ser
16191619

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

16291629
ser.iloc[1:] = pd.NaT
1630-
expected = pd.Series(
1631-
["91279 Days", "NaT", "NaT", "NaT"], dtype="timedelta64[ns]"
1632-
)
1630+
expected = Series(["91279 Days", "NaT", "NaT", "NaT"], dtype="timedelta64[ns]")
16331631
res = ser - dt
16341632
tm.assert_series_equal(res, expected)
16351633
res = dt - ser
@@ -1830,8 +1828,8 @@ def test_dt64tz_series_sub_dtitz(self):
18301828
# GH#19071 subtracting tzaware DatetimeIndex from tzaware Series
18311829
# (with same tz) raises, fixed by #19024
18321830
dti = pd.date_range("1999-09-30", periods=10, tz="US/Pacific")
1833-
ser = pd.Series(dti)
1834-
expected = pd.Series(pd.TimedeltaIndex(["0days"] * 10))
1831+
ser = Series(dti)
1832+
expected = Series(pd.TimedeltaIndex(["0days"] * 10))
18351833

18361834
res = dti - ser
18371835
tm.assert_series_equal(res, expected)

pandas/tests/arithmetic/test_interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,6 @@ def test_index_series_compat(self, op, constructor, expected_type, assert_func):
290290
def test_comparison_operations(self, scalars):
291291
# GH #28981
292292
expected = Series([False, False])
293-
s = pd.Series([pd.Interval(0, 1), pd.Interval(1, 2)], dtype="interval")
293+
s = Series([pd.Interval(0, 1), pd.Interval(1, 2)], dtype="interval")
294294
result = s == scalars
295295
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)