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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 11 deletions
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

Lines changed: 4 additions & 13 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 7 additions & 9 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 2 additions & 4 deletions
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

0 commit comments

Comments
 (0)