Skip to content
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
6 changes: 6 additions & 0 deletions doc/source/whatsnew/v2.3.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ Bug fixes
- The :meth:`DataFrame.iloc` now works correctly with ``copy_on_write`` option when assigning values after subsetting the columns of a homogeneous DataFrame (:issue:`60309`)


Other Bug fixes
~~~~~~~~~~~~~~~~

- Fixed regression in :meth:`DataFrame.from_records` not initializing subclasses properly (:issue:`57008`)


.. ---------------------------------------------------------------------------
.. _whatsnew_233.contributors:

Expand Down
6 changes: 4 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2549,8 +2549,10 @@ def maybe_reorder(

manager = _get_option("mode.data_manager", silent=True)
mgr = arrays_to_mgr(arrays, columns, result_index, typ=manager)

return cls._from_mgr(mgr, axes=mgr.axes)
df = DataFrame._from_mgr(mgr, axes=mgr.axes)
if cls is not DataFrame:
return cls(df, copy=False)
return df

def to_records(
self, index: bool = True, column_dtypes=None, index_dtypes=None
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/frame/test_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,13 @@ def test_constructor_with_metadata():
assert isinstance(subset, MySubclassWithMetadata)


def test_constructor_with_metadata_from_records():
# GH#57008
df = MySubclassWithMetadata.from_records([{"a": 1, "b": 2}])
assert df.my_metadata is None
assert type(df) is MySubclassWithMetadata


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

Expand Down
Loading