Skip to content

CLN: suppress distutils warnings, assorted #45663

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 4 commits into from
Jan 29, 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
4 changes: 3 additions & 1 deletion pandas/core/array_algos/putmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ArrayLike,
npt,
)
from pandas.compat import np_version_under1p20

from pandas.core.dtypes.cast import (
can_hold_element,
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ 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)

# Signature of "argmax" incompatible with supertype "ExtensionArray"
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)

Expand Down
1 change: 0 additions & 1 deletion pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/computation/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/parser/test_unsupported.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions pandas/util/_test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down