Skip to content

Commit 6d92086

Browse files
jbrockmendelJulianWgs
authored andcommitted
CLN: assorted (pandas-dev#41816)
1 parent 8eb49c0 commit 6d92086

File tree

15 files changed

+31
-37
lines changed

15 files changed

+31
-37
lines changed

pandas/core/arrays/datetimelike.py

-5
Original file line numberDiff line numberDiff line change
@@ -1677,11 +1677,6 @@ class TimelikeOps(DatetimeLikeArrayMixin):
16771677
Common ops for TimedeltaIndex/DatetimeIndex, but not PeriodIndex.
16781678
"""
16791679

1680-
def copy(self: TimelikeOpsT) -> TimelikeOpsT:
1681-
result = super().copy()
1682-
result._freq = self._freq
1683-
return result
1684-
16851680
def _round(self, freq, mode, ambiguous, nonexistent):
16861681
# round the local times
16871682
if is_datetime64tz_dtype(self.dtype):

pandas/core/construction.py

-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ def sanitize_array(
556556
if dtype is not None or len(data) == 0:
557557
subarr = _try_cast(data, dtype, copy, raise_cast_failure)
558558
else:
559-
# TODO: copy?
560559
subarr = maybe_convert_platform(data)
561560
if subarr.dtype == object:
562561
subarr = cast(np.ndarray, subarr)

pandas/core/dtypes/dtypes.py

-6
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ class PandasExtensionDtype(ExtensionDtype):
8989
isnative = 0
9090
_cache_dtypes: dict[str_type, PandasExtensionDtype] = {}
9191

92-
def __str__(self) -> str_type:
93-
"""
94-
Return a string representation for a particular Object
95-
"""
96-
return self.name
97-
9892
def __repr__(self) -> str_type:
9993
"""
10094
Return a string representation for a particular object.

pandas/core/generic.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10176,7 +10176,9 @@ def pct_change(
1017610176
assert _data is not None # needed for mypy
1017710177
data = _data
1017810178

10179-
rs = data.div(data.shift(periods=periods, freq=freq, axis=axis, **kwargs)) - 1
10179+
shifted = data.shift(periods=periods, freq=freq, axis=axis, **kwargs)
10180+
# Unsupported left operand type for / ("FrameOrSeries")
10181+
rs = data / shifted - 1 # type: ignore[operator]
1018010182
if freq is not None:
1018110183
# Shift method is implemented differently when freq is not None
1018210184
# We want to restore the original index

pandas/core/indexes/base.py

-3
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,6 @@ def _outer_indexer(
360360
_can_hold_na: bool = True
361361
_can_hold_strings: bool = True
362362

363-
# would we like our indexing holder to defer to us
364-
_defer_to_indexing = False
365-
366363
_engine_type: type[libindex.IndexEngine] = libindex.ObjectEngine
367364
# whether we support partial string indexing. Overridden
368365
# in DatetimeIndex and PeriodIndex

pandas/core/indexes/datetimes.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,7 @@ def __new__(
323323
) -> DatetimeIndex:
324324

325325
if is_scalar(data):
326-
raise TypeError(
327-
f"{cls.__name__}() must be called with a "
328-
f"collection of some kind, {repr(data)} was passed"
329-
)
326+
raise cls._scalar_data_error(data)
330327

331328
# - Cases checked above all return/raise before reaching here - #
332329

pandas/core/indexes/interval.py

-3
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ class IntervalIndex(ExtensionIndex):
258258
closed_left: bool
259259
closed_right: bool
260260

261-
# we would like our indexing holder to defer to us
262-
_defer_to_indexing = True
263-
264261
_data: IntervalArray
265262
_values: IntervalArray
266263
_can_hold_strings = False

pandas/core/indexes/multi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2813,7 +2813,7 @@ def slice_locs(self, start=None, end=None, step=None, kind=None):
28132813
# happens in get_slice_bound method), but it adds meaningful doc.
28142814
return super().slice_locs(start, end, step)
28152815

2816-
def _partial_tup_index(self, tup, side="left"):
2816+
def _partial_tup_index(self, tup: tuple, side="left"):
28172817
if len(tup) > self._lexsort_depth:
28182818
raise UnsortedIndexError(
28192819
f"Key length ({len(tup)}) was greater than MultiIndex lexsort depth "

pandas/core/indexes/timedeltas.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ def __new__(
130130
name = maybe_extract_name(name, data, cls)
131131

132132
if is_scalar(data):
133-
raise TypeError(
134-
f"{cls.__name__}() must be called with a "
135-
f"collection of some kind, {repr(data)} was passed"
136-
)
133+
raise cls._scalar_data_error(data)
137134

138135
if unit in {"Y", "y", "M"}:
139136
raise ValueError(

pandas/tests/indexes/datetimes/test_constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ def test_constructor_coverage(self):
552552
with pytest.raises(TypeError, match=msg):
553553
date_range(start="1/1/2000", periods="foo", freq="D")
554554

555-
msg = "DatetimeIndex\\(\\) must be called with a collection"
555+
msg = r"DatetimeIndex\(\.\.\.\) must be called with a collection"
556556
with pytest.raises(TypeError, match=msg):
557557
DatetimeIndex("1/1/2000")
558558

pandas/tests/indexes/multi/test_isin.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,5 @@ def test_isin_level_kwarg():
8686
def test_isin_multi_index_with_missing_value(labels, expected, level):
8787
# GH 19132
8888
midx = MultiIndex.from_arrays([[np.nan, "a", "b"], ["c", "d", np.nan]])
89-
tm.assert_numpy_array_equal(midx.isin(labels, level=level), expected)
89+
result = midx.isin(labels, level=level)
90+
tm.assert_numpy_array_equal(result, expected)

pandas/tests/indexes/timedeltas/test_constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def test_constructor_coverage(self):
193193
timedelta_range(start="1 days", periods="foo", freq="D")
194194

195195
msg = (
196-
r"TimedeltaIndex\(\) must be called with a collection of some kind, "
196+
r"TimedeltaIndex\(\.\.\.\) must be called with a collection of some kind, "
197197
"'1 days' was passed"
198198
)
199199
with pytest.raises(TypeError, match=msg):

pandas/tests/io/test_common.py

+6
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ def test_read_expands_user_home_dir(
262262
@pytest.mark.filterwarnings(
263263
"ignore:CategoricalBlock is deprecated:DeprecationWarning"
264264
)
265+
@pytest.mark.filterwarnings( # pytables np.object usage
266+
"ignore:`np.object` is a deprecated alias:DeprecationWarning"
267+
)
265268
def test_read_fspath_all(self, reader, module, path, datapath):
266269
pytest.importorskip(module)
267270
path = datapath(*path)
@@ -309,6 +312,9 @@ def test_write_fspath_all(self, writer_name, writer_kwargs, module):
309312

310313
assert result == expected
311314

315+
@pytest.mark.filterwarnings( # pytables np.object usage
316+
"ignore:`np.object` is a deprecated alias:DeprecationWarning"
317+
)
312318
@td.skip_array_manager_not_yet_implemented # TODO(ArrayManager) IO HDF5
313319
def test_write_fspath_hdf5(self):
314320
# Same test as write_fspath_all, except HDF5 files aren't

pandas/tests/reshape/merge/test_join.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ def test_join_hierarchical_mixed(self):
417417
other_df = DataFrame([(1, 2, 3), (7, 10, 6)], columns=["a", "b", "d"])
418418
other_df.set_index("a", inplace=True)
419419
# GH 9455, 12219
420-
with tm.assert_produces_warning(FutureWarning):
420+
msg = "merging between different levels is deprecated"
421+
with tm.assert_produces_warning(FutureWarning, match=msg):
421422
result = merge(new_df, other_df, left_index=True, right_index=True)
422423
assert ("b", "mean") in result
423424
assert "b" in result

pandas/tests/series/test_logical_ops.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,15 @@ def test_reversed_xor_with_index_returns_index(self):
273273
idx1 = Index([True, False, True, False])
274274
idx2 = Index([1, 0, 1, 0])
275275

276+
msg = "operating as a set operation"
277+
276278
expected = Index.symmetric_difference(idx1, ser)
277-
with tm.assert_produces_warning(FutureWarning):
279+
with tm.assert_produces_warning(FutureWarning, match=msg):
278280
result = idx1 ^ ser
279281
tm.assert_index_equal(result, expected)
280282

281283
expected = Index.symmetric_difference(idx2, ser)
282-
with tm.assert_produces_warning(FutureWarning):
284+
with tm.assert_produces_warning(FutureWarning, match=msg):
283285
result = idx2 ^ ser
284286
tm.assert_index_equal(result, expected)
285287

@@ -308,13 +310,15 @@ def test_reversed_logical_op_with_index_returns_series(self, op):
308310
idx1 = Index([True, False, True, False])
309311
idx2 = Index([1, 0, 1, 0])
310312

313+
msg = "operating as a set operation"
314+
311315
expected = Series(op(idx1.values, ser.values))
312-
with tm.assert_produces_warning(FutureWarning):
316+
with tm.assert_produces_warning(FutureWarning, match=msg):
313317
result = op(ser, idx1)
314318
tm.assert_series_equal(result, expected)
315319

316320
expected = Series(op(idx2.values, ser.values))
317-
with tm.assert_produces_warning(FutureWarning):
321+
with tm.assert_produces_warning(FutureWarning, match=msg):
318322
result = op(ser, idx2)
319323
tm.assert_series_equal(result, expected)
320324

@@ -331,7 +335,11 @@ def test_reverse_ops_with_index(self, op, expected):
331335
# multi-set Index ops are buggy, so let's avoid duplicates...
332336
ser = Series([True, False])
333337
idx = Index([False, True])
334-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
338+
339+
msg = "operating as a set operation"
340+
with tm.assert_produces_warning(
341+
FutureWarning, match=msg, check_stacklevel=False
342+
):
335343
# behaving as set ops is deprecated, will become logical ops
336344
result = op(ser, idx)
337345
tm.assert_index_equal(result, expected)

0 commit comments

Comments
 (0)