Skip to content

Commit 6f75f72

Browse files
authored
CLN: address TODOs (#44305)
1 parent b36c1ae commit 6f75f72

File tree

20 files changed

+54
-84
lines changed

20 files changed

+54
-84
lines changed

pandas/_libs/hashtable.pyi

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -194,21 +194,6 @@ class StringHashTable(HashTable): ...
194194
class PyObjectHashTable(HashTable): ...
195195
class IntpHashTable(HashTable): ...
196196

197-
def duplicated_int64(
198-
values: np.ndarray, # const int64_t[:] values
199-
keep: Literal["last", "first", False] = ...,
200-
) -> npt.NDArray[np.bool_]: ...
201-
202-
# TODO: Is it actually bool or is it uint8?
203-
204-
def mode_int64(
205-
values: np.ndarray, # const int64_t[:] values
206-
dropna: bool,
207-
) -> npt.NDArray[np.int64]: ...
208-
def value_count_int64(
209-
values: np.ndarray, # const int64_t[:]
210-
dropna: bool,
211-
) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]: ...
212197
def duplicated(
213198
values: np.ndarray,
214199
keep: Literal["last", "first", False] = ...,

pandas/_libs/tslibs/offsets.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ cdef class Tick(SingleConstructorOffset):
777777
"Tick offset with `normalize=True` are not allowed."
778778
)
779779

780-
# FIXME: Without making this cpdef, we get AttributeError when calling
780+
# Note: Without making this cpdef, we get AttributeError when calling
781781
# from __mul__
782782
cpdef Tick _next_higher_resolution(Tick self):
783783
if type(self) is Day:

pandas/_libs/writers.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
from __future__ import annotations
2+
13
import numpy as np
24

3-
# TODO: can make this more specific
5+
from pandas._typing import ArrayLike
6+
47
def write_csv_rows(
5-
data: list,
8+
data: list[ArrayLike],
69
data_index: np.ndarray,
710
nlevels: int,
811
cols: np.ndarray,

pandas/_libs/writers.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def write_csv_rows(
3030

3131
Parameters
3232
----------
33-
data : list
33+
data : list[ArrayLike]
3434
data_index : ndarray
3535
nlevels : int
3636
cols : ndarray

pandas/core/array_algos/putmask.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def putmask_inplace(values: ArrayLike, mask: npt.NDArray[np.bool_], value: Any)
6565
np.putmask(values, mask, value)
6666

6767

68-
def putmask_smart(values: np.ndarray, mask: np.ndarray, new) -> np.ndarray:
68+
def putmask_smart(values: np.ndarray, mask: npt.NDArray[np.bool_], new) -> np.ndarray:
6969
"""
7070
Return a new ndarray, try to preserve dtype if possible.
7171
@@ -84,12 +84,11 @@ def putmask_smart(values: np.ndarray, mask: np.ndarray, new) -> np.ndarray:
8484
8585
See Also
8686
--------
87-
ndarray.putmask
87+
np.putmask
8888
"""
8989
# we cannot use np.asarray() here as we cannot have conversions
9090
# that numpy does when numeric are mixed with strings
9191

92-
# n should be the length of the mask or a scalar here
9392
if not is_list_like(new):
9493
new = np.broadcast_to(new, mask.shape)
9594

@@ -139,15 +138,17 @@ def putmask_smart(values: np.ndarray, mask: np.ndarray, new) -> np.ndarray:
139138
return _putmask_preserve(values, new, mask)
140139

141140

142-
def _putmask_preserve(new_values: np.ndarray, new, mask: np.ndarray):
141+
def _putmask_preserve(new_values: np.ndarray, new, mask: npt.NDArray[np.bool_]):
143142
try:
144143
new_values[mask] = new[mask]
145144
except (IndexError, ValueError):
146145
new_values[mask] = new
147146
return new_values
148147

149148

150-
def putmask_without_repeat(values: np.ndarray, mask: np.ndarray, new: Any) -> None:
149+
def putmask_without_repeat(
150+
values: np.ndarray, mask: npt.NDArray[np.bool_], new: Any
151+
) -> None:
151152
"""
152153
np.putmask will truncate or repeat if `new` is a listlike with
153154
len(new) != len(values). We require an exact match.
@@ -181,7 +182,9 @@ def putmask_without_repeat(values: np.ndarray, mask: np.ndarray, new: Any) -> No
181182
np.putmask(values, mask, new)
182183

183184

184-
def validate_putmask(values: ArrayLike, mask: np.ndarray) -> tuple[np.ndarray, bool]:
185+
def validate_putmask(
186+
values: ArrayLike, mask: np.ndarray
187+
) -> tuple[npt.NDArray[np.bool_], bool]:
185188
"""
186189
Validate mask and check if this putmask operation is a no-op.
187190
"""
@@ -193,7 +196,7 @@ def validate_putmask(values: ArrayLike, mask: np.ndarray) -> tuple[np.ndarray, b
193196
return mask, noop
194197

195198

196-
def extract_bool_array(mask: ArrayLike) -> np.ndarray:
199+
def extract_bool_array(mask: ArrayLike) -> npt.NDArray[np.bool_]:
197200
"""
198201
If we have a SparseArray or BooleanArray, convert it to ndarray[bool].
199202
"""

pandas/core/indexes/category.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ def fillna(self, value, downcast=None):
390390

391391
return type(self)._simple_new(cat, name=self.name)
392392

393+
# TODO(2.0): remove reindex once non-unique deprecation is enforced
393394
def reindex(
394395
self, target, method=None, level=None, limit=None, tolerance=None
395396
) -> tuple[Index, npt.NDArray[np.intp] | None]:

pandas/tests/arithmetic/test_timedelta64.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,6 @@ def test_float_series_rdiv_td64arr(self, box_with_array, names):
21322132

21332133
result = ser.__rtruediv__(tdi)
21342134
if box is DataFrame:
2135-
# TODO: Should we skip this case sooner or test something else?
21362135
assert result is NotImplemented
21372136
else:
21382137
tm.assert_equal(result, expected)

pandas/tests/arrays/categorical/test_replace.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
([1, 2, "3"], "5", ["5", "5", 3], True),
3030
],
3131
)
32-
def test_replace(to_replace, value, expected, flip_categories):
32+
def test_replace_categorical_series(to_replace, value, expected, flip_categories):
3333
# GH 31720
3434
stays_categorical = not isinstance(value, list) or len(pd.unique(value)) == 1
3535

36-
s = pd.Series([1, 2, 3], dtype="category")
37-
result = s.replace(to_replace, value)
36+
ser = pd.Series([1, 2, 3], dtype="category")
37+
result = ser.replace(to_replace, value)
3838
expected = pd.Series(expected, dtype="category")
39-
s.replace(to_replace, value, inplace=True)
39+
ser.replace(to_replace, value, inplace=True)
4040

4141
if flip_categories:
4242
expected = expected.cat.set_categories(expected.cat.categories[::-1])
@@ -46,7 +46,7 @@ def test_replace(to_replace, value, expected, flip_categories):
4646
expected = pd.Series(np.asarray(expected))
4747

4848
tm.assert_series_equal(expected, result, check_category_order=False)
49-
tm.assert_series_equal(expected, s, check_category_order=False)
49+
tm.assert_series_equal(expected, ser, check_category_order=False)
5050

5151

5252
@pytest.mark.parametrize(
@@ -59,8 +59,7 @@ def test_replace(to_replace, value, expected, flip_categories):
5959
("b", None, ["a", None], "Categorical.categories length are different"),
6060
],
6161
)
62-
def test_replace2(to_replace, value, result, expected_error_msg):
63-
# TODO: better name
62+
def test_replace_categorical(to_replace, value, result, expected_error_msg):
6463
# GH#26988
6564
cat = Categorical(["a", "b"])
6665
expected = Categorical(result)

pandas/tests/arrays/timedeltas/test_reductions.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,8 @@ def test_sum(self):
8484
assert isinstance(result, Timedelta)
8585
assert result == expected
8686

87-
# TODO: de-duplicate with test_npsum below
88-
def test_np_sum(self):
89-
# GH#25282
90-
vals = np.arange(5, dtype=np.int64).view("m8[h]").astype("m8[ns]")
91-
arr = TimedeltaArray(vals)
92-
result = np.sum(arr)
93-
assert result == vals.sum()
94-
95-
result = np.sum(pd.TimedeltaIndex(arr))
96-
assert result == vals.sum()
97-
9887
def test_npsum(self):
99-
# GH#25335 np.sum should return a Timedelta, not timedelta64
88+
# GH#25282, GH#25335 np.sum should return a Timedelta, not timedelta64
10089
tdi = pd.TimedeltaIndex(["3H", "3H", "2H", "5H", "4H"])
10190
arr = tdi.array
10291

pandas/tests/extension/decimal/test_decimal.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,12 @@ def test_series_repr(self, data):
174174
assert "Decimal: " in repr(ser)
175175

176176

177-
# TODO(extension)
178177
@pytest.mark.xfail(
179178
reason=(
180-
"raising AssertionError as this is not implemented, though easy enough to do"
181-
)
179+
"DecimalArray constructor raises bc _from_sequence wants Decimals, not ints."
180+
"Easy to fix, just need to do it."
181+
),
182+
raises=TypeError,
182183
)
183184
def test_series_constructor_coerce_data_to_extension_dtype_raises():
184185
xpr = (

pandas/tests/indexes/categorical/test_indexing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ def test_get_indexer_same_categories_different_order(self):
300300

301301

302302
class TestWhere:
303-
def test_where(self, listlike_box_with_tuple):
304-
klass = listlike_box_with_tuple
303+
def test_where(self, listlike_box):
304+
klass = listlike_box
305305

306306
i = CategoricalIndex(list("aabbca"), categories=list("cab"), ordered=False)
307307
cond = [True] * len(i)

pandas/tests/indexes/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ def test_numpy_repeat(self, simple_index):
375375
with pytest.raises(ValueError, match=msg):
376376
np.repeat(idx, rep, axis=0)
377377

378-
def test_where(self, listlike_box_with_tuple, simple_index):
379-
klass = listlike_box_with_tuple
378+
def test_where(self, listlike_box, simple_index):
379+
klass = listlike_box
380380

381381
idx = simple_index
382382
if isinstance(idx, (DatetimeIndex, TimedeltaIndex)):

pandas/tests/indexes/conftest.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,9 @@ def freq_sample(request):
3333
return request.param
3434

3535

36-
@pytest.fixture(params=[list, np.array, array, Series])
36+
@pytest.fixture(params=[list, tuple, np.array, array, Series])
3737
def listlike_box(request):
3838
"""
3939
Types that may be passed as the indexer to searchsorted.
4040
"""
4141
return request.param
42-
43-
44-
# TODO: not clear if this _needs_ to be different from listlike_box or
45-
# if that is just a historical artifact
46-
@pytest.fixture(params=[list, tuple, np.array, Series])
47-
def listlike_box_with_tuple(request):
48-
"""
49-
Types that may be passed as the indexer to searchsorted.
50-
"""
51-
return request.param

pandas/tests/indexes/interval/test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def test_take(self, closed):
4343
expected = IntervalIndex.from_arrays([0, 0, 1], [1, 1, 2], closed=closed)
4444
tm.assert_index_equal(result, expected)
4545

46-
def test_where(self, simple_index, listlike_box_with_tuple):
47-
klass = listlike_box_with_tuple
46+
def test_where(self, simple_index, listlike_box):
47+
klass = listlike_box
4848

4949
idx = simple_index
5050
cond = [True] * len(idx)

pandas/tests/indexes/multi/test_indexing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,12 +720,12 @@ def test_where(self):
720720
with pytest.raises(NotImplementedError, match=msg):
721721
i.where(True)
722722

723-
def test_where_array_like(self, listlike_box_with_tuple):
723+
def test_where_array_like(self, listlike_box):
724724
mi = MultiIndex.from_tuples([("A", 1), ("A", 2)])
725725
cond = [False, True]
726726
msg = r"\.where is not supported for MultiIndex operations"
727727
with pytest.raises(NotImplementedError, match=msg):
728-
mi.where(listlike_box_with_tuple(cond))
728+
mi.where(listlike_box(cond))
729729

730730

731731
class TestContains:

pandas/tests/indexes/numeric/test_indexing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,14 @@ class TestWhere:
397397
UInt64Index(np.arange(5, dtype="uint64")),
398398
],
399399
)
400-
def test_where(self, listlike_box_with_tuple, index):
400+
def test_where(self, listlike_box, index):
401401
cond = [True] * len(index)
402402
expected = index
403-
result = index.where(listlike_box_with_tuple(cond))
403+
result = index.where(listlike_box(cond))
404404

405405
cond = [False] + [True] * (len(index) - 1)
406406
expected = Float64Index([index._na_value] + index[1:].tolist())
407-
result = index.where(listlike_box_with_tuple(cond))
407+
result = index.where(listlike_box(cond))
408408
tm.assert_index_equal(result, expected)
409409

410410
def test_where_uint64(self):

pandas/tests/indexes/period/test_indexing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,16 +602,16 @@ def test_get_indexer2(self):
602602

603603

604604
class TestWhere:
605-
def test_where(self, listlike_box_with_tuple):
605+
def test_where(self, listlike_box):
606606
i = period_range("20130101", periods=5, freq="D")
607607
cond = [True] * len(i)
608608
expected = i
609-
result = i.where(listlike_box_with_tuple(cond))
609+
result = i.where(listlike_box(cond))
610610
tm.assert_index_equal(result, expected)
611611

612612
cond = [False] + [True] * (len(i) - 1)
613613
expected = PeriodIndex([NaT] + i[1:].tolist(), freq="D")
614-
result = i.where(listlike_box_with_tuple(cond))
614+
result = i.where(listlike_box(cond))
615615
tm.assert_index_equal(result, expected)
616616

617617
def test_where_other(self):

pandas/tests/io/formats/style/test_html.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ def test_replaced_css_class_names(styler_mi):
488488
uuid_len=0,
489489
).set_table_styles(css_class_names=css)
490490
styler_mi.index.names = ["n1", "n2"]
491-
styler_mi.hide_index(styler_mi.index[1:])
492-
styler_mi.hide_columns(styler_mi.columns[1:])
491+
styler_mi.hide(styler_mi.index[1:], axis=0)
492+
styler_mi.hide(styler_mi.columns[1:], axis=1)
493493
styler_mi.applymap_index(lambda v: "color: red;", axis=0)
494494
styler_mi.applymap_index(lambda v: "color: green;", axis=1)
495495
styler_mi.applymap(lambda v: "color: blue;")
@@ -611,9 +611,9 @@ def test_hiding_index_columns_multiindex_alignment():
611611
)
612612
df = DataFrame(np.arange(16).reshape(4, 4), index=midx, columns=cidx)
613613
styler = Styler(df, uuid_len=0)
614-
styler.hide_index(level=1).hide_columns(level=0)
615-
styler.hide_index([("j0", "i1", "j2")])
616-
styler.hide_columns([("c0", "d1", "d2")])
614+
styler.hide(level=1, axis=0).hide(level=0, axis=1)
615+
styler.hide([("j0", "i1", "j2")], axis=0)
616+
styler.hide([("c0", "d1", "d2")], axis=1)
617617
result = styler.to_html()
618618
expected = dedent(
619619
"""\

pandas/tests/io/formats/style/test_style.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ def test_hiding_headers_over_index_no_sparsify():
15301530
df = DataFrame(9, index=midx, columns=[0])
15311531
ctx = df.style._translate(False, False)
15321532
assert len(ctx["body"]) == 6
1533-
ctx = df.style.hide_index((1, "a"))._translate(False, False)
1533+
ctx = df.style.hide((1, "a"), axis=0)._translate(False, False)
15341534
assert len(ctx["body"]) == 4
15351535
assert "row2" in ctx["body"][0][0]["class"]
15361536

pandas/tests/io/formats/style/test_to_latex.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ def test_css_convert_apply_index(styler, axis):
803803

804804
def test_hide_index_latex(styler):
805805
# GH 43637
806-
styler.hide_index([0])
806+
styler.hide([0], axis=0)
807807
result = styler.to_latex()
808808
expected = dedent(
809809
"""\
@@ -826,9 +826,9 @@ def test_latex_hiding_index_columns_multiindex_alignment():
826826
)
827827
df = DataFrame(np.arange(16).reshape(4, 4), index=midx, columns=cidx)
828828
styler = Styler(df, uuid_len=0)
829-
styler.hide_index(level=1).hide_columns(level=0)
830-
styler.hide_index([("i0", "i1", "i2")])
831-
styler.hide_columns([("c0", "c1", "c2")])
829+
styler.hide(level=1, axis=0).hide(level=0, axis=1)
830+
styler.hide([("i0", "i1", "i2")], axis=0)
831+
styler.hide([("c0", "c1", "c2")], axis=1)
832832
styler.applymap(lambda x: "color:{red};" if x == 5 else "")
833833
styler.applymap_index(lambda x: "color:{blue};" if "j" in x else "")
834834
result = styler.to_latex()

0 commit comments

Comments
 (0)