Skip to content

Commit 878a022

Browse files
authored
CLN: TODOs/FIXMEs (#44717)
1 parent e992969 commit 878a022

File tree

15 files changed

+47
-65
lines changed

15 files changed

+47
-65
lines changed

asv_bench/benchmarks/frame_ctor.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
)
2020
except ImportError:
2121
# For compatibility with older versions
22-
from pandas.core.datetools import * # noqa
22+
from pandas.core.datetools import (
23+
Hour,
24+
Nano,
25+
)
2326

2427

2528
class FromDicts:

doc/source/whatsnew/v0.5.0.rst

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ New features
2828
- :ref:`Added <indexing.set_index>` convenience ``set_index`` function for creating a DataFrame index from its existing columns
2929
- :ref:`Implemented <groupby.multiindex>` ``groupby`` hierarchical index level name (:issue:`223`)
3030
- :ref:`Added <io.store_in_csv>` support for different delimiters in ``DataFrame.to_csv`` (:issue:`244`)
31-
- TODO: DOCS ABOUT TAKE METHODS
3231

3332
Performance enhancements
3433
~~~~~~~~~~~~~~~~~~~~~~~~

pandas/_libs/tslibs/offsets.pyx

-3
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,6 @@ cdef class RelativeDeltaOffset(BaseOffset):
11501150
def is_on_offset(self, dt: datetime) -> bool:
11511151
if self.normalize and not _is_normalized(dt):
11521152
return False
1153-
# TODO: see GH#1395
11541153
return True
11551154

11561155

@@ -2659,7 +2658,6 @@ cdef class WeekOfMonth(WeekOfMonthMixin):
26592658
def _from_name(cls, suffix=None):
26602659
if not suffix:
26612660
raise ValueError(f"Prefix {repr(cls._prefix)} requires a suffix.")
2662-
# TODO: handle n here...
26632661
# only one digit weeks (1 --> week 0, 2 --> week 1, etc.)
26642662
week = int(suffix[0]) - 1
26652663
weekday = weekday_to_int[suffix[1:]]
@@ -2725,7 +2723,6 @@ cdef class LastWeekOfMonth(WeekOfMonthMixin):
27252723
def _from_name(cls, suffix=None):
27262724
if not suffix:
27272725
raise ValueError(f"Prefix {repr(cls._prefix)} requires a suffix.")
2728-
# TODO: handle n here...
27292726
weekday = weekday_to_int[suffix]
27302727
return cls(weekday=weekday)
27312728

pandas/_typing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def closed(self) -> bool:
272272
# SequenceIndexer is for list like or slices (but not tuples)
273273
# PositionalIndexerTuple is extends the PositionalIndexer for 2D arrays
274274
# These are used in various __getitem__ overloads
275-
# TODO: add Ellipsis, see
275+
# TODO(typing#684): add Ellipsis, see
276276
# https://github.com/python/typing/issues/684#issuecomment-548203158
277277
# https://bugs.python.org/issue41810
278278
# Using List[int] here rather than Sequence[int] to disallow tuples.

pandas/core/dtypes/common.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ def _is_dtype_type(arr_or_dtype, condition) -> bool:
16201620
return condition(tipo)
16211621

16221622

1623-
def infer_dtype_from_object(dtype) -> DtypeObj:
1623+
def infer_dtype_from_object(dtype) -> type:
16241624
"""
16251625
Get a numpy dtype.type-style object for a dtype object.
16261626
@@ -1637,24 +1637,20 @@ def infer_dtype_from_object(dtype) -> DtypeObj:
16371637
16381638
Returns
16391639
-------
1640-
dtype_object : The extracted numpy dtype.type-style object.
1640+
type
16411641
"""
16421642
if isinstance(dtype, type) and issubclass(dtype, np.generic):
16431643
# Type object from a dtype
16441644

1645-
# error: Incompatible return value type (got "Type[generic]", expected
1646-
# "Union[dtype[Any], ExtensionDtype]")
1647-
return dtype # type: ignore[return-value]
1645+
return dtype
16481646
elif isinstance(dtype, (np.dtype, ExtensionDtype)):
16491647
# dtype object
16501648
try:
16511649
_validate_date_like_dtype(dtype)
16521650
except TypeError:
16531651
# Should still pass if we don't have a date-like
16541652
pass
1655-
# error: Incompatible return value type (got "Union[Type[generic], Type[Any]]",
1656-
# expected "Union[dtype[Any], ExtensionDtype]")
1657-
return dtype.type # type: ignore[return-value]
1653+
return dtype.type
16581654

