Skip to content

Commit 9c421f0

Browse files
authored
CLN: TODOs and FIXMEs (#44479)
1 parent 05ccc98 commit 9c421f0

File tree

19 files changed

+159
-178
lines changed

19 files changed

+159
-178
lines changed

pandas/core/arrays/datetimelike.py

-2
Original file line numberDiff line numberDiff line change
@@ -1466,8 +1466,6 @@ def max(self, *, axis: int | None = None, skipna: bool = True, **kwargs):
14661466
Index.max : Return the maximum value in an Index.
14671467
Series.max : Return the maximum value in a Series.
14681468
"""
1469-
# TODO: skipna is broken with max.
1470-
# See https://github.com/pandas-dev/pandas/issues/24265
14711469
nv.validate_max((), kwargs)
14721470
nv.validate_minmax_axis(axis, self.ndim)
14731471

pandas/core/arrays/masked.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ def value_counts(self, dropna: bool = True) -> Series:
605605
data = self._data[~self._mask]
606606
value_counts = Index(data).value_counts()
607607

608-
# TODO(extension)
608+
# TODO(ExtensionIndex)
609609
# if we have allow Index to hold an ExtensionArray
610610
# this is easier
611611
index = value_counts.index._values.astype(object)

pandas/core/groupby/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ def _wrap_applied_output_series(
10391039
key_index,
10401040
) -> DataFrame | Series:
10411041
# this is to silence a DeprecationWarning
1042-
# TODO: Remove when default dtype of empty Series is object
1042+
# TODO(2.0): Remove when default dtype of empty Series is object
10431043
kwargs = first_not_none._construct_axes_dict()
10441044
backup = create_series_with_explicit_dtype(dtype_if_empty=object, **kwargs)
10451045
values = [x if (x is not None) else backup for x in values]

pandas/core/groupby/groupby.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3337,7 +3337,8 @@ def pct_change(self, periods=1, fill_method="pad", limit=None, freq=None, axis=0
33373337
Series or DataFrame
33383338
Percentage changes within each group.
33393339
"""
3340-
# TODO: Remove this conditional for SeriesGroupBy when GH#23918 is fixed
3340+
# TODO(GH#23918): Remove this conditional for SeriesGroupBy when
3341+
# GH#23918 is fixed
33413342
if freq is not None or axis != 0:
33423343
return self.apply(
33433344
lambda x: x.pct_change(

pandas/core/groupby/ops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,8 @@ def result_arraylike(self) -> ArrayLike:
868868
Analogous to result_index, but returning an ndarray/ExtensionArray
869869
allowing us to retain ExtensionDtypes not supported by Index.
870870
"""
871-
# TODO: once Index supports arbitrary EAs, this can be removed in favor
872-
# of result_index
871+
# TODO(ExtensionIndex): once Index supports arbitrary EAs, this can
872+
# be removed in favor of result_index
873873
if len(self.groupings) == 1:
874874
return self.groupings[0].group_arraylike
875875

pandas/core/internals/managers.py

-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@
8080
operate_blockwise,
8181
)
8282

83-
# TODO: flexible with index=None and/or items=None
84-
8583
T = TypeVar("T", bound="BaseBlockManager")
8684

8785

pandas/core/nanops.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -1781,16 +1781,20 @@ def na_accum_func(values: ArrayLike, accum_func, *, skipna: bool) -> ArrayLike:
17811781
# We need to define mask before masking NaTs
17821782
mask = isna(values)
17831783

1784-
if accum_func == np.minimum.accumulate:
1785-
# Note: the accum_func comparison fails as an "is" comparison
1786-
y = values.view("i8")
1787-
y[mask] = lib.i8max
1788-
changed = True
1789-
else:
1790-
y = values
1791-
changed = False
1784+
y = values.view("i8")
1785+
# Note: the accum_func comparison fails as an "is" comparison
1786+
changed = accum_func == np.minimum.accumulate
1787+
1788+
try:
1789+
if changed:
1790+
y[mask] = lib.i8max
1791+
1792+
result = accum_func(y, axis=0)
1793+
finally:
1794+
if changed:
1795+
# restore NaT elements
1796+
y[mask] = iNaT
17921797

1793-
result = accum_func(y.view("i8"), axis=0)
17941798
if skipna:
17951799
result[mask] = iNaT
17961800
elif accum_func == np.minimum.accumulate:
@@ -1800,10 +1804,6 @@ def na_accum_func(values: ArrayLike, accum_func, *, skipna: bool) -> ArrayLike:
18001804
# everything up to the first non-na entry stays NaT
18011805
result[: nz[0]] = iNaT
18021806

1803-
if changed:
1804-
# restore NaT elements
1805-
y[mask] = iNaT # TODO: could try/finally for this?
1806-
18071807
if isinstance(values.dtype, np.dtype):
18081808
result = result.view(orig_dtype)
18091809
else:

pandas/io/sas/sas7bdat.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,14 @@ class _Column:
103103
col_id: int
104104
name: str | bytes
105105
label: str | bytes
106-
format: str | bytes # TODO: i think allowing bytes is from py2 days
106+
format: str | bytes
107107
ctype: bytes
108108
length: int
109109

110110
def __init__(
111111
self,
112112
col_id: int,
113+
# These can be bytes when convert_header_text is False
113114
name: str | bytes,
114115
label: str | bytes,
115116
format: str | bytes,

pandas/io/sql.py

-3
Original file line numberDiff line numberDiff line change
@@ -2158,9 +2158,6 @@ def to_sql(
21582158
table.insert(chunksize, method)
21592159

21602160
def has_table(self, name: str, schema: str | None = None):
2161-
# TODO(wesm): unused?
2162-
# escape = _get_valid_sqlite_name
2163-
# esc_name = escape(name)
21642161

21652162
wld = "?"
21662163
query = f"SELECT name FROM sqlite_master WHERE type='table' AND name={wld};"

pandas/tests/apply/test_series_apply.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -794,18 +794,15 @@ def test_apply_to_timedelta():
794794
list_of_valid_strings = ["00:00:01", "00:00:02"]
795795
a = pd.to_timedelta(list_of_valid_strings)
796796
b = Series(list_of_valid_strings).apply(pd.to_timedelta)
797-
# FIXME: dont leave commented-out
798-
# Can't compare until apply on a Series gives the correct dtype
799-
# assert_series_equal(a, b)
797+
tm.assert_series_equal(Series(a), b)
800798

801799
list_of_strings = ["00:00:01", np.nan, pd.NaT, pd.NaT]
802800

803-
a = pd.to_timedelta(list_of_strings) # noqa
801+
a = pd.to_timedelta(list_of_strings)
804802
with tm.assert_produces_warning(FutureWarning, match="Inferring timedelta64"):
805803
ser = Series(list_of_strings)
806-
b = ser.apply(pd.to_timedelta) # noqa
807-
# Can't compare until apply on a Series gives the correct dtype
808-
# assert_series_equal(a, b)
804+
b = ser.apply(pd.to_timedelta)
805+
tm.assert_series_equal(Series(a), b)
809806

810807

811808
@pytest.mark.parametrize(

pandas/tests/arrays/floating/test_arithmetic.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,16 @@ def test_error_invalid_values(data, all_arithmetic_operators):
142142
with pytest.raises(TypeError, match=msg):
143143
ops(pd.Series("foo", index=s.index))
144144

145-
if op != "__rpow__":
146-
# TODO(extension)
147-
# rpow with a datetimelike coerces the integer array incorrectly
148-
msg = (
149-
"can only perform ops with numeric values|"
150-
"cannot perform .* with this index type: DatetimeArray|"
145+
msg = "|".join(
146+
[
147+
"can only perform ops with numeric values",
148+
"cannot perform .* with this index type: DatetimeArray",
151149
"Addition/subtraction of integers and integer-arrays "
152-
"with DatetimeArray is no longer supported. *"
153-
)
154-
with pytest.raises(TypeError, match=msg):
155-
ops(pd.Series(pd.date_range("20180101", periods=len(s))))
150+
"with DatetimeArray is no longer supported. *",
151+
]
152+
)
153+
with pytest.raises(TypeError, match=msg):
154+
ops(pd.Series(pd.date_range("20180101", periods=len(s))))
156155

157156

158157
# Various

pandas/tests/arrays/integer/test_arithmetic.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,16 @@ def test_error_invalid_values(data, all_arithmetic_operators):
179179
with pytest.raises(TypeError, match=msg):
180180
ops(pd.Series("foo", index=s.index))
181181

182-
if op != "__rpow__":
183-
# TODO(extension)
184-
# rpow with a datetimelike coerces the integer array incorrectly
185-
msg = (
186-
"can only perform ops with numeric values|"
187-
"cannot perform .* with this index type: DatetimeArray|"
182+
msg = "|".join(
183+
[
184+
"can only perform ops with numeric values",
185+
"cannot perform .* with this index type: DatetimeArray",
188186
"Addition/subtraction of integers and integer-arrays "
189-
"with DatetimeArray is no longer supported. *"
190-
)
191-
with pytest.raises(TypeError, match=msg):
192-
ops(pd.Series(pd.date_range("20180101", periods=len(s))))
187+
"with DatetimeArray is no longer supported. *",
188+
]
189+
)
190+
with pytest.raises(TypeError, match=msg):
191+
ops(pd.Series(pd.date_range("20180101", periods=len(s))))
193192

194193

195194
# Various

pandas/tests/arrays/test_datetimes.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ def test_cmp_dt64_arraylike_tznaive(self, comparison_op):
3333

3434
result = op(arr, arr)
3535
tm.assert_numpy_array_equal(result, expected)
36-
for other in [right, np.array(right)]:
37-
# TODO: add list and tuple, and object-dtype once those
38-
# are fixed in the constructor
36+
for other in [
37+
right,
38+
np.array(right),
39+
list(right),
40+
tuple(right),
41+
right.astype(object),
42+
]:
3943
result = op(arr, other)
4044
tm.assert_numpy_array_equal(result, expected)
4145

pandas/tests/frame/test_arithmetic.py

+19-22
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,8 @@ def test_binop_other(self, op, value, dtype, switch_numexpr_min_elements):
925925
(operator.mul, "bool"),
926926
}
927927

928-
e = DummyElement(value, dtype)
929-
s = DataFrame({"A": [e.value, e.value]}, dtype=e.dtype)
928+
elem = DummyElement(value, dtype)
929+
df = DataFrame({"A": [elem.value, elem.value]}, dtype=elem.dtype)
930930

931931
invalid = {
932932
(operator.pow, "<M8[ns]"),
@@ -960,7 +960,7 @@ def test_binop_other(self, op, value, dtype, switch_numexpr_min_elements):
960960

961961
with pytest.raises(TypeError, match=msg):
962962
with tm.assert_produces_warning(warn):
963-
op(s, e.value)
963+
op(df, elem.value)
964964

965965
elif (op, dtype) in skip:
966966

@@ -971,19 +971,17 @@ def test_binop_other(self, op, value, dtype, switch_numexpr_min_elements):
971971
else:
972972
warn = None
973973
with tm.assert_produces_warning(warn):
974-
op(s, e.value)
974+
op(df, elem.value)
975975

976976
else:
977977
msg = "operator '.*' not implemented for .* dtypes"
978978
with pytest.raises(NotImplementedError, match=msg):
979-
op(s, e.value)
979+
op(df, elem.value)
980980

981981
else:
982-
# FIXME: Since dispatching to Series, this test no longer
983-
# asserts anything meaningful
984982
with tm.assert_produces_warning(None):
985-
result = op(s, e.value).dtypes
986-
expected = op(s, value).dtypes
983+
result = op(df, elem.value).dtypes
984+
expected = op(df, value).dtypes
987985
tm.assert_series_equal(result, expected)
988986

989987

@@ -1240,9 +1238,7 @@ def test_combineFrame(self, float_frame, mixed_float_frame, mixed_int_frame):
12401238
added = float_frame + mixed_int_frame
12411239
_check_mixed_float(added, dtype="float64")
12421240

1243-
def test_combine_series(
1244-
self, float_frame, mixed_float_frame, mixed_int_frame, datetime_frame
1245-
):
1241+
def test_combine_series(self, float_frame, mixed_float_frame, mixed_int_frame):
12461242

12471243
# Series
12481244
series = float_frame.xs(float_frame.index[0])
@@ -1272,17 +1268,18 @@ def test_combine_series(
12721268
added = mixed_float_frame + series.astype("float16")
12731269
_check_mixed_float(added, dtype={"C": None})
12741270

1275-
# FIXME: don't leave commented-out
1276-
# these raise with numexpr.....as we are adding an int64 to an
1277-
# uint64....weird vs int
1278-
1279-
# added = mixed_int_frame + (100*series).astype('int64')
1280-
# _check_mixed_int(added, dtype = {"A": 'int64', "B": 'float64', "C":
1281-
# 'int64', "D": 'int64'})
1282-
# added = mixed_int_frame + (100*series).astype('int32')
1283-
# _check_mixed_int(added, dtype = {"A": 'int32', "B": 'float64', "C":
1284-
# 'int32', "D": 'int64'})
1271+
# these used to raise with numexpr as we are adding an int64 to an
1272+
# uint64....weird vs int
1273+
added = mixed_int_frame + (100 * series).astype("int64")
1274+
_check_mixed_int(
1275+
added, dtype={"A": "int64", "B": "float64", "C": "int64", "D": "int64"}
1276+
)
1277+
added = mixed_int_frame + (100 * series).astype("int32")
1278+
_check_mixed_int(
1279+
added, dtype={"A": "int32", "B": "float64", "C": "int32", "D": "int64"}
1280+
)
12851281

1282+
def test_combine_timeseries(self, datetime_frame):
12861283
# TimeSeries
12871284
ts = datetime_frame["A"]
12881285

pandas/tests/indexes/datetimes/methods/test_insert.py

-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ def test_insert_mismatched_types_raises(self, tz_aware_fixture, item):
236236
result = dti.insert(1, item)
237237

238238
if isinstance(item, np.ndarray):
239-
# FIXME: without doing .item() here this segfaults
240239
assert item.item() == 0
241240
expected = Index([dti[0], 0] + list(dti[1:]), dtype=object, name=9)
242241
else:

pandas/tests/indexes/multi/test_formats.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ def test_unicode_repr_issues(self):
8787
index = MultiIndex(levels=levels, codes=codes)
8888

8989
repr(index.levels)
90-
91-
# FIXME: dont leave commented-out
92-
# NumPy bug
93-
# repr(index.get_level_values(1))
90+
repr(index.get_level_values(1))
9491

9592
def test_repr_max_seq_items_equal_to_n(self, idx):
9693
# display.max_seq_items == n

pandas/tests/series/methods/test_convert.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ def test_convert(self):
108108
result = ser._convert(datetime=True)
109109
tm.assert_series_equal(result, expected)
110110

111-
# preserver if non-object
111+
# preserve if non-object
112112
ser = Series([1], dtype="float32")
113113
result = ser._convert(datetime=True)
114114
tm.assert_series_equal(result, ser)
115115

116116
# FIXME: dont leave commented-out
117117
# res = ser.copy()
118-
# r[0] = np.nan
119-
# result = res._convert(convert_dates=True,convert_numeric=False)
118+
# res[0] = np.nan
119+
# result = res._convert(datetime=True, numeric=False)
120120
# assert result.dtype == 'M8[ns]'
121121

122122
def test_convert_no_arg_error(self):

pandas/tests/series/test_arithmetic.py

-12
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,6 @@ def test_add_corner_cases(self, datetime_series):
244244
result = empty + empty.copy()
245245
assert len(result) == 0
246246

247-
# FIXME: dont leave commented-out
248-
# TODO: this returned NotImplemented earlier, what to do?
249-
# deltas = Series([timedelta(1)] * 5, index=np.arange(5))
250-
# sub_deltas = deltas[::2]
251-
# deltas5 = deltas * 5
252-
# deltas = deltas + sub_deltas
253-
254247
def test_add_float_plus_int(self, datetime_series):
255248
# float + int
256249
int_ts = datetime_series.astype(int)[:-5]
@@ -613,11 +606,6 @@ def test_comparison_operators_with_nas(self, comparison_op):
613606

614607
tm.assert_series_equal(result, expected)
615608

616-
# FIXME: dont leave commented-out
617-
# result = comparison_op(val, ser)
618-
# expected = comparison_op(val, ser.dropna()).reindex(ser.index)
619-
# tm.assert_series_equal(result, expected)
620-
621609
def test_ne(self):
622610
ts = Series([3, 4, 5, 6, 7], [3, 4, 5, 6, 7], dtype=float)
623611
expected = [True, True, False, True, True]

0 commit comments

Comments
 (0)