Skip to content

Remove unnecessary @td.skip_if_no("pathlib") #30379

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

Closed
wants to merge 12 commits into from
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ Groupby/resample/rolling
- Bug in :meth:`DataFrame.groupby` where ``any``, ``all``, ``nunique`` and transform functions would incorrectly handle duplicate column labels (:issue:`21668`)
- Bug in :meth:`DataFrameGroupBy.agg` with timezone-aware datetime64 column incorrectly casting results to the original dtype (:issue:`29641`)
- Bug in :meth:`DataFrame.groupby` when using axis=1 and having a single level columns index (:issue:`30208`)
- Bug in :meth:`DataFrame.groupby` when using nunique on axis=1 (:issue:`30253`)

Reshaping
^^^^^^^^^
Expand Down
15 changes: 13 additions & 2 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1813,9 +1813,20 @@ def groupby_series(obj, col=None):
# Try to consolidate with normal wrapping functions
from pandas.core.reshape.concat import concat

results = [groupby_series(content, label) for label, content in obj.items()]
axis_number = obj._get_axis_number(self.axis)
other_axis = int(not axis_number)
if axis_number == 0:
iter_func = obj.items
else:
iter_func = obj.iterrows

results = [groupby_series(content, label) for label, content in iter_func()]
results = concat(results, axis=1)
results.columns.names = obj.columns.names

if axis_number == 1:
results = results.T

results._get_axis(other_axis).names = obj._get_axis(other_axis).names

if not self.as_index:
results.index = ibase.default_index(len(results))
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1994,3 +1994,20 @@ def test_dup_labels_output_shape(groupby_func, idx):

assert result.shape == (1, 2)
tm.assert_index_equal(result.columns, idx)


def test_groupby_crash_on_nunique(axis):
# Fix following 30253
df = pd.DataFrame({("A", "B"): [1, 2], ("A", "C"): [1, 3], ("D", "B"): [0, 0]})

axis_number = df._get_axis_number(axis)
if not axis_number:
df = df.T

result = df.groupby(axis=axis_number, level=0).nunique()

expected = pd.DataFrame({"A": [1, 2], "D": [1, 1]})
if not axis_number:
expected = expected.T

tm.assert_frame_equal(result, expected)
1 change: 0 additions & 1 deletion pandas/tests/io/pytables/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -4594,7 +4594,6 @@ def test_read_nokey_empty(self, setup_path):
with pytest.raises(ValueError):
read_hdf(path)

@td.skip_if_no("pathlib")
def test_read_from_pathlib_path(self, setup_path):

# GH11773
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/io/sas/test_sas7bdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def test_from_iterator(self):
tm.assert_frame_equal(df, df0.iloc[2:5, :])
rdr.close()

@td.skip_if_no("pathlib")
def test_path_pathlib(self):
from pathlib import Path

Expand Down
1 change: 0 additions & 1 deletion pandas/tests/io/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def test_expand_user_normal_path(self):
assert expanded_name == filename
assert os.path.expanduser(filename) == expanded_name

@td.skip_if_no("pathlib")
def test_stringify_path_pathlib(self):
rel_path = icom._stringify_path(Path("."))
assert rel_path == "."
Expand Down