16591655
try:
16601656
dtype = pandas_dtype(dtype)
@@ -1668,9 +1664,7 @@ def infer_dtype_from_object(dtype) -> DtypeObj:
16681664
# TODO(jreback)
16691665
# should deprecate these
16701666
if dtype in ["datetimetz", "datetime64tz"]:
1671-
# error: Incompatible return value type (got "Type[Any]", expected
1672-
# "Union[dtype[Any], ExtensionDtype]")
1673-
return DatetimeTZDtype.type # type: ignore[return-value]
1667+
return DatetimeTZDtype.type
16741668
elif dtype in ["period"]:
16751669
raise NotImplementedError
16761670

pandas/core/frame.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -4333,27 +4333,18 @@ def select_dtypes(self, include=None, exclude=None) -> DataFrame:
43334333

43344334
# convert the myriad valid dtypes object to a single representation
43354335
def check_int_infer_dtype(dtypes):
4336-
converted_dtypes = []
4336+
converted_dtypes: list[type] = []
43374337
for dtype in dtypes:
43384338
# Numpy maps int to different types (int32, in64) on Windows and Linux
43394339
# see https://github.com/numpy/numpy/issues/9464
43404340
if (isinstance(dtype, str) and dtype == "int") or (dtype is int):
43414341
converted_dtypes.append(np.int32)
4342-
# error: Argument 1 to "append" of "list" has incompatible type
4343-
# "Type[signedinteger[Any]]"; expected "Type[signedinteger[Any]]"
4344-
converted_dtypes.append(np.int64) # type: ignore[arg-type]
4342+
converted_dtypes.append(np.int64)
43454343
elif dtype == "float" or dtype is float:
43464344
# GH#42452 : np.dtype("float") coerces to np.float64 from Numpy 1.20
4347-
converted_dtypes.extend(
4348-
[np.float64, np.float32] # type: ignore[list-item]
4349-
)
4345+
converted_dtypes.extend([np.float64, np.float32])
43504346
else:
4351-
# error: Argument 1 to "append" of "list" has incompatible type
4352-
# "Union[dtype[Any], ExtensionDtype]"; expected
4353-
# "Type[signedinteger[Any]]"
4354-
converted_dtypes.append(
4355-
infer_dtype_from_object(dtype) # type: ignore[arg-type]
4356-
)
4347+
converted_dtypes.append(infer_dtype_from_object(dtype))
43574348
return frozenset(converted_dtypes)
43584349

43594350
include = check_int_infer_dtype(include)

pandas/core/indexes/interval.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,11 @@ def _get_indexer_pointwise(
727727
if isinstance(locs, slice):
728728
# Only needed for get_indexer_non_unique
729729
locs = np.arange(locs.start, locs.stop, locs.step, dtype="intp")
730-
elif not self.is_unique and not self.is_monotonic:
730+
elif lib.is_integer(locs):
731+
locs = np.array(locs, ndmin=1)
732+
else:
733+
# otherwise we have ndarray[bool]
731734
locs = np.where(locs)[0]
732-
locs = np.array(locs, ndmin=1)
733735
except KeyError:
734736
missing.append(i)
735737
locs = np.array([-1])

pandas/tests/base/test_value_counts.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def test_value_counts(index_or_series_obj):
3131
if isinstance(obj, pd.MultiIndex):
3232
expected.index = Index(expected.index)
3333

34-
# TODO: Order of entries with the same count is inconsistent on CI (gh-32449)
34+
# TODO(GH#32514): Order of entries with the same count is inconsistent
35+
# on CI (gh-32449)
3536
if obj.duplicated().any():
3637
result = result.sort_index()
3738
expected = expected.sort_index()
@@ -65,20 +66,17 @@ def test_value_counts_null(null_obj, index_or_series_obj):
6566

6667
result = obj.value_counts()
6768
if obj.duplicated().any():
68-
# TODO:
69+
# TODO(GH#32514):
6970
# Order of entries with the same count is inconsistent on CI (gh-32449)
7071
expected = expected.sort_index()
7172
result = result.sort_index()
7273
tm.assert_series_equal(result, expected)
7374

74-
# can't use expected[null_obj] = 3 as
75-
# IntervalIndex doesn't allow assignment
76-
new_entry = Series({np.nan: 3}, dtype=np.int64)
77-
expected = expected.append(new_entry)
75+
expected[null_obj] = 3
7876

7977
result = obj.value_counts(dropna=False)
8078
if obj.duplicated().any():
81-
# TODO:
79+
# TODO(GH#32514):
8280
# Order of entries with the same count is inconsistent on CI (gh-32449)
8381
expected = expected.sort_index()
8482
result = result.sort_index()
@@ -277,8 +275,8 @@ def test_value_counts_with_nan(dropna, index_or_series):
277275
# GH31944
278276
klass = index_or_series
279277
values = [True, pd.NA, np.nan]
280-
s = klass(values)
281-
res = s.value_counts(dropna=dropna)
278+
obj = klass(values)
279+
res = obj.value_counts(dropna=dropna)
282280
if dropna is True:
283281
expected = Series([1], index=[True])
284282
else:

pandas/tests/computation/test_eval.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,9 @@ def test_disallow_scalar_bool_ops(self):
673673
exprs += ("2 * x > 2 or 1 and 2",)
674674
exprs += ("2 * df > 3 and 1 or a",)
675675

676-
x, a, b, df = np.random.randn(3), 1, 2, DataFrame(np.random.randn(3, 2)) # noqa
676+
x, a, b = np.random.randn(3), 1, 2 # noqa:F841
677+
df = DataFrame(np.random.randn(3, 2)) # noqa:F841
678+
677679
for ex in exprs:
678680
msg = "cannot evaluate scalar only bool ops|'BoolOp' nodes are not"
679681
with pytest.raises(NotImplementedError, match=msg):
@@ -1167,9 +1169,8 @@ def test_single_variable(self):
11671169
tm.assert_frame_equal(df, df2)
11681170

11691171
def test_truediv(self):
1170-
s = np.array([1])
1172+
s = np.array([1]) # noqa:F841
11711173
ex = "s / 1"
1172-
d = {"s": s} # noqa
11731174

11741175
# FutureWarning: The `truediv` parameter in pd.eval is deprecated and will be
11751176
# removed in a future version.

pandas/tests/frame/methods/test_clip.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@ def test_dataframe_clip(self):
4444
assert (clipped_df.values[mask] == df.values[mask]).all()
4545

4646
def test_clip_mixed_numeric(self):
47-
# TODO(jreback)
4847
# clip on mixed integer or floats
49-
# with integer clippers coerces to float
48+
# GH#24162, clipping now preserves numeric types per column
5049
df = DataFrame({"A": [1, 2, 3], "B": [1.0, np.nan, 3.0]})
5150
result = df.clip(1, 2)
5251
expected = DataFrame({"A": [1, 2, 2], "B": [1.0, np.nan, 2.0]})
53-
tm.assert_frame_equal(result, expected, check_like=True)
52+
tm.assert_frame_equal(result, expected)
5453

55-
# GH#24162, clipping now preserves numeric types per column
5654
df = DataFrame([[1, 2, 3.4], [3, 4, 5.6]], columns=["foo", "bar", "baz"])
5755
expected = df.dtypes
5856
result = df.clip(upper=3).dtypes

pandas/tests/indexing/test_indexing.py

-2
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ def test_dups_fancy_indexing_only_missing_label(self):
277277
):
278278
dfnu.loc[["E"]]
279279

280-
# TODO: check_index_type can be True after GH 11497
281-
282280
@pytest.mark.parametrize("vals", [[0, 1, 2], list("abc")])
283281
def test_dups_fancy_indexing_missing_label(self, vals):
284282

pandas/tests/plotting/test_series.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -722,12 +722,12 @@ def test_custom_business_day_freq(self):
722722

723723
@pytest.mark.xfail(reason="TODO: reason?")
724724
def test_plot_accessor_updates_on_inplace(self):
725-
s = Series([1, 2, 3, 4])
725+
ser = Series([1, 2, 3, 4])
726726
_, ax = self.plt.subplots()
727-
ax = s.plot(ax=ax)
727+
ax = ser.plot(ax=ax)
728728
before = ax.xaxis.get_ticklocs()
729729

730-
s.drop([0, 1], inplace=True)
730+
ser.drop([0, 1], inplace=True)
731731
_, ax = self.plt.subplots()
732732
after = ax.xaxis.get_ticklocs()
733733
tm.assert_numpy_array_equal(before, after)

pandas/tests/series/methods/test_fillna.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ def test_fillna_nat(self):
6161
tm.assert_frame_equal(filled, expected)
6262
tm.assert_frame_equal(filled2, expected)
6363

64-
def test_fillna(self, datetime_series):
64+
def test_fillna_value_or_method(self, datetime_series):
65+
msg = "Cannot specify both 'value' and 'method'"
66+
with pytest.raises(ValueError, match=msg):
67+
datetime_series.fillna(value=0, method="ffill")
68+
69+
def test_fillna(self):
6570
ts = Series([0.0, 1.0, 2.0, 3.0, 4.0], index=tm.makeDateIndex(5))
6671

6772
tm.assert_series_equal(ts, ts.fillna(method="ffill"))
@@ -81,10 +86,7 @@ def test_fillna(self, datetime_series):
8186
with pytest.raises(ValueError, match=msg):
8287
ts.fillna()
8388

84-
msg = "Cannot specify both 'value' and 'method'"
85-
with pytest.raises(ValueError, match=msg):
86-
datetime_series.fillna(value=0, method="ffill")
87-
89+
def test_fillna_nonscalar(self):
8890
# GH#5703
8991
s1 = Series([np.nan])
9092
s2 = Series([1])
@@ -108,13 +110,14 @@ def test_fillna(self, datetime_series):
108110
result = s1.fillna(Series({0: 1, 1: 1}, index=[4, 5]))
109111
tm.assert_series_equal(result, s1)
110112

113+
def test_fillna_aligns(self):
111114
s1 = Series([0, 1, 2], list("abc"))
112115
s2 = Series([0, np.nan, 2], list("bac"))
113116
result = s2.fillna(s1)
114117
expected = Series([0, 0, 2.0], list("bac"))
115118
tm.assert_series_equal(result, expected)
116119

117-
# limit
120+
def test_fillna_limit(self):
118121
ser = Series(np.nan, index=[0, 1, 2])
119122
result = ser.fillna(999, limit=1)
120123
expected = Series([999, np.nan, np.nan], index=[0, 1, 2])
@@ -124,6 +127,7 @@ def test_fillna(self, datetime_series):
124127
expected = Series([999, 999, np.nan], index=[0, 1, 2])
125128
tm.assert_series_equal(result, expected)
126129

130+
def test_fillna_dont_cast_strings(self):
127131
# GH#9043
128132
# make sure a string representation of int/float values can be filled
129133
# correctly without raising errors or being converted
@@ -320,6 +324,7 @@ def test_datetime64_fillna(self):
320324
)
321325
tm.assert_series_equal(result, expected)
322326

327+
def test_datetime64_fillna_backfill(self):
323328
# GH#6587
324329
# make sure that we are treating as integer when filling
325330
msg = "containing strings is deprecated"
@@ -774,7 +779,7 @@ def test_fillna_datetime64_with_timezone_tzinfo(self):
774779
with tm.assert_produces_warning(FutureWarning, match="mismatched timezone"):
775780
result = ser2.fillna(ts)
776781
expected = Series([ser[0], ts, ser[2]], dtype=object)
777-
# once deprecation is enforced
782+
# TODO(2.0): once deprecation is enforced
778783
# expected = Series(
779784
# [ser2[0], ts.tz_convert(ser2.dtype.tz), ser2[2]],
780785
# dtype=ser2.dtype,

pandas/tests/series/test_constructors.py

-4
Original file line numberDiff line numberDiff line change
@@ -1491,10 +1491,6 @@ def test_convert_non_ns(self):
14911491
tm.assert_series_equal(s, expected)
14921492

14931493
# convert from a numpy array of non-ns datetime64
1494-
# note that creating a numpy datetime64 is in LOCAL time!!!!
1495-
# seems to work for M8[D], but not for M8[s]
1496-
# TODO: is the above comment still accurate/needed?
1497-
14981494
arr = np.array(
14991495
["2013-01-01", "2013-01-02", "2013-01-03"], dtype="datetime64[D]"
15001496
)

pandas/tests/series/test_ufunc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_binary_ufunc_scalar(ufunc, sparse, flip, arrays_for_binary_ufunc):
167167
tm.assert_series_equal(result, expected)
168168

169169

170-
@pytest.mark.parametrize("ufunc", [np.divmod]) # TODO: any others?
170+
@pytest.mark.parametrize("ufunc", [np.divmod]) # TODO: np.modf, np.frexp
171171
@pytest.mark.parametrize("sparse", SPARSE, ids=SPARSE_IDS)
172172
@pytest.mark.parametrize("shuffle", SHUFFLE)
173173
@pytest.mark.filterwarnings("ignore:divide by zero:RuntimeWarning")

0 commit comments

Comments
 (0)