Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BUG: Fix DataFrame constructor misclassification of array-like with 'name' attribute (#61443)#61451

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mroeschke merged 3 commits intopandas-dev:mainfromiabhi4:fix-61443-df-constructor
May 19, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
1 change: 1 addition & 0 deletionsdoc/source/whatsnew/v3.0.0.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -904,6 +904,7 @@ Other
- Bug in ``Series.list`` methods not preserving the original name. (:issue:`60522`)
- Bug in printing a :class:`DataFrame` with a :class:`DataFrame` stored in :attr:`DataFrame.attrs` raised a ``ValueError`` (:issue:`60455`)
- Bug in printing a :class:`Series` with a :class:`DataFrame` stored in :attr:`Series.attrs` raised a ``ValueError`` (:issue:`60568`)
- Fixed bug where the :class:`DataFrame` constructor misclassified array-like objects with a ``.name`` attribute as :class:`Series` or :class:`Index` (:issue:`61443`)
- Fixed regression in :meth:`DataFrame.from_records` not initializing subclasses properly (:issue:`57008`)

.. ***DO NOT USE THIS SECTION***
Expand Down
8 changes: 6 additions & 2 deletionspandas/core/frame.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,6 +112,10 @@
BaseMaskedDtype,
ExtensionDtype,
)
from pandas.core.dtypes.generic import (
ABCIndex,
ABCSeries,
)
from pandas.core.dtypes.missing import (
isna,
notna,
Expand DownExpand Up@@ -795,12 +799,12 @@ def __init__(
dtype,
copy,
)
elifgetattr(data,"name", None) is not None:
elifisinstance(data,(ABCSeries, ABCIndex)) and data.name is not None:
# i.e. Series/Index with non-None name
mgr = dict_to_mgr(
# error: Item "ndarray" of "Union[ndarray, Series, Index]" has no
# attribute "name"
{data.name: data}, # type: ignore[union-attr]
{data.name: data},
index,
columns,
dtype=dtype,
Expand Down
13 changes: 13 additions & 0 deletionspandas/tests/frame/test_constructors.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2780,6 +2780,19 @@ def test_construction_nan_value_timedelta64_dtype(self):
)
tm.assert_frame_equal(result, expected)

def test_dataframe_from_array_like_with_name_attribute(self):
# GH#61443
class DummyArray(np.ndarray):
def __new__(cls, input_array):
obj = np.asarray(input_array).view(cls)
obj.name = "foo"
return obj

dummy = DummyArray(np.eye(3))
df = DataFrame(dummy)
expected = DataFrame(np.eye(3))
tm.assert_frame_equal(df, expected)


class TestDataFrameConstructorIndexInference:
def test_frame_from_dict_of_series_overlapping_monthly_period_indexes(self):
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp