Skip to content

Commit c4b69b4

Browse files
jbrockmendeltopper-123
authored andcommitted
CLN: remove unused nan comparison functions, ensure_float (pandas-dev#52385)
* CLN: remove unused nan comparison functions * CLN: remove unused ensure_float
1 parent 0e48b77 commit c4b69b4

File tree

4 files changed

+1
-121
lines changed

4 files changed

+1
-121
lines changed

pandas/core/dtypes/common.py

-27
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,6 @@
6666
_is_scipy_sparse = None
6767

6868
ensure_float64 = algos.ensure_float64
69-
70-
71-
def ensure_float(arr):
72-
"""
73-
Ensure that an array object has a float dtype if possible.
74-
75-
Parameters
76-
----------
77-
arr : array-like
78-
The array whose data type we want to enforce as float.
79-
80-
Returns
81-
-------
82-
float_arr : The original array cast to the float dtype if
83-
possible. Otherwise, the original array is returned.
84-
"""
85-
if is_extension_array_dtype(arr.dtype):
86-
if is_float_dtype(arr.dtype):
87-
arr = arr.to_numpy(dtype=arr.dtype.numpy_dtype, na_value=np.nan)
88-
else:
89-
arr = arr.to_numpy(dtype="float64", na_value=np.nan)
90-
elif issubclass(arr.dtype.type, (np.integer, np.bool_)):
91-
arr = arr.astype(float)
92-
return arr
93-
94-
9569
ensure_int64 = algos.ensure_int64
9670
ensure_int32 = algos.ensure_int32
9771
ensure_int16 = algos.ensure_int16
@@ -1735,7 +1709,6 @@ def is_all_strings(value: ArrayLike) -> bool:
17351709
"classes",
17361710
"classes_and_not_datetimelike",
17371711
"DT64NS_DTYPE",
1738-
"ensure_float",
17391712
"ensure_float64",
17401713
"ensure_python_int",
17411714
"ensure_str",

pandas/core/nanops.py

-31
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import functools
44
import itertools
5-
import operator
65
from typing import (
76
Any,
87
Callable,
@@ -36,7 +35,6 @@
3635

3736
from pandas.core.dtypes.common import (
3837
is_any_int_dtype,
39-
is_bool_dtype,
4038
is_complex,
4139
is_float,
4240
is_float_dtype,
@@ -1688,35 +1686,6 @@ def _ensure_numeric(x):
16881686
return x
16891687

16901688

1691-
# NA-friendly array comparisons
1692-
1693-
1694-
def make_nancomp(op):
1695-
def f(x, y):
1696-
xmask = isna(x)
1697-
ymask = isna(y)
1698-
mask = xmask | ymask
1699-
1700-
result = op(x, y)
1701-
1702-
if mask.any():
1703-
if is_bool_dtype(result):
1704-
result = result.astype("O")
1705-
np.putmask(result, mask, np.nan)
1706-
1707-
return result
1708-
1709-
return f
1710-
1711-
1712-
nangt = make_nancomp(operator.gt)
1713-
nange = make_nancomp(operator.ge)
1714-
nanlt = make_nancomp(operator.lt)
1715-
nanle = make_nancomp(operator.le)
1716-
naneq = make_nancomp(operator.eq)
1717-
nanne = make_nancomp(operator.ne)
1718-
1719-
17201689
def na_accum_func(values: ArrayLike, accum_func, *, skipna: bool) -> ArrayLike:
17211690
"""
17221691
Cumulative function with skipna support.

pandas/tests/series/test_arithmetic.py

+1-15
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727
isna,
2828
)
2929
import pandas._testing as tm
30-
from pandas.core import (
31-
nanops,
32-
ops,
33-
)
30+
from pandas.core import ops
3431
from pandas.core.computation import expressions as expr
3532
from pandas.core.computation.check import NUMEXPR_INSTALLED
3633

@@ -499,17 +496,6 @@ def test_ser_cmp_result_names(self, names, comparison_op):
499496
assert result.name == names[2]
500497

501498
def test_comparisons(self):
502-
left = np.random.randn(10)
503-
right = np.random.randn(10)
504-
left[:3] = np.nan
505-
506-
result = nanops.nangt(left, right)
507-
with np.errstate(invalid="ignore"):
508-
expected = (left > right).astype("O")
509-
expected[:3] = np.nan
510-
511-
tm.assert_almost_equal(result, expected)
512-
513499
s = Series(["a", "b", "c"])
514500
s2 = Series([False, True, False])
515501

pandas/tests/test_nanops.py

-48
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from functools import partial
2-
import operator
32
import warnings
43

54
import numpy as np
@@ -744,53 +743,6 @@ def test_nancov(self):
744743
self.check_nancorr_nancov_1d(nanops.nancov, targ0, targ1)
745744

746745

747-
@pytest.mark.parametrize(
748-
"op,nanop",
749-
[
750-
(operator.eq, nanops.naneq),
751-
(operator.ne, nanops.nanne),
752-
(operator.gt, nanops.nangt),
753-
(operator.ge, nanops.nange),
754-
(operator.lt, nanops.nanlt),
755-
(operator.le, nanops.nanle),
756-
],
757-
)
758-
def test_nan_comparison(request, op, nanop, disable_bottleneck):
759-
arr_float = request.getfixturevalue("arr_float")
760-
arr_float1 = request.getfixturevalue("arr_float")
761-
targ0 = op(arr_float, arr_float1)
762-
arr_nan = request.getfixturevalue("arr_nan")
763-
arr_nan_nan = request.getfixturevalue("arr_nan_nan")
764-
arr_float_nan = request.getfixturevalue("arr_float_nan")
765-
arr_float1_nan = request.getfixturevalue("arr_float_nan")
766-
arr_nan_float1 = request.getfixturevalue("arr_nan_float1")
767-
768-
while targ0.ndim:
769-
res0 = nanop(arr_float, arr_float1)
770-
tm.assert_almost_equal(targ0, res0)
771-
772-
if targ0.ndim > 1:
773-
targ1 = np.vstack([targ0, arr_nan])
774-
else:
775-
targ1 = np.hstack([targ0, arr_nan])
776-
res1 = nanop(arr_float_nan, arr_float1_nan)
777-
tm.assert_numpy_array_equal(targ1, res1, check_dtype=False)
778-
779-
targ2 = arr_nan_nan
780-
res2 = nanop(arr_float_nan, arr_nan_float1)
781-
tm.assert_numpy_array_equal(targ2, res2, check_dtype=False)
782-
783-
# Lower dimension for next step in the loop
784-
arr_float = np.take(arr_float, 0, axis=-1)
785-
arr_float1 = np.take(arr_float1, 0, axis=-1)
786-
arr_nan = np.take(arr_nan, 0, axis=-1)
787-
arr_nan_nan = np.take(arr_nan_nan, 0, axis=-1)
788-
arr_float_nan = np.take(arr_float_nan, 0, axis=-1)
789-
arr_float1_nan = np.take(arr_float1_nan, 0, axis=-1)
790-
arr_nan_float1 = np.take(arr_nan_float1, 0, axis=-1)
791-
targ0 = np.take(targ0, 0, axis=-1)
792-
793-
794746
@pytest.mark.parametrize(
795747
"arr, correct",
796748
[

0 commit comments

Comments
 (0)