diff --git a/pandas/core/array_algos/putmask.py b/pandas/core/array_algos/putmask.py index daf7d0bd3f213..1082f8d71af01 100644 --- a/pandas/core/array_algos/putmask.py +++ b/pandas/core/array_algos/putmask.py @@ -12,6 +12,7 @@ ArrayLike, npt, ) +from pandas.compat import np_version_under1p20 from pandas.core.dtypes.cast import ( can_hold_element, @@ -126,7 +127,8 @@ def putmask_without_repeat( mask : np.ndarray[bool] new : Any """ - new = setitem_datetimelike_compat(values, mask.sum(), new) + if np_version_under1p20: + new = setitem_datetimelike_compat(values, mask.sum(), new) if getattr(new, "ndim", 0) >= 1: new = new.astype(values.dtype, copy=False) diff --git a/pandas/core/arrays/_mixins.py b/pandas/core/arrays/_mixins.py index a40be5a988f26..3446d5fc43a65 100644 --- a/pandas/core/arrays/_mixins.py +++ b/pandas/core/arrays/_mixins.py @@ -180,7 +180,7 @@ def _values_for_argsort(self) -> np.ndarray: def argmin(self, axis: int = 0, skipna: bool = True): # type:ignore[override] # override base class by adding axis keyword validate_bool_kwarg(skipna, "skipna") - if not skipna and self.isna().any(): + if not skipna and self._hasna: raise NotImplementedError return nargminmax(self, "argmin", axis=axis) @@ -188,7 +188,7 @@ def argmin(self, axis: int = 0, skipna: bool = True): # type:ignore[override] def argmax(self, axis: int = 0, skipna: bool = True): # type:ignore[override] # override base class by adding axis keyword validate_bool_kwarg(skipna, "skipna") - if not skipna and self.isna().any(): + if not skipna and self._hasna: raise NotImplementedError return nargminmax(self, "argmax", axis=axis) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 87acadc01faad..9c262fa37d760 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -2289,7 +2289,6 @@ def maybe_convert_dtype(data, copy: bool): copy = False elif is_extension_array_dtype(data.dtype) and not is_datetime64tz_dtype(data.dtype): - # Includes categorical # TODO: We have no tests for these data = np.array(data, dtype=np.object_) copy = False diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 3d4f53530b89c..accacbf464434 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -367,14 +367,16 @@ def iget(self, i: int | tuple[int, int] | tuple[slice, int]): # "Union[int, integer[Any]]" return self.values[i] # type: ignore[index] - def set_inplace(self, locs, values) -> None: + def set_inplace(self, locs, values: ArrayLike) -> None: """ Modify block values in-place with new item value. Notes ----- - `set` never creates a new array or new Block, whereas `setitem` _may_ - create a new array and always creates a new Block. + `set_inplace` never creates a new array or new Block, whereas `setitem` + _may_ create a new array and always creates a new Block. + + Caller is responsible for checking values.dtype == self.dtype. """ self.values[locs] = values @@ -1183,7 +1185,7 @@ def where(self, other, cond) -> list[Block]: icond, noop = validate_putmask(values, ~cond) if noop: # GH-39595: Always return a copy; short-circuit up/downcasting - return self.copy() + return [self.copy()] if other is lib.no_default: other = self.fill_value @@ -1375,7 +1377,8 @@ def setitem(self, indexer, value): values = self.values if values.ndim == 2: - # TODO: string[pyarrow] tests break if we transpose unconditionally + # TODO(GH#45419): string[pyarrow] tests break if we transpose + # unconditionally values = values.T check_setitem_lengths(indexer, value, values) values[indexer] = value @@ -1396,7 +1399,7 @@ def where(self, other, cond) -> list[Block]: if noop: # GH#44181, GH#45135 # Avoid a) raising for Interval/PeriodDtype and b) unnecessary object upcast - return self.copy() + return [self.copy()] try: res_values = arr._where(cond, other).T @@ -1597,12 +1600,16 @@ def iget(self, i: int | tuple[int, int] | tuple[slice, int]): raise IndexError(f"{self} only contains one item") return self.values - def set_inplace(self, locs, values) -> None: + def set_inplace(self, locs, values: ArrayLike) -> None: # NB: This is a misnomer, is supposed to be inplace but is not, # see GH#33457 # When an ndarray, we should have locs.tolist() == [0] # When a BlockPlacement we should have list(locs) == [0] - self.values = values + + # error: Incompatible types in assignment (expression has type + # "Union[ExtensionArray, ndarray[Any, Any]]", variable has type + # "ExtensionArray") + self.values = values # type: ignore[assignment] try: # TODO(GH33457) this can be removed self._cache.clear() diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index 94b1f5d2717a4..bf74e11ae247a 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -797,7 +797,7 @@ def _is_datetime(x): def should_warn(*args): - not_mono = not any(map(operator.attrgetter("is_monotonic"), args)) + not_mono = not any(map(operator.attrgetter("is_monotonic_increasing"), args)) only_one_dt = reduce(operator.xor, map(_is_datetime, args)) return not_mono and only_one_dt diff --git a/pandas/tests/io/parser/test_unsupported.py b/pandas/tests/io/parser/test_unsupported.py index e223378b600e0..67f155817582c 100644 --- a/pandas/tests/io/parser/test_unsupported.py +++ b/pandas/tests/io/parser/test_unsupported.py @@ -166,7 +166,7 @@ def test_on_bad_lines_callable_python_only(self, all_parsers): parser.read_csv(sio, on_bad_lines=bad_lines_func) -def test_close_file_handle_on_invalide_usecols(all_parsers): +def test_close_file_handle_on_invalid_usecols(all_parsers): # GH 45384 parser = all_parsers diff --git a/pandas/util/_test_decorators.py b/pandas/util/_test_decorators.py index 33bde4e69b042..78ef335adf948 100644 --- a/pandas/util/_test_decorators.py +++ b/pandas/util/_test_decorators.py @@ -80,6 +80,12 @@ def safe_import(mod_name: str, min_version: str | None = None): message=".*Int64Index.*", ) + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + message="distutils Version classes are deprecated.*", + ) + try: mod = __import__(mod_name) except ImportError: