Skip to content

Commit 7c00e0c

Browse files
authored
CLN/TST: address TODOs/FIXMES pandas-dev#2 (pandas-dev#44174)
1 parent d8440f1 commit 7c00e0c

File tree

10 files changed

+59
-104
lines changed

10 files changed

+59
-104
lines changed

pandas/core/groupby/groupby.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1517,8 +1517,11 @@ def _cython_agg_general(
15171517
if numeric_only:
15181518
if is_ser and not is_numeric_dtype(self._selected_obj.dtype):
15191519
# GH#41291 match Series behavior
1520+
kwd_name = "numeric_only"
1521+
if how in ["any", "all"]:
1522+
kwd_name = "bool_only"
15201523
raise NotImplementedError(
1521-
f"{type(self).__name__}.{how} does not implement numeric_only."
1524+
f"{type(self).__name__}.{how} does not implement {kwd_name}."
15221525
)
15231526
elif not is_ser:
15241527
data = data.get_numeric_data(copy=False)

pandas/core/indexes/range.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,7 @@ def _intersection(self, other: Index, sort=False):
600600
new_index = new_index[::-1]
601601

602602
if sort is None:
603-
# TODO: can revert to just `if sort is None` after GH#43666
604-
if new_index.step < 0:
605-
new_index = new_index[::-1]
603+
new_index = new_index.sort_values()
606604

607605
return new_index
608606

pandas/core/series.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -4169,7 +4169,7 @@ def map(self, arg, na_action=None) -> Series:
41694169
3 I am a rabbit
41704170
dtype: object
41714171
"""
4172-
new_values = super()._map_values(arg, na_action=na_action)
4172+
new_values = self._map_values(arg, na_action=na_action)
41734173
return self._constructor(new_values, index=self.index).__finalize__(
41744174
self, method="map"
41754175
)
@@ -4396,8 +4396,11 @@ def _reduce(
43964396
else:
43974397
# dispatch to numpy arrays
43984398
if numeric_only:
4399+
kwd_name = "numeric_only"
4400+
if name in ["any", "all"]:
4401+
kwd_name = "bool_only"
43994402
raise NotImplementedError(
4400-
f"Series.{name} does not implement numeric_only."
4403+
f"Series.{name} does not implement {kwd_name}."
44014404
)
44024405
with np.errstate(all="ignore"):
44034406
return op(delegate, skipna=skipna, **kwds)

pandas/tests/extension/decimal/test_decimal.py

+13-61
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import decimal
2-
import math
32
import operator
43

54
import numpy as np
@@ -70,54 +69,7 @@ def data_for_grouping():
7069
return DecimalArray([b, b, na, na, a, a, b, c])
7170

7271

73-
class BaseDecimal:
74-
@classmethod
75-
def assert_series_equal(cls, left, right, *args, **kwargs):
76-
def convert(x):
77-
# need to convert array([Decimal(NaN)], dtype='object') to np.NaN
78-
# because Series[object].isnan doesn't recognize decimal(NaN) as
79-
# NA.
80-
try:
81-
return math.isnan(x)
82-
except TypeError:
83-
return False
84-
85-
if left.dtype == "object":
86-
left_na = left.apply(convert)
87-
else:
88-
left_na = left.isna()
89-
if right.dtype == "object":
90-
right_na = right.apply(convert)
91-
else:
92-
right_na = right.isna()
93-
94-
tm.assert_series_equal(left_na, right_na)
95-
return tm.assert_series_equal(left[~left_na], right[~right_na], *args, **kwargs)
96-
97-
@classmethod
98-
def assert_frame_equal(cls, left, right, *args, **kwargs):
99-
# TODO(EA): select_dtypes
100-
tm.assert_index_equal(
101-
left.columns,
102-
right.columns,
103-
exact=kwargs.get("check_column_type", "equiv"),
104-
check_names=kwargs.get("check_names", True),
105-
check_exact=kwargs.get("check_exact", False),
106-
check_categorical=kwargs.get("check_categorical", True),
107-
obj=f"{kwargs.get('obj', 'DataFrame')}.columns",
108-
)
109-
110-
decimals = (left.dtypes == "decimal").index
111-
112-
for col in decimals:
113-
cls.assert_series_equal(left[col], right[col], *args, **kwargs)
114-
115-
left = left.drop(columns=decimals)
116-
right = right.drop(columns=decimals)
117-
tm.assert_frame_equal(left, right, *args, **kwargs)
118-
119-
120-
class TestDtype(BaseDecimal, base.BaseDtypeTests):
72+
class TestDtype(base.BaseDtypeTests):
12173
def test_hashable(self, dtype):
12274
pass
12375

@@ -129,27 +81,27 @@ def test_infer_dtype(self, data, data_missing, skipna):
12981
assert infer_dtype(data_missing, skipna=skipna) == "unknown-array"
13082

13183

132-
class TestInterface(BaseDecimal, base.BaseInterfaceTests):
84+
class TestInterface(base.BaseInterfaceTests):
13385
pass
13486

13587

136-
class TestConstructors(BaseDecimal, base.BaseConstructorsTests):
88+
class TestConstructors(base.BaseConstructorsTests):
13789
pass
13890

13991

140-
class TestReshaping(BaseDecimal, base.BaseReshapingTests):
92+
class TestReshaping(base.BaseReshapingTests):
14193
pass
14294

14395

144-
class TestGetitem(BaseDecimal, base.BaseGetitemTests):
96+
class TestGetitem(base.BaseGetitemTests):
14597
def test_take_na_value_other_decimal(self):
14698
arr = DecimalArray([decimal.Decimal("1.0"), decimal.Decimal("2.0")])
14799
result = arr.take([0, -1], allow_fill=True, fill_value=decimal.Decimal("-1.0"))
148100
expected = DecimalArray([decimal.Decimal("1.0"), decimal.Decimal("-1.0")])
149101
self.assert_extension_array_equal(result, expected)
150102

151103

152-
class TestMissing(BaseDecimal, base.BaseMissingTests):
104+
class TestMissing(base.BaseMissingTests):
153105
pass
154106

155107

@@ -175,7 +127,7 @@ class TestBooleanReduce(Reduce, base.BaseBooleanReduceTests):
175127
pass
176128

177129

178-
class TestMethods(BaseDecimal, base.BaseMethodsTests):
130+
class TestMethods(base.BaseMethodsTests):
179131
@pytest.mark.parametrize("dropna", [True, False])
180132
def test_value_counts(self, all_data, dropna, request):
181133
all_data = all_data[:10]
@@ -200,20 +152,20 @@ def test_value_counts_with_normalize(self, data):
200152
return super().test_value_counts_with_normalize(data)
201153

202154

203-
class TestCasting(BaseDecimal, base.BaseCastingTests):
155+
class TestCasting(base.BaseCastingTests):
204156
pass
205157

206158

207-
class TestGroupby(BaseDecimal, base.BaseGroupbyTests):
159+
class TestGroupby(base.BaseGroupbyTests):
208160
def test_groupby_agg_extension(self, data_for_grouping):
209161
super().test_groupby_agg_extension(data_for_grouping)
210162

211163

212-
class TestSetitem(BaseDecimal, base.BaseSetitemTests):
164+
class TestSetitem(base.BaseSetitemTests):
213165
pass
214166

215167

216-
class TestPrinting(BaseDecimal, base.BasePrintingTests):
168+
class TestPrinting(base.BasePrintingTests):
217169
def test_series_repr(self, data):
218170
# Overriding this base test to explicitly test that
219171
# the custom _formatter is used
@@ -282,7 +234,7 @@ def test_astype_dispatches(frame):
282234
assert result.dtype.context.prec == ctx.prec
283235

284236

285-
class TestArithmeticOps(BaseDecimal, base.BaseArithmeticOpsTests):
237+
class TestArithmeticOps(base.BaseArithmeticOpsTests):
286238
def check_opname(self, s, op_name, other, exc=None):
287239
super().check_opname(s, op_name, other, exc=None)
288240

@@ -313,7 +265,7 @@ def _check_divmod_op(self, s, op, other, exc=NotImplementedError):
313265
super()._check_divmod_op(s, op, other, exc=None)
314266

315267

316-
class TestComparisonOps(BaseDecimal, base.BaseComparisonOpsTests):
268+
class TestComparisonOps(base.BaseComparisonOpsTests):
317269
def test_compare_scalar(self, data, all_compare_operators):
318270
op_name = all_compare_operators
319271
s = pd.Series(data)

pandas/tests/frame/methods/test_shift.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def test_shift_axis1_multiple_blocks_with_int_fill(self):
211211

212212
@pytest.mark.filterwarnings("ignore:tshift is deprecated:FutureWarning")
213213
def test_tshift(self, datetime_frame):
214-
# TODO: remove this test when tshift deprecation is enforced
214+
# TODO(2.0): remove this test when tshift deprecation is enforced
215215

216216
# PeriodIndex
217217
ps = tm.makePeriodFrame()

pandas/tests/frame/test_constructors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2508,7 +2508,7 @@ def check_views():
25082508
# TODO: we can call check_views if we stop consolidating
25092509
# in setitem_with_indexer
25102510

2511-
# FIXME: until GH#35417, iloc.setitem into EA values does not preserve
2511+
# FIXME(GH#35417): until GH#35417, iloc.setitem into EA values does not preserve
25122512
# view, so we have to check in the other direction
25132513
# df.iloc[0, 2] = 0
25142514
# if not copy:
@@ -2522,7 +2522,7 @@ def check_views():
25222522
else:
25232523
assert a[0] == a.dtype.type(1)
25242524
assert b[0] == b.dtype.type(3)
2525-
# FIXME: enable after GH#35417
2525+
# FIXME(GH#35417): enable after GH#35417
25262526
# assert c[0] == 1
25272527
assert df.iloc[0, 2] == 1
25282528
else:

pandas/tests/reductions/test_reductions.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -929,13 +929,11 @@ def test_all_any_params(self):
929929
with tm.assert_produces_warning(FutureWarning):
930930
s.all(bool_only=True, level=0)
931931

932-
# bool_only is not implemented alone.
933-
# TODO GH38810 change this error message to:
934-
# "Series.any does not implement bool_only"
935-
msg = "Series.any does not implement numeric_only"
932+
# GH#38810 bool_only is not implemented alone.
933+
msg = "Series.any does not implement bool_only"
936934
with pytest.raises(NotImplementedError, match=msg):
937935
s.any(bool_only=True)
938-
msg = "Series.all does not implement numeric_only."
936+
msg = "Series.all does not implement bool_only."
939937
with pytest.raises(NotImplementedError, match=msg):
940938
s.all(bool_only=True)
941939

pandas/tests/series/methods/test_rename.py

+29-27
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ def test_rename(self, datetime_series):
2222
renamed2 = ts.rename(rename_dict)
2323
tm.assert_series_equal(renamed, renamed2)
2424

25+
def test_rename_partial_dict(self):
2526
# partial dict
26-
s = Series(np.arange(4), index=["a", "b", "c", "d"], dtype="int64")
27-
renamed = s.rename({"b": "foo", "d": "bar"})
27+
ser = Series(np.arange(4), index=["a", "b", "c", "d"], dtype="int64")
28+
renamed = ser.rename({"b": "foo", "d": "bar"})
2829
tm.assert_index_equal(renamed.index, Index(["a", "foo", "c", "bar"]))
2930

31+
def test_rename_retain_index_name(self):
3032
# index with name
3133
renamer = Series(
3234
np.arange(4), index=Index(["a", "b", "c", "d"], name="name"), dtype="int64"
@@ -35,38 +37,38 @@ def test_rename(self, datetime_series):
3537
assert renamed.index.name == renamer.index.name
3638

3739
def test_rename_by_series(self):
38-
s = Series(range(5), name="foo")
40+
ser = Series(range(5), name="foo")
3941
renamer = Series({1: 10, 2: 20})
40-
result = s.rename(renamer)
42+
result = ser.rename(renamer)
4143
expected = Series(range(5), index=[0, 10, 20, 3, 4], name="foo")
4244
tm.assert_series_equal(result, expected)
4345

4446
def test_rename_set_name(self):
45-
s = Series(range(4), index=list("abcd"))
47+
ser = Series(range(4), index=list("abcd"))
4648
for name in ["foo", 123, 123.0, datetime(2001, 11, 11), ("foo",)]:
47-
result = s.rename(name)
49+
result = ser.rename(name)
4850
assert result.name == name
49-
tm.assert_numpy_array_equal(result.index.values, s.index.values)
50-
assert s.name is None
51+
tm.assert_numpy_array_equal(result.index.values, ser.index.values)
52+
assert ser.name is None
5153

5254
def test_rename_set_name_inplace(self):
53-
s = Series(range(3), index=list("abc"))
55+
ser = Series(range(3), index=list("abc"))
5456
for name in ["foo", 123, 123.0, datetime(2001, 11, 11), ("foo",)]:
55-
s.rename(name, inplace=True)
56-
assert s.name == name
57+
ser.rename(name, inplace=True)
58+
assert ser.name == name
5759

5860
exp = np.array(["a", "b", "c"], dtype=np.object_)
59-
tm.assert_numpy_array_equal(s.index.values, exp)
61+
tm.assert_numpy_array_equal(ser.index.values, exp)
6062

6163
def test_rename_axis_supported(self):
6264
# Supporting axis for compatibility, detailed in GH-18589
63-
s = Series(range(5))
64-
s.rename({}, axis=0)
65-
s.rename({}, axis="index")
66-
# FIXME: dont leave commenred-out
65+
ser = Series(range(5))
66+
ser.rename({}, axis=0)
67+
ser.rename({}, axis="index")
68+
# FIXME: dont leave commented-out
6769
# TODO: clean up shared index validation
6870
# with pytest.raises(ValueError, match="No axis named 5"):
69-
# s.rename({}, axis=5)
71+
# ser.rename({}, axis=5)
7072

7173
def test_rename_inplace(self, datetime_series):
7274
renamer = lambda x: x.strftime("%Y%m%d")
@@ -81,24 +83,24 @@ class MyIndexer:
8183
pass
8284

8385
ix = MyIndexer()
84-
s = Series([1, 2, 3]).rename(ix)
85-
assert s.name is ix
86+
ser = Series([1, 2, 3]).rename(ix)
87+
assert ser.name is ix
8688

8789
def test_rename_with_custom_indexer_inplace(self):
8890
# GH 27814
8991
class MyIndexer:
9092
pass
9193

9294
ix = MyIndexer()
93-
s = Series([1, 2, 3])
94-
s.rename(ix, inplace=True)
95-
assert s.name is ix
95+
ser = Series([1, 2, 3])
96+
ser.rename(ix, inplace=True)
97+
assert ser.name is ix
9698

9799
def test_rename_callable(self):
98100
# GH 17407
99-
s = Series(range(1, 6), index=Index(range(2, 7), name="IntIndex"))
100-
result = s.rename(str)
101-
expected = s.rename(lambda i: str(i))
101+
ser = Series(range(1, 6), index=Index(range(2, 7), name="IntIndex"))
102+
result = ser.rename(str)
103+
expected = ser.rename(lambda i: str(i))
102104
tm.assert_series_equal(result, expected)
103105

104106
assert result.name == expected.name
@@ -111,8 +113,8 @@ def test_rename_series_with_multiindex(self):
111113
]
112114

113115
index = MultiIndex.from_arrays(arrays, names=["first", "second"])
114-
s = Series(np.ones(5), index=index)
115-
result = s.rename(index={"one": "yes"}, level="second", errors="raise")
116+
ser = Series(np.ones(5), index=index)
117+
result = ser.rename(index={"one": "yes"}, level="second", errors="raise")
116118

117119
arrays_expected = [
118120
["bar", "baz", "baz", "foo", "qux"],

pandas/tests/series/methods/test_shift.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def test_shift_dst(self):
202202

203203
@pytest.mark.filterwarnings("ignore:tshift is deprecated:FutureWarning")
204204
def test_tshift(self, datetime_series):
205-
# TODO: remove this test when tshift deprecation is enforced
205+
# TODO(2.0): remove this test when tshift deprecation is enforced
206206

207207
# PeriodIndex
208208
ps = tm.makePeriodSeries()

pandas/tests/strings/test_api.py

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def test_api_per_method(
7171
inferred_dtype, values = any_allowed_skipna_inferred_dtype
7272
method_name, args, kwargs = any_string_method
7373

74-
# TODO: get rid of these xfails
7574
reason = None
7675
if box is Index and values.size == 0:
7776
if method_name in ["partition", "rpartition"] and kwargs.get("expand", True):

0 commit comments

Comments
 (0)