Skip to content

CLN: assorted #41816

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 2 commits into from
Jun 4, 2021
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
5 changes: 0 additions & 5 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1677,11 +1677,6 @@ class TimelikeOps(DatetimeLikeArrayMixin):
Common ops for TimedeltaIndex/DatetimeIndex, but not PeriodIndex.
"""

def copy(self: TimelikeOpsT) -> TimelikeOpsT:
result = super().copy()
result._freq = self._freq
return result

def _round(self, freq, mode, ambiguous, nonexistent):
# round the local times
if is_datetime64tz_dtype(self.dtype):
Expand Down
1 change: 0 additions & 1 deletion pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ def sanitize_array(
if dtype is not None or len(data) == 0:
subarr = _try_cast(data, dtype, copy, raise_cast_failure)
else:
# TODO: copy?
subarr = maybe_convert_platform(data)
if subarr.dtype == object:
subarr = cast(np.ndarray, subarr)
Expand Down
6 changes: 0 additions & 6 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ class PandasExtensionDtype(ExtensionDtype):
isnative = 0
_cache_dtypes: dict[str_type, PandasExtensionDtype] = {}

def __str__(self) -> str_type:
"""
Return a string representation for a particular Object
"""
return self.name

def __repr__(self) -> str_type:
"""
Return a string representation for a particular object.
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10176,7 +10176,9 @@ def pct_change(
assert _data is not None # needed for mypy
data = _data

rs = data.div(data.shift(periods=periods, freq=freq, axis=axis, **kwargs)) - 1
shifted = data.shift(periods=periods, freq=freq, axis=axis, **kwargs)
# Unsupported left operand type for / ("FrameOrSeries")
rs = data / shifted - 1 # type: ignore[operator]
if freq is not None:
# Shift method is implemented differently when freq is not None
# We want to restore the original index
Expand Down
3 changes: 0 additions & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,6 @@ def _outer_indexer(
_can_hold_na: bool = True
_can_hold_strings: bool = True

# would we like our indexing holder to defer to us
_defer_to_indexing = False

_engine_type: type[libindex.IndexEngine] = libindex.ObjectEngine
# whether we support partial string indexing. Overridden
# in DatetimeIndex and PeriodIndex
Expand Down
5 changes: 1 addition & 4 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,7 @@ def __new__(
) -> DatetimeIndex:

if is_scalar(data):
raise TypeError(
f"{cls.__name__}() must be called with a "
f"collection of some kind, {repr(data)} was passed"
)
raise cls._scalar_data_error(data)

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

Expand Down
3 changes: 0 additions & 3 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,6 @@ class IntervalIndex(ExtensionIndex):
closed_left: bool
closed_right: bool

# we would like our indexing holder to defer to us
_defer_to_indexing = True

_data: IntervalArray
_values: IntervalArray
_can_hold_strings = False
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2813,7 +2813,7 @@ def slice_locs(self, start=None, end=None, step=None, kind=None):
# happens in get_slice_bound method), but it adds meaningful doc.
return super().slice_locs(start, end, step)

def _partial_tup_index(self, tup, side="left"):
def _partial_tup_index(self, tup: tuple, side="left"):
if len(tup) > self._lexsort_depth:
raise UnsortedIndexError(
f"Key length ({len(tup)}) was greater than MultiIndex lexsort depth "
Expand Down
5 changes: 1 addition & 4 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ def __new__(
name = maybe_extract_name(name, data, cls)

if is_scalar(data):
raise TypeError(
f"{cls.__name__}() must be called with a "
f"collection of some kind, {repr(data)} was passed"
)
raise cls._scalar_data_error(data)

if unit in {"Y", "y", "M"}:
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimes/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def test_constructor_coverage(self):
with pytest.raises(TypeError, match=msg):
date_range(start="1/1/2000", periods="foo", freq="D")

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

Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/indexes/multi/test_isin.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ def test_isin_level_kwarg():
def test_isin_multi_index_with_missing_value(labels, expected, level):
# GH 19132
midx = MultiIndex.from_arrays([[np.nan, "a", "b"], ["c", "d", np.nan]])
tm.assert_numpy_array_equal(midx.isin(labels, level=level), expected)
result = midx.isin(labels, level=level)
tm.assert_numpy_array_equal(result, expected)
2 changes: 1 addition & 1 deletion pandas/tests/indexes/timedeltas/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_constructor_coverage(self):
timedelta_range(start="1 days", periods="foo", freq="D")

msg = (
r"TimedeltaIndex\(\) must be called with a collection of some kind, "
r"TimedeltaIndex\(\.\.\.\) must be called with a collection of some kind, "
"'1 days' was passed"
)
with pytest.raises(TypeError, match=msg):
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/io/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ def test_read_expands_user_home_dir(
@pytest.mark.filterwarnings(
"ignore:CategoricalBlock is deprecated:DeprecationWarning"
)
@pytest.mark.filterwarnings( # pytables np.object usage
"ignore:`np.object` is a deprecated alias:DeprecationWarning"
)
def test_read_fspath_all(self, reader, module, path, datapath):
pytest.importorskip(module)
path = datapath(*path)
Expand Down Expand Up @@ -309,6 +312,9 @@ def test_write_fspath_all(self, writer_name, writer_kwargs, module):

assert result == expected

@pytest.mark.filterwarnings( # pytables np.object usage
"ignore:`np.object` is a deprecated alias:DeprecationWarning"
)
@td.skip_array_manager_not_yet_implemented # TODO(ArrayManager) IO HDF5
def test_write_fspath_hdf5(self):
# Same test as write_fspath_all, except HDF5 files aren't
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/reshape/merge/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ def test_join_hierarchical_mixed(self):
other_df = DataFrame([(1, 2, 3), (7, 10, 6)], columns=["a", "b", "d"])
other_df.set_index("a", inplace=True)
# GH 9455, 12219
with tm.assert_produces_warning(FutureWarning):
msg = "merging between different levels is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
result = merge(new_df, other_df, left_index=True, right_index=True)
assert ("b", "mean") in result
assert "b" in result
Expand Down
18 changes: 13 additions & 5 deletions pandas/tests/series/test_logical_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,15 @@ def test_reversed_xor_with_index_returns_index(self):
idx1 = Index([True, False, True, False])
idx2 = Index([1, 0, 1, 0])

msg = "operating as a set operation"

expected = Index.symmetric_difference(idx1, ser)
with tm.assert_produces_warning(FutureWarning):
with tm.assert_produces_warning(FutureWarning, match=msg):
result = idx1 ^ ser
tm.assert_index_equal(result, expected)

expected = Index.symmetric_difference(idx2, ser)
with tm.assert_produces_warning(FutureWarning):
with tm.assert_produces_warning(FutureWarning, match=msg):
result = idx2 ^ ser
tm.assert_index_equal(result, expected)

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

msg = "operating as a set operation"

expected = Series(op(idx1.values, ser.values))
with tm.assert_produces_warning(FutureWarning):
with tm.assert_produces_warning(FutureWarning, match=msg):
result = op(ser, idx1)
tm.assert_series_equal(result, expected)

expected = Series(op(idx2.values, ser.values))
with tm.assert_produces_warning(FutureWarning):
with tm.assert_produces_warning(FutureWarning, match=msg):
result = op(ser, idx2)
tm.assert_series_equal(result, expected)

Expand All @@ -331,7 +335,11 @@ def test_reverse_ops_with_index(self, op, expected):
# multi-set Index ops are buggy, so let's avoid duplicates...
ser = Series([True, False])
idx = Index([False, True])
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):

msg = "operating as a set operation"
with tm.assert_produces_warning(
FutureWarning, match=msg, check_stacklevel=False
):
# behaving as set ops is deprecated, will become logical ops
result = op(ser, idx)
tm.assert_index_equal(result, expected)
Expand Down