Skip to content

Commit 1d1ab8e

Browse files
authored
CLN: assorted, suppress test warnings (#45147)
1 parent 9dfb454 commit 1d1ab8e

File tree

15 files changed

+42
-41
lines changed

15 files changed

+42
-41
lines changed

doc/source/whatsnew/v1.4.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ ExtensionArray
959959
- Bug in :func:`array` failing to preserve :class:`PandasArray` (:issue:`43887`)
960960
- NumPy ufuncs ``np.abs``, ``np.positive``, ``np.negative`` now correctly preserve dtype when called on ExtensionArrays that implement ``__abs__, __pos__, __neg__``, respectively. In particular this is fixed for :class:`TimedeltaArray` (:issue:`43899`, :issue:`23316`)
961961
- NumPy ufuncs ``np.minimum.reduce`` ``np.maximum.reduce``, ``np.add.reduce``, and ``np.prod.reduce`` now work correctly instead of raising ``NotImplementedError`` on :class:`Series` with ``IntegerDtype`` or ``FloatDtype`` (:issue:`43923`, :issue:`44793`)
962-
- NumPy ufuncs with ``out`` keyword are now supported by arrays with ``IntegerDtype`` and ``FloatingDtype`` (:issue:`??`)
962+
- NumPy ufuncs with ``out`` keyword are now supported by arrays with ``IntegerDtype`` and ``FloatingDtype`` (:issue:`45122`)
963963
- Avoid raising ``PerformanceWarning`` about fragmented DataFrame when using many columns with an extension dtype (:issue:`44098`)
964964
- Bug in :class:`IntegerArray` and :class:`FloatingArray` construction incorrectly coercing mismatched NA values (e.g. ``np.timedelta64("NaT")``) to numeric NA (:issue:`44514`)
965965
- Bug in :meth:`BooleanArray.__eq__` and :meth:`BooleanArray.__ne__` raising ``TypeError`` on comparison with an incompatible type (like a string). This caused :meth:`DataFrame.replace` to sometimes raise a ``TypeError`` if a nullable boolean column was included (:issue:`44499`)

pandas/core/algorithms.py

-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@
108108
TimedeltaArray,
109109
)
110110

111-
_shared_docs: dict[str, str] = {}
112-
113111

114112
# --------------- #
115113
# dtype access #

pandas/core/arraylike.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
import numpy as np
1212

1313
from pandas._libs import lib
14+
from pandas._libs.ops_dispatch import maybe_dispatch_ufunc_to_dunder_op
1415
from pandas.util._exceptions import find_stack_level
1516

1617
from pandas.core.dtypes.generic import ABCNDFrame
1718

19+
from pandas.core import roperator
1820
from pandas.core.construction import extract_array
19-
from pandas.core.ops import (
20-
maybe_dispatch_ufunc_to_dunder_op,
21-
roperator,
22-
)
2321
from pandas.core.ops.common import unpack_zerodim_and_defer
2422

