Skip to content

CLN: tests, annotations #43186

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
Aug 25, 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
2 changes: 0 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4816,7 +4816,6 @@ def reindex(self: FrameOrSeries, *args, **kwargs) -> FrameOrSeries:
axes, level, limit, tolerance, method, fill_value, copy
).__finalize__(self, method="reindex")

@final
def _reindex_axes(
self: FrameOrSeries, axes, level, limit, tolerance, method, fill_value, copy
) -> FrameOrSeries:
Expand Down Expand Up @@ -8977,7 +8976,6 @@ def where(

return self._where(cond, other, inplace, axis, level, errors=errors)

@final
@doc(
where,
klass=_shared_doc_kwargs["klass"],
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1960,7 +1960,6 @@ def ohlc(self) -> DataFrame:
lambda x: x.ohlc(), self._obj_with_exclusions
)

@final
@doc(DataFrame.describe)
def describe(self, **kwargs):
with group_selection_context(self):
Expand Down Expand Up @@ -3093,7 +3092,6 @@ def shift(self, periods=1, freq=None, axis=0, fill_value=None):
)
return res

@final
@Substitution(name="groupby")
@Appender(_common_see_also)
def pct_change(self, periods=1, fill_method="pad", limit=None, freq=None, axis=0):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,7 @@ def construction_error(
# -----------------------------------------------------------------------


def _grouping_func(tup):
def _grouping_func(tup: tuple[int, ArrayLike]) -> tuple[bool, DtypeObj]:
# compat for numpy<1.21, in which comparing a np.dtype with an ExtensionDtype
# raises instead of returning False. Once earlier numpy versions are dropped,
# this can be simplified to `return tup[1].dtype`
Expand Down
50 changes: 27 additions & 23 deletions pandas/tests/generic/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,38 @@ class TestSeries(Generic):

@pytest.mark.parametrize("func", ["rename_axis", "_set_axis_name"])
def test_set_axis_name_mi(self, func):
s = Series(
ser = Series(
[11, 21, 31],
index=MultiIndex.from_tuples(
[("A", x) for x in ["a", "B", "c"]], names=["l1", "l2"]
),
)

result = methodcaller(func, ["L1", "L2"])(s)
assert s.index.name is None
assert s.index.names == ["l1", "l2"]
result = methodcaller(func, ["L1", "L2"])(ser)
assert ser.index.name is None
assert ser.index.names == ["l1", "l2"]
assert result.index.name is None
assert result.index.names, ["L1", "L2"]

def test_set_axis_name_raises(self):
s = Series([1])
ser = Series([1])
msg = "No axis named 1 for object type Series"
with pytest.raises(ValueError, match=msg):
s._set_axis_name(name="a", axis=1)
ser._set_axis_name(name="a", axis=1)

def test_get_bool_data_preserve_dtype(self):
o = Series([True, False, True])
result = o._get_bool_data()
self._compare(result, o)
ser = Series([True, False, True])
result = ser._get_bool_data()
self._compare(result, ser)

def test_nonzero_single_element(self):

# allow single item via bool method
s = Series([True])
assert s.bool()
ser = Series([True])
assert ser.bool()

s = Series([False])
assert not s.bool()
ser = Series([False])
assert not ser.bool()

@pytest.mark.parametrize("data", [np.nan, pd.NaT, True, False])
def test_nonzero_single_element_raise_1(self, data):
Expand Down Expand Up @@ -112,25 +112,29 @@ def test_metadata_propagation_indiv_resample(self):
def test_metadata_propagation_indiv(self):
# check that the metadata matches up on the resulting ops

o = Series(range(3), range(3))
o.name = "foo"
o2 = Series(range(3), range(3))
o2.name = "bar"
ser = Series(range(3), range(3))
ser.name = "foo"
ser2 = Series(range(3), range(3))
ser2.name = "bar"

result = o.T
self.check_metadata(o, result)
result = ser.T
self.check_metadata(ser, result)

_metadata = Series._metadata
_finalize = Series.__finalize__
Series._metadata = ["name", "filename"]
o.filename = "foo"
o2.filename = "bar"
ser.filename = "foo"
ser2.filename = "bar"

def finalize(self, other, method=None, **kwargs):
for name in self._metadata:
if method == "concat" and name == "filename":
value = "+".join(
[getattr(o, name) for o in other.objs if getattr(o, name, None)]
[
getattr(obj, name)
for obj in other.objs
if getattr(obj, name, None)
]
)
object.__setattr__(self, name, value)
else:
Expand All @@ -140,7 +144,7 @@ def finalize(self, other, method=None, **kwargs):

Series.__finalize__ = finalize

result = pd.concat([o, o2])
result = pd.concat([ser, ser2])
assert result.filename == "foo+bar"
assert result.name is None

Expand Down