Skip to content

Commit c972e4c

Browse files
committed
REGR: from_records not initializing subclasses properly
1 parent ec3eddd commit c972e4c

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v2.2.2.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Fixed regressions
1616
- :meth:`DataFrame.__dataframe__` was producing incorrect data buffers when the a column's type was a pandas nullable on with missing values (:issue:`56702`)
1717
- :meth:`DataFrame.__dataframe__` was producing incorrect data buffers when the a column's type was a pyarrow nullable on with missing values (:issue:`57664`)
1818
- Avoid issuing a spurious ``DeprecationWarning`` when a custom :class:`DataFrame` or :class:`Series` subclass method is called (:issue:`57553`)
19+
- Fixed regression in :meth:`DataFrame.from_records` not initializing subclasses properly (:issue:`57008`)
1920
- Fixed regression in precision of :func:`to_datetime` with string and ``unit`` input (:issue:`57051`)
2021

2122
.. ---------------------------------------------------------------------------

pandas/core/frame.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,8 @@ def maybe_reorder(
23022302
columns = columns.drop(exclude)
23032303

23042304
mgr = arrays_to_mgr(arrays, columns, result_index)
2305-
return cls._from_mgr(mgr, axes=mgr.axes)
2305+
result = cls._from_mgr(mgr, axes=mgr.axes)
2306+
return result._constructor_from_mgr(mgr, axes=mgr.axes)
23062307

23072308
def to_records(
23082309
self, index: bool = True, column_dtypes=None, index_dtypes=None

pandas/tests/frame/test_subclass.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,13 @@ def test_constructor_with_metadata():
769769
assert isinstance(subset, MySubclassWithMetadata)
770770

771771

772+
def test_constructor_with_metadata_from_records():
773+
# GH#57008
774+
df = MySubclassWithMetadata.from_records([{"a": 1, "b": 2}])
775+
assert df.my_metadata is None
776+
assert type(df) is MySubclassWithMetadata
777+
778+
772779
class SimpleDataFrameSubClass(DataFrame):
773780
"""A subclass of DataFrame that does not define a constructor."""
774781

0 commit comments

Comments
 (0)