Skip to content

CLN: assorted, suppress test warnings #45147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ ExtensionArray
- Bug in :func:`array` failing to preserve :class:`PandasArray` (:issue:`43887`)
- 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`)
- 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`)
- NumPy ufuncs with ``out`` keyword are now supported by arrays with ``IntegerDtype`` and ``FloatingDtype`` (:issue:`??`)
- NumPy ufuncs with ``out`` keyword are now supported by arrays with ``IntegerDtype`` and ``FloatingDtype`` (:issue:`45122`)
- Avoid raising ``PerformanceWarning`` about fragmented DataFrame when using many columns with an extension dtype (:issue:`44098`)
- Bug in :class:`IntegerArray` and :class:`FloatingArray` construction incorrectly coercing mismatched NA values (e.g. ``np.timedelta64("NaT")``) to numeric NA (:issue:`44514`)
- 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`)
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@
TimedeltaArray,
)

_shared_docs: dict[str, str] = {}


# --------------- #
# dtype access #
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/arraylike.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import numpy as np

from pandas._libs import lib
from pandas._libs.ops_dispatch import maybe_dispatch_ufunc_to_dunder_op
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.generic import ABCNDFrame

from pandas.core import roperator
from pandas.core.construction import extract_array
from pandas.core.ops import (
maybe_dispatch_ufunc_to_dunder_op,
roperator,
)
from pandas.core.ops.common import unpack_zerodim_and_defer

REDUCTION_ALIASES = {
Expand Down
28 changes: 15 additions & 13 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
from pandas.core import (
arraylike,
missing,
ops,
roperator,
)
from pandas.core.algorithms import (
factorize_array,
Expand Down Expand Up @@ -1644,21 +1644,23 @@ def _create_arithmetic_method(cls, op):
@classmethod
def _add_arithmetic_ops(cls):
setattr(cls, "__add__", cls._create_arithmetic_method(operator.add))
setattr(cls, "__radd__", cls._create_arithmetic_method(ops.radd))
setattr(cls, "__radd__", cls._create_arithmetic_method(roperator.radd))
setattr(cls, "__sub__", cls._create_arithmetic_method(operator.sub))
setattr(cls, "__rsub__", cls._create_arithmetic_method(ops.rsub))
setattr(cls, "__rsub__", cls._create_arithmetic_method(roperator.rsub))
setattr(cls, "__mul__", cls._create_arithmetic_method(operator.mul))
setattr(cls, "__rmul__", cls._create_arithmetic_method(ops.rmul))
setattr(cls, "__rmul__", cls._create_arithmetic_method(roperator.rmul))
setattr(cls, "__pow__", cls._create_arithmetic_method(operator.pow))
setattr(cls, "__rpow__", cls._create_arithmetic_method(ops.rpow))
setattr(cls, "__rpow__", cls._create_arithmetic_method(roperator.rpow))
setattr(cls, "__mod__", cls._create_arithmetic_method(operator.mod))
setattr(cls, "__rmod__", cls._create_arithmetic_method(ops.rmod))
setattr(cls, "__rmod__", cls._create_arithmetic_method(roperator.rmod))
setattr(cls, "__floordiv__", cls._create_arithmetic_method(operator.floordiv))
setattr(cls, "__rfloordiv__", cls._create_arithmetic_method(ops.rfloordiv))
setattr(
cls, "__rfloordiv__", cls._create_arithmetic_method(roperator.rfloordiv)
)
setattr(cls, "__truediv__", cls._create_arithmetic_method(operator.truediv))
setattr(cls, "__rtruediv__", cls._create_arithmetic_method(ops.rtruediv))
setattr(cls, "__rtruediv__", cls._create_arithmetic_method(roperator.rtruediv))
setattr(cls, "__divmod__", cls._create_arithmetic_method(divmod))
setattr(cls, "__rdivmod__", cls._create_arithmetic_method(ops.rdivmod))
setattr(cls, "__rdivmod__", cls._create_arithmetic_method(roperator.rdivmod))

@classmethod
def _create_comparison_method(cls, op):
Expand All @@ -1680,16 +1682,16 @@ def _create_logical_method(cls, op):
@classmethod
def _add_logical_ops(cls):
setattr(cls, "__and__", cls._create_logical_method(operator.and_))
setattr(cls, "__rand__", cls._create_logical_method(ops.rand_))
setattr(cls, "__rand__", cls._create_logical_method(roperator.rand_))
setattr(cls, "__or__", cls._create_logical_method(operator.or_))
setattr(cls, "__ror__", cls._create_logical_method(ops.ror_))
setattr(cls, "__ror__", cls._create_logical_method(roperator.ror_))
setattr(cls, "__xor__", cls._create_logical_method(operator.xor))
setattr(cls, "__rxor__", cls._create_logical_method(ops.rxor))
setattr(cls, "__rxor__", cls._create_logical_method(roperator.rxor))


class ExtensionScalarOpsMixin(ExtensionOpsMixin):
"""
A mixin for defining ops on an ExtensionArray.
A mixin for defining ops on an ExtensionArray.

It is assumed that the underlying scalar objects have the operators
already defined.
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
TypeVar,
Union,
cast,
final,
overload,
)
import warnings
Expand Down Expand Up @@ -1138,6 +1139,7 @@ def _add_timedelta_arraylike(self, other):

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

@final
def _add_nat(self):
"""
Add pd.NaT to self
Expand All @@ -1153,6 +1155,7 @@ def _add_nat(self):
result.fill(iNaT)
return type(self)(result, dtype=self.dtype, freq=None)

@final
def _sub_nat(self):
"""
Subtract pd.NaT from self
Expand Down Expand Up @@ -1589,7 +1592,7 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]:
dtype='object')
"""
result = self._format_native_types(date_format=date_format, na_rep=np.nan)
return result.astype(object)
return result.astype(object, copy=False)


_round_doc = """
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/arrays/sparse/scipy_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,17 @@ def coo_to_sparse_series(
from pandas import SparseDtype

try:
s = Series(A.data, MultiIndex.from_arrays((A.row, A.col)))
ser = Series(A.data, MultiIndex.from_arrays((A.row, A.col)))
except AttributeError as err:
raise TypeError(
f"Expected coo_matrix. Got {type(A).__name__} instead."
) from err
s = s.sort_index()
s = s.astype(SparseDtype(s.dtype))
ser = ser.sort_index()
ser = ser.astype(SparseDtype(ser.dtype))
if dense_index:
# is there a better constructor method to use here?
i = range(A.shape[0])
j = range(A.shape[1])
ind = MultiIndex.from_product([i, j])
s = s.reindex(ind)
return s
ser = ser.reindex(ind)
return ser
2 changes: 1 addition & 1 deletion pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def __setitem__(self, key, value):

super().__setitem__(key, value)

def astype(self, dtype, copy=True):
def astype(self, dtype, copy: bool = True):
dtype = pandas_dtype(dtype)

if is_dtype_equal(dtype, self.dtype):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ def value_counts(self, dropna: bool = True) -> Series:

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

def astype(self, dtype, copy=True):
def astype(self, dtype, copy: bool = True):
dtype = pandas_dtype(dtype)

if is_dtype_equal(dtype, self.dtype):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ def view(self, cls=None):
result._id = self._id
return result

def astype(self, dtype, copy=True):
def astype(self, dtype, copy: bool = True):
"""
Create an Index with values cast to dtypes.

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def __contains__(self, key) -> bool:
return False

@doc(Index.astype)
def astype(self, dtype, copy=True):
def astype(self, dtype, copy: bool = True):
dtype = pandas_dtype(dtype)
if is_float_dtype(self.dtype):
if needs_i8_conversion(dtype):
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ def test_value_counts(self, all_data, dropna, request):

tm.assert_series_equal(result, expected)

def test_value_counts_with_normalize(self, data):
return super().test_value_counts_with_normalize(data)


class TestCasting(base.BaseCastingTests):
pass
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/extension/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ def test_index_from_array(self, data):
# the sparse dtype
@pytest.mark.xfail(reason="Index cannot yet store sparse dtype")
def test_index_from_listlike_with_dtype(self, data):
super().test_index_from_listlike_with_dtype(data)
msg = "passing a SparseArray to pd.Index"
with tm.assert_produces_warning(FutureWarning, match=msg):
super().test_index_from_listlike_with_dtype(data)


class TestMissing(BaseSparseTests, base.BaseMissingTests):
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/indexes/datetimes/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ def test_get_indexer_mixed_dtypes(self, target):
([date(9999, 1, 1), date(9999, 1, 1)], [-1, -1]),
],
)
@pytest.mark.filterwarnings("ignore:Comparison of Timestamp.*:FutureWarning")
def test_get_indexer_out_of_bounds_date(self, target, positions):
values = DatetimeIndex([Timestamp("2020-01-01"), Timestamp("2020-01-02")])

Expand Down
10 changes: 3 additions & 7 deletions pandas/tests/indexing/test_coercion.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,9 @@ def _assert_setitem_series_conversion(
# check dtype explicitly for sure
assert temp.dtype == expected_dtype

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

@pytest.mark.parametrize(
"val,exp_dtype", [(1, object), (1.1, object), (1 + 1j, object), (True, object)]
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/io/formats/test_printing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest

import pandas._config.config as cf

Expand Down Expand Up @@ -119,6 +120,9 @@ def test_ambiguous_width(self):


class TestTableSchemaRepr:
@pytest.mark.filterwarnings(
"ignore:.*signature may therefore change.*:FutureWarning"
)
def test_publishes(self, ip):
ipython = ip.instance(config=ip.config)
df = pd.DataFrame({"A": [1, 2]})
Expand Down