2523
REDUCTION_ALIASES = {

pandas/core/arrays/base.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
from pandas.core import (
6969
arraylike,
7070
missing,
71-
ops,
71+
roperator,
7272
)
7373
from pandas.core.algorithms import (
7474
factorize_array,
@@ -1644,21 +1644,23 @@ def _create_arithmetic_method(cls, op):
16441644
@classmethod
16451645
def _add_arithmetic_ops(cls):
16461646
setattr(cls, "__add__", cls._create_arithmetic_method(operator.add))
1647-
setattr(cls, "__radd__", cls._create_arithmetic_method(ops.radd))
1647+
setattr(cls, "__radd__", cls._create_arithmetic_method(roperator.radd))
16481648
setattr(cls, "__sub__", cls._create_arithmetic_method(operator.sub))
1649-
setattr(cls, "__rsub__", cls._create_arithmetic_method(ops.rsub))
1649+
setattr(cls, "__rsub__", cls._create_arithmetic_method(roperator.rsub))
16501650
setattr(cls, "__mul__", cls._create_arithmetic_method(operator.mul))
1651-
setattr(cls, "__rmul__", cls._create_arithmetic_method(ops.rmul))
1651+
setattr(cls, "__rmul__", cls._create_arithmetic_method(roperator.rmul))
16521652
setattr(cls, "__pow__", cls._create_arithmetic_method(operator.pow))
1653-
setattr(cls, "__rpow__", cls._create_arithmetic_method(ops.rpow))
1653+
setattr(cls, "__rpow__", cls._create_arithmetic_method(roperator.rpow))
16541654
setattr(cls, "__mod__", cls._create_arithmetic_method(operator.mod))
1655-
setattr(cls, "__rmod__", cls._create_arithmetic_method(ops.rmod))
1655+
setattr(cls, "__rmod__", cls._create_arithmetic_method(roperator.rmod))
16561656
setattr(cls, "__floordiv__", cls._create_arithmetic_method(operator.floordiv))
1657-
setattr(cls, "__rfloordiv__", cls._create_arithmetic_method(ops.rfloordiv))
1657+
setattr(
1658+
cls, "__rfloordiv__", cls._create_arithmetic_method(roperator.rfloordiv)
1659+
)
16581660
setattr(cls, "__truediv__", cls._create_arithmetic_method(operator.truediv))
1659-
setattr(cls, "__rtruediv__", cls._create_arithmetic_method(ops.rtruediv))
1661+
setattr(cls, "__rtruediv__", cls._create_arithmetic_method(roperator.rtruediv))
16601662
setattr(cls, "__divmod__", cls._create_arithmetic_method(divmod))
1661-
setattr(cls, "__rdivmod__", cls._create_arithmetic_method(ops.rdivmod))
1663+
setattr(cls, "__rdivmod__", cls._create_arithmetic_method(roperator.rdivmod))
16621664

16631665
@classmethod
16641666
def _create_comparison_method(cls, op):
@@ -1680,16 +1682,16 @@ def _create_logical_method(cls, op):
16801682
@classmethod
16811683
def _add_logical_ops(cls):
16821684
setattr(cls, "__and__", cls._create_logical_method(operator.and_))
1683-
setattr(cls, "__rand__", cls._create_logical_method(ops.rand_))
1685+
setattr(cls, "__rand__", cls._create_logical_method(roperator.rand_))
16841686
setattr(cls, "__or__", cls._create_logical_method(operator.or_))
1685-
setattr(cls, "__ror__", cls._create_logical_method(ops.ror_))
1687+
setattr(cls, "__ror__", cls._create_logical_method(roperator.ror_))
16861688
setattr(cls, "__xor__", cls._create_logical_method(operator.xor))
1687-
setattr(cls, "__rxor__", cls._create_logical_method(ops.rxor))
1689+
setattr(cls, "__rxor__", cls._create_logical_method(roperator.rxor))
16881690

16891691

16901692
class ExtensionScalarOpsMixin(ExtensionOpsMixin):
16911693
"""
1692-
A mixin for defining ops on an ExtensionArray.
1694+
A mixin for defining ops on an ExtensionArray.
16931695
16941696
It is assumed that the underlying scalar objects have the operators
16951697
already defined.

pandas/core/arrays/datetimelike.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
TypeVar,
1515
Union,
1616
cast,
17+
final,
1718
overload,
1819
)
1920
import warnings
@@ -1138,6 +1139,7 @@ def _add_timedelta_arraylike(self, other):
11381139

11391140
return type(self)(new_values, dtype=self.dtype)
11401141

1142+
@final
11411143
def _add_nat(self):
11421144
"""
11431145
Add pd.NaT to self
@@ -1153,6 +1155,7 @@ def _add_nat(self):
11531155
result.fill(iNaT)
11541156
return type(self)(result, dtype=self.dtype, freq=None)
11551157

1158+
@final
11561159
def _sub_nat(self):
11571160
"""
11581161
Subtract pd.NaT from self
@@ -1589,7 +1592,7 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]:
15891592
dtype='object')
15901593
"""
15911594
result = self._format_native_types(date_format=date_format, na_rep=np.nan)
1592-
return result.astype(object)
1595+
return result.astype(object, copy=False)
15931596

15941597

15951598
_round_doc = """

pandas/core/arrays/sparse/scipy_sparse.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,17 @@ def coo_to_sparse_series(
195195
from pandas import SparseDtype
196196

197197
try:
198-
s = Series(A.data, MultiIndex.from_arrays((A.row, A.col)))
198+
ser = Series(A.data, MultiIndex.from_arrays((A.row, A.col)))
199199
except AttributeError as err:
200200
raise TypeError(
201201
f"Expected coo_matrix. Got {type(A).__name__} instead."
202202
) from err
203-
s = s.sort_index()
204-
s = s.astype(SparseDtype(s.dtype))
203+
ser = ser.sort_index()
204+
ser = ser.astype(SparseDtype(ser.dtype))
205205
if dense_index:
206206
# is there a better constructor method to use here?
207207
i = range(A.shape[0])
208208
j = range(A.shape[1])
209209
ind = MultiIndex.from_product([i, j])
210-
s = s.reindex(ind)
211-
return s
210+
ser = ser.reindex(ind)
211+
return ser

pandas/core/arrays/string_.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def __setitem__(self, key, value):
413413

414414
super().__setitem__(key, value)
415415

416-
def astype(self, dtype, copy=True):
416+
def astype(self, dtype, copy: bool = True):
417417
dtype = pandas_dtype(dtype)
418418

419419
if is_dtype_equal(dtype, self.dtype):

pandas/core/arrays/string_arrow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def value_counts(self, dropna: bool = True) -> Series:
626626

627627
return Series(counts, index=index).astype("Int64")
628628

629-
def astype(self, dtype, copy=True):
629+
def astype(self, dtype, copy: bool = True):
630630
dtype = pandas_dtype(dtype)
631631

632632
if is_dtype_equal(dtype, self.dtype):

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ def view(self, cls=None):
10001000
result._id = self._id
10011001
return result
10021002

1003-
def astype(self, dtype, copy=True):
1003+
def astype(self, dtype, copy: bool = True):
10041004
"""
10051005
Create an Index with values cast to dtypes.
10061006

pandas/core/indexes/numeric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def __contains__(self, key) -> bool:
233233
return False
234234

235235
@doc(Index.astype)
236-
def astype(self, dtype, copy=True):
236+
def astype(self, dtype, copy: bool = True):
237237
dtype = pandas_dtype(dtype)
238238
if is_float_dtype(self.dtype):
239239
if needs_i8_conversion(dtype):

pandas/tests/extension/decimal/test_decimal.py

-3
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ def test_value_counts(self, all_data, dropna, request):
152152

153153
tm.assert_series_equal(result, expected)
154154

155-
def test_value_counts_with_normalize(self, data):
156-
return super().test_value_counts_with_normalize(data)
157-
158155

159156
class TestCasting(base.BaseCastingTests):
160157
pass

pandas/tests/extension/test_sparse.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ def test_index_from_array(self, data):
208208
# the sparse dtype
209209
@pytest.mark.xfail(reason="Index cannot yet store sparse dtype")
210210
def test_index_from_listlike_with_dtype(self, data):
211-
super().test_index_from_listlike_with_dtype(data)
211+
msg = "passing a SparseArray to pd.Index"
212+
with tm.assert_produces_warning(FutureWarning, match=msg):
213+
super().test_index_from_listlike_with_dtype(data)
212214

213215

214216
class TestMissing(BaseSparseTests, base.BaseMissingTests):

pandas/tests/indexes/datetimes/test_indexing.py

+1
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ def test_get_indexer_mixed_dtypes(self, target):
651651
([date(9999, 1, 1), date(9999, 1, 1)], [-1, -1]),
652652
],
653653
)
654+
@pytest.mark.filterwarnings("ignore:Comparison of Timestamp.*:FutureWarning")
654655
def test_get_indexer_out_of_bounds_date(self, target, positions):
655656
values = DatetimeIndex([Timestamp("2020-01-01"), Timestamp("2020-01-02")])
656657

pandas/tests/indexing/test_coercion.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,9 @@ def _assert_setitem_series_conversion(
8888
# check dtype explicitly for sure
8989
assert temp.dtype == expected_dtype
9090

91-
# AFAICT the problem is in Series.__setitem__ where with integer dtype
92-
# ser[1] = 2.2 casts 2.2 to 2 instead of casting the ser to floating
93-
# FIXME: dont leave commented-out
94-
# .loc works different rule, temporary disable
95-
# temp = original_series.copy()
96-
# temp.loc[1] = loc_value
97-
# tm.assert_series_equal(temp, expected_series)
91+
temp = original_series.copy()
92+
temp.loc[1] = loc_value
93+
tm.assert_series_equal(temp, expected_series)
9894

9995
@pytest.mark.parametrize(
10096
"val,exp_dtype", [(1, object), (1.1, object), (1 + 1j, object), (True, object)]

pandas/tests/io/formats/test_printing.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
import pytest
23

34
import pandas._config.config as cf
45

@@ -119,6 +120,9 @@ def test_ambiguous_width(self):
119120

120121

121122
class TestTableSchemaRepr:
123+
@pytest.mark.filterwarnings(
124+
"ignore:.*signature may therefore change.*:FutureWarning"
125+
)
122126
def test_publishes(self, ip):
123127
ipython = ip.instance(config=ip.config)
124128
df = pd.DataFrame({"A": [1, 2]})

0 commit comments

Comments
 (0)