Skip to content

REGR: fix return class in _constructor_from_mgr for simple subclasses #55764

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

Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
ivirshup committed Oct 31, 2023
commit 6c5086d1be8baa586b1ad13fb5583a42fd1acbba
18 changes: 18 additions & 0 deletions pandas/tests/frame/test_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,3 +773,21 @@ def test_constructor_with_metadata():
)
subset = df[["A", "B"]]
assert isinstance(subset, MySubclassWithMetadata)


class SimpleSubClass(DataFrame):
"""A subclass of DataFrame that does not define a constructor."""


class TestSubclassWithoutConstructor:
def test_copy(self):
expected = DataFrame({"a": [1, 2, 3]})
result = SimpleSubClass(expected).copy()

tm.assert_frame_equal(result, expected)

def test_groupby(self):
df = SimpleSubClass(DataFrame({"a": [1, 2, 3]}))

for _, v in df.groupby("a"):
assert isinstance(v, DataFrame)