Skip to content

Commit 00d4dfc

Browse files
jbrockmendeljreback
authored andcommitted
CLN: Remove unused _isfinite, make_axis_dummies (#29380)
1 parent 137d9e9 commit 00d4dfc

File tree

4 files changed

+1
-112
lines changed

4 files changed

+1
-112
lines changed

pandas/core/nanops.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
is_any_int_dtype,
1717
is_bool_dtype,
1818
is_complex,
19-
is_complex_dtype,
2019
is_datetime64_dtype,
2120
is_datetime64tz_dtype,
2221
is_datetime_or_timedelta_dtype,
@@ -325,19 +324,6 @@ def _get_values(
325324
return values, mask, dtype, dtype_max, fill_value
326325

327326

328-
def _isfinite(values):
329-
if is_datetime_or_timedelta_dtype(values):
330-
return isna(values)
331-
if (
332-
is_complex_dtype(values)
333-
or is_float_dtype(values)
334-
or is_integer_dtype(values)
335-
or is_bool_dtype(values)
336-
):
337-
return ~np.isfinite(values)
338-
return ~np.isfinite(values.astype("float64"))
339-
340-
341327
def _na_ok_dtype(dtype):
342328
# TODO: what about datetime64tz? PeriodDtype?
343329
return not issubclass(dtype.type, (np.integer, np.timedelta64, np.datetime64))

pandas/core/reshape/reshape.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,43 +1046,7 @@ def _make_col_name(prefix, prefix_sep, level):
10461046
return DataFrame(dummy_mat, index=index, columns=dummy_cols)
10471047

10481048

1049-
def make_axis_dummies(frame, axis="minor", transform=None):
1050-
"""
1051-
Construct 1-0 dummy variables corresponding to designated axis
1052-
labels
1053-
1054-
Parameters
1055-
----------
1056-
frame : DataFrame
1057-
axis : {'major', 'minor'}, default 'minor'
1058-
transform : function, default None
1059-
Function to apply to axis labels first. For example, to
1060-
get "day of week" dummies in a time series regression
1061-
you might call::
1062-
1063-
make_axis_dummies(panel, axis='major',
1064-
transform=lambda d: d.weekday())
1065-
Returns
1066-
-------
1067-
dummies : DataFrame
1068-
Column names taken from chosen axis
1069-
"""
1070-
numbers = {"major": 0, "minor": 1}
1071-
num = numbers.get(axis, axis)
1072-
1073-
items = frame.index.levels[num]
1074-
codes = frame.index.codes[num]
1075-
if transform is not None:
1076-
mapped_items = items.map(transform)
1077-
codes, items = _factorize_from_iterable(mapped_items.take(codes))
1078-
1079-
values = np.eye(len(items), dtype=float)
1080-
values = values.take(codes, axis=0)
1081-
1082-
return DataFrame(values, columns=items, index=frame.index)
1083-
1084-
1085-
def _reorder_for_extension_array_stack(arr, n_rows, n_columns):
1049+
def _reorder_for_extension_array_stack(arr, n_rows: int, n_columns: int):
10861050
"""
10871051
Re-orders the values when stacking multiple extension-arrays.
10881052

pandas/tests/reshape/test_reshape.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -645,24 +645,3 @@ def test_reshaping_multi_index_categorical(self):
645645
index=dti.rename("major"),
646646
)
647647
tm.assert_frame_equal(result, expected)
648-
649-
650-
class TestMakeAxisDummies:
651-
def test_preserve_categorical_dtype(self):
652-
# GH13854
653-
for ordered in [False, True]:
654-
cidx = pd.CategoricalIndex(list("xyz"), ordered=ordered)
655-
midx = pd.MultiIndex(levels=[["a"], cidx], codes=[[0, 0], [0, 1]])
656-
df = DataFrame([[10, 11]], index=midx)
657-
658-
expected = DataFrame(
659-
[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]], index=midx, columns=cidx
660-
)
661-
662-
from pandas.core.reshape.reshape import make_axis_dummies
663-
664-
result = make_axis_dummies(df)
665-
tm.assert_frame_equal(result, expected)
666-
667-
result = make_axis_dummies(df, transform=lambda x: x)
668-
tm.assert_frame_equal(result, expected)

pandas/tests/test_nanops.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -704,46 +704,6 @@ def test__has_infs(self):
704704
self.check_bool(nanops._has_infs, val.astype("f4"), correct)
705705
self.check_bool(nanops._has_infs, val.astype("f2"), correct)
706706

707-
def test__isfinite(self):
708-
pairs = [
709-
("arr_complex", False),
710-
("arr_int", False),
711-
("arr_bool", False),
712-
("arr_str", False),
713-
("arr_utf", False),
714-
("arr_complex", False),
715-
("arr_complex_nan", True),
716-
("arr_nan_nanj", True),
717-
("arr_nan_infj", True),
718-
("arr_complex_nan_infj", True),
719-
]
720-
pairs_float = [
721-
("arr_float", False),
722-
("arr_nan", True),
723-
("arr_float_nan", True),
724-
("arr_nan_nan", True),
725-
("arr_float_inf", True),
726-
("arr_inf", True),
727-
("arr_nan_inf", True),
728-
("arr_float_nan_inf", True),
729-
("arr_nan_nan_inf", True),
730-
]
731-
732-
func1 = lambda x: np.any(nanops._isfinite(x).ravel())
733-
734-
# TODO: unused?
735-
# func2 = lambda x: np.any(nanops._isfinite(x).values.ravel())
736-
737-
for arr, correct in pairs:
738-
val = getattr(self, arr)
739-
self.check_bool(func1, val, correct)
740-
741-
for arr, correct in pairs_float:
742-
val = getattr(self, arr)
743-
self.check_bool(func1, val, correct)
744-
self.check_bool(func1, val.astype("f4"), correct)
745-
self.check_bool(func1, val.astype("f2"), correct)
746-
747707
def test__bn_ok_dtype(self):
748708
assert nanops._bn_ok_dtype(self.arr_float.dtype, "test")
749709
assert nanops._bn_ok_dtype(self.arr_complex.dtype, "test")

0 commit comments

Comments
 (0)