Skip to content

CLN: assorted #49590

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 1 commit into from
Nov 9, 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 asv_bench/benchmarks/tslibs/tslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TimeIntsToPydatetime:
_tzs,
)
param_names = ["box", "size", "tz"]
# TODO: fold? freq?
# TODO: fold?

def setup(self, box, size, tz):
if box == "date" and tz is not None:
Expand Down
14 changes: 1 addition & 13 deletions pandas/core/arrays/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,21 +234,9 @@ def searchsorted(
side: Literal["left", "right"] = "left",
sorter: NumpySorter = None,
) -> npt.NDArray[np.intp] | np.intp:
# TODO(2.0): use _validate_setitem_value once dt64tz mismatched-timezone
# deprecation is enforced
npvalue = self._validate_searchsorted_value(value)
npvalue = self._validate_setitem_value(value)
return self._ndarray.searchsorted(npvalue, side=side, sorter=sorter)

def _validate_searchsorted_value(
self, value: NumpyValueArrayLike | ExtensionArray
) -> NumpyValueArrayLike:
# TODO(2.0): after deprecation in datetimelikearraymixin is enforced,
# we can remove this and use _validate_setitem_value directly
if isinstance(value, ExtensionArray):
return value.to_numpy()
else:
return value

@doc(ExtensionArray.shift)
def shift(self, periods: int = 1, fill_value=None, axis: AxisInt = 0):

Expand Down
2 changes: 0 additions & 2 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,8 +1301,6 @@ def _validate_setitem_value(self, value):
else:
return self._validate_scalar(value)

_validate_searchsorted_value = _validate_setitem_value

def _validate_scalar(self, fill_value):
"""
Convert a user-facing fill_value to a representation to use with our
Expand Down
16 changes: 1 addition & 15 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,6 @@ def _validate_scalar(
value,
*,
allow_listlike: bool = False,
setitem: bool = True,
unbox: bool = True,
):
"""
Expand All @@ -612,8 +611,6 @@ def _validate_scalar(
allow_listlike: bool, default False
When raising an exception, whether the message should say
listlike inputs are allowed.
setitem : bool, default True
Whether to check compatibility with setitem strictness.
unbox : bool, default True
Whether to unbox the result before returning. Note: unbox=False
skips the setitem compatibility check.
Expand Down Expand Up @@ -735,14 +732,6 @@ def _validate_listlike(self, value, allow_object: bool = False):

return value

def _validate_searchsorted_value(self, value):
if not is_list_like(value):
return self._validate_scalar(value, allow_listlike=True, setitem=False)
else:
value = self._validate_listlike(value)

return self._unbox(value)

def _validate_setitem_value(self, value):
if is_list_like(value):
value = self._validate_listlike(value)
Expand Down Expand Up @@ -1363,10 +1352,7 @@ def _addsub_object_array(self, other: np.ndarray, op):
# Caller is responsible for broadcasting if necessary
assert self.shape == other.shape, (self.shape, other.shape)

with warnings.catch_warnings():
# filter out warnings about Timestamp.freq
warnings.filterwarnings("ignore", category=FutureWarning)
res_values = op(self.astype("O"), np.asarray(other))
res_values = op(self.astype("O"), np.asarray(other))

result = pd_array(res_values.ravel())
result = extract_array(result, extract_numpy=True).reshape(self.shape)
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 @@ -751,7 +751,6 @@ def _add_offset(self, offset) -> DatetimeArray:
else:
result = DatetimeArray._simple_new(result, dtype=result.dtype)
if self.tz is not None:
# FIXME: tz_localize with non-nano
result = result.tz_localize(self.tz)

return result
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def searchsorted(
side: Literal["left", "right"] = "left",
sorter: NumpySorter = None,
) -> npt.NDArray[np.intp] | np.intp:
npvalue = self._validate_searchsorted_value(value).view("M8[ns]")
npvalue = self._validate_setitem_value(value).view("M8[ns]")

# Cast to M8 to get datetime-like NaT placement
m8arr = self._ndarray.view("M8[ns]")
Expand Down
15 changes: 6 additions & 9 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,15 +1029,12 @@ def soft_convert_objects(
if datetime or timedelta:
# GH 20380, when datetime is beyond year 2262, hence outside
# bound of nanosecond-resolution 64-bit integers.
try:
converted = lib.maybe_convert_objects(
values,
convert_datetime=datetime,
convert_timedelta=timedelta,
convert_period=period,
)
except (OutOfBoundsDatetime, ValueError):
return values
converted = lib.maybe_convert_objects(
values,
convert_datetime=datetime,
convert_timedelta=timedelta,
convert_period=period,
)
if converted is not values:
return converted

Expand Down
8 changes: 1 addition & 7 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3500,13 +3500,7 @@ def _assert_can_do_setop(self, other) -> bool:

def _convert_can_do_setop(self, other) -> tuple[Index, Hashable]:
if not isinstance(other, Index):
# TODO(2.0): no need to special-case here once _with_infer
# deprecation is enforced
if hasattr(other, "dtype"):
other = Index(other, name=self.name, dtype=other.dtype)
else:
# e.g. list
other = Index(other, name=self.name)
other = Index(other, name=self.name)
result_name = self.name
else:
result_name = get_op_result_name(self, other)
Expand Down
4 changes: 0 additions & 4 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1920,15 +1920,11 @@ def _catch_deprecated_value_error(err: Exception) -> None:
which will no longer be raised in version.2.0.
"""
if isinstance(err, ValueError):
# TODO(2.0): once DTA._validate_setitem_value deprecation
# is enforced, stop catching ValueError here altogether
if isinstance(err, IncompatibleFrequency):
pass
elif "'value.closed' is" in str(err):
# IntervalDtype mismatched 'closed'
pass
elif "Timezones don't match" not in str(err):
raise err


class DatetimeLikeBlock(NDArrayBackedExtensionBlock):
Expand Down
6 changes: 1 addition & 5 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,11 +1180,7 @@ def _plot_colorbar(self, ax: Axes, **kwds):
# use the last one which contains the latest information
# about the ax
img = ax.collections[-1]
with warnings.catch_warnings():
# https://github.com/matplotlib/matplotlib/issues/23614
# False positive deprecation warning until matplotlib=3.6
warnings.filterwarnings("ignore", "Auto-removal of grids")
return self.fig.colorbar(img, ax=ax, **kwds)
return self.fig.colorbar(img, ax=ax, **kwds)


class ScatterPlot(PlanePlot):
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/apply/test_frame_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def func(x):
frame_kernels_raise = [x for x in frame_transform_kernels if x not in wont_fail]


@pytest.mark.filterwarnings(
"ignore:Calling Series.rank with numeric_only:FutureWarning"
)
@pytest.mark.filterwarnings("ignore:Dropping of nuisance:FutureWarning")
@pytest.mark.parametrize("op", [*frame_kernels_raise, lambda x: x + 1])
def test_transform_bad_dtype(op, frame_or_series, request):
# GH 35964
Expand Down Expand Up @@ -162,6 +166,12 @@ def test_transform_bad_dtype(op, frame_or_series, request):
obj.transform({"A": [op]})


@pytest.mark.filterwarnings(
"ignore:Dropping of nuisance columns in Series.rank:FutureWarning"
)
@pytest.mark.filterwarnings(
"ignore:Calling Series.rank with numeric_only:FutureWarning"
)
@pytest.mark.parametrize("op", frame_kernels_raise)
def test_transform_failure_typeerror(request, op):
# GH 35964
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/apply/test_series_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ def test_transform(string_series):
tm.assert_series_equal(result.reindex_like(expected), expected)


@pytest.mark.filterwarnings("ignore:Calling Series.rank:FutureWarning")
@pytest.mark.filterwarnings("ignore:Dropping of nuisance:FutureWarning")
@pytest.mark.parametrize("op", series_transform_kernels)
def test_transform_partial_failure(op, request):
# GH 35964
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/arithmetic/test_datetime64.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,6 @@ def test_comparison_tzawareness_compat_scalars(self, comparison_op, box_with_arr
# Raising in __eq__ will fallback to NumPy, which warns, fails,
# then re-raises the original exception. So we just need to ignore.
@pytest.mark.filterwarnings("ignore:elementwise comp:DeprecationWarning")
@pytest.mark.filterwarnings("ignore:Converting timezone-aware:FutureWarning")
def test_scalar_comparison_tzawareness(
self, comparison_op, other, tz_aware_fixture, box_with_array
):
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/arithmetic/test_timedelta64.py
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,7 @@ def test_td64arr_floordiv_td64arr_with_nat(
result = np.asarray(left) // right
tm.assert_equal(result, expected)

@pytest.mark.filterwarnings("ignore:invalid value encountered:RuntimeWarning")
def test_td64arr_floordiv_tdscalar(self, box_with_array, scalar_td):
# GH#18831, GH#19125
box = box_with_array
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/test_datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_non_nano(self, unit, reso, dtype):
def test_fields(self, unit, reso, field, dtype, dta_dti):
dta, dti = dta_dti

# FIXME: assert (dti == dta).all()
assert (dti == dta).all()

res = getattr(dta, field)
expected = getattr(dti._data, field)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/base/dim2.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_reductions_2d_axis0(self, data, method):
kwargs["ddof"] = 0

try:
if method == "mean" and hasattr(data, "_mask"):
if method in ["mean", "var"] and hasattr(data, "_mask"):
# Empty slices produced by the mask cause RuntimeWarnings by numpy
with tm.assert_produces_warning(RuntimeWarning, check_stacklevel=False):
result = getattr(arr2d, method)(axis=0, **kwargs)
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ def test_in_numeric_groupby(self, data_for_grouping, request):
)
super().test_in_numeric_groupby(data_for_grouping)

@pytest.mark.filterwarnings(
"ignore:The default value of numeric_only:FutureWarning"
)
@pytest.mark.parametrize("as_index", [True, False])
def test_groupby_extension_agg(self, as_index, data_for_grouping, request):
pa_dtype = data_for_grouping.dtype.pyarrow_dtype
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/frame/methods/test_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,6 @@ def test_quantile_empty_no_rows_ints(self, interp_method):
exp = Series([np.nan, np.nan], index=["a", "b"], name=0.5)
tm.assert_series_equal(res, exp)

@pytest.mark.filterwarnings(
"ignore:The behavior of DatetimeArray._from_sequence:FutureWarning"
)
def test_quantile_empty_no_rows_dt64(self, interp_method):
interpolation, method = interp_method
# datetimes
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/frame/methods/test_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,6 @@ def test_shift_dt64values_int_fill_deprecated(self):
],
ids=lambda x: str(x.dtype),
)
# TODO(2.0): remove filtering
@pytest.mark.filterwarnings("ignore:Index.ravel.*:FutureWarning")
def test_shift_dt64values_axis1_invalid_fill(self, vals, as_cat):
# GH#44564
ser = Series(vals)
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/generic/test_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ def test_finalize_called_eval_numexpr():
# Binary operations


@pytest.mark.filterwarnings(
"ignore:Automatic reindexing on DataFrame vs Series:FutureWarning"
)
@pytest.mark.parametrize("annotate", ["left", "right", "both"])
@pytest.mark.parametrize(
"args",
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/groupby/aggregate/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pandas.io.formats.printing import pprint_thing


@pytest.mark.filterwarnings("ignore:Dropping invalid columns:FutureWarning")
def test_agg_partial_failure_raises():
# GH#43741

Expand Down
1 change: 0 additions & 1 deletion pandas/tests/indexes/datetimes/methods/test_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def astype_non_nano(dti_nano, unit):
return dti


@pytest.mark.filterwarnings("ignore::DeprecationWarning")
@pytest.mark.parametrize("tz", [None, "Asia/Shanghai", "Europe/Berlin"])
@pytest.mark.parametrize("name", [None, "my_dti"])
@pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"])
Expand Down
4 changes: 0 additions & 4 deletions pandas/tests/indexes/test_any_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ def test_slice_keeps_name(self, index):
assert index.name == index[1:].name

@pytest.mark.parametrize("item", [101, "no_int", 2.5])
# FutureWarning from non-tuple sequence of nd indexing
@pytest.mark.filterwarnings("ignore::FutureWarning")
def test_getitem_error(self, index, item):
msg = "|".join(
[
Expand All @@ -145,8 +143,6 @@ def test_getitem_error(self, index, item):
"are valid indices"
),
"index out of bounds", # string[pyarrow]
"Only integers, slices and integer or "
"boolean arrays are valid indices.", # string[pyarrow]
]
)
with pytest.raises(IndexError, match=msg):
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ def test_constructor_simple_new(self, vals, dtype):
result = index._simple_new(index.values, dtype)
tm.assert_index_equal(result, index)

@pytest.mark.filterwarnings("ignore:Passing keywords other:FutureWarning")
@pytest.mark.parametrize("attr", ["values", "asi8"])
@pytest.mark.parametrize("klass", [Index, DatetimeIndex])
def test_constructor_dtypes_datetime(self, tz_naive_fixture, attr, klass):
Expand Down Expand Up @@ -1498,7 +1497,6 @@ def test_index_subclass_constructor_wrong_kwargs(index_maker):
index_maker(foo="bar")


@pytest.mark.filterwarnings("ignore:Passing keywords other:FutureWarning")
def test_deprecated_fastpath():
msg = "[Uu]nexpected keyword argument"
with pytest.raises(TypeError, match=msg):
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/series/accessors/test_dt_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,6 @@ def test_dt_timetz_accessor(self, tz_naive_fixture):
[["2016-01-07", "2016-01-01"], [[2016, 1, 4], [2015, 53, 5]]],
],
)
@pytest.mark.filterwarnings("ignore:Inferring datetime64:FutureWarning")
def test_isocalendar(self, input_series, expected_output):
result = pd.to_datetime(Series(input_series)).dt.isocalendar()
expected_frame = DataFrame(
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/test_downstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def test_oo_optimized_datetime_index_unpickle():
@pytest.mark.network
@tm.network
# Cython import warning
@pytest.mark.filterwarnings("ignore:pandas.util.testing is deprecated")
@pytest.mark.filterwarnings("ignore:can't:ImportWarning")
@pytest.mark.filterwarnings("ignore:.*64Index is deprecated:FutureWarning")
@pytest.mark.filterwarnings(
Expand Down