-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: DataFrame
constructor not compatible with array-like classes that have a 'name'
attribute
#61443
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
Comments
Hi! I'm a beginner contributor and spent some time digging into this — here's what I found: When an array-like object (like This behavior is unexpected because the array-like input is valid (2D, convertible to DataFrame), but it's being misinterpreted solely due to the presence of I'd like to work on this issue. I'm happy to follow any guidance or suggestions! |
Yes exactly - the check for a - elif getattr(data, "name", None) is not None:
+ elif isinstance(data, (Series, Index)): though there may be some historical or other reason for why |
@user27182 Thanks for the confirmation! I looked into the historical context of the It appears to have been introduced in this commit from 2013 by @jreback as part of a broader set of fixes (GH4204, GH4463) related to Series/indexing and type coercion — notably when Back then, checking for So unless there's some subtle compatibility case that still requires relying on elif isinstance(data, (ABCSeries, ABCIndexClass)): |
Thanks for the report @user27182 and investigaiton @iabhi4. I agree it seems like we should switch to an isinstance check here. PRs are welcome! |
…name' attribute Previously, any object with a .name attribute (like some vtkArray-like objects) was assumed to be a Series or Index, causing the constructor to misinterpret the input. This fix ensures we only apply the named-Index/Series logic when the input is actually an instance of ABCSeries or ABCIndex *and* has a non-None name. Closes pandas-dev#61443.
I’ve submitted a PR implementing the |
…name' attribute (#61443) (#61451) * BUG: Fix DataFrame constructor misclassification of array-like with 'name' attribute Previously, any object with a .name attribute (like some vtkArray-like objects) was assumed to be a Series or Index, causing the constructor to misinterpret the input. This fix ensures we only apply the named-Index/Series logic when the input is actually an instance of ABCSeries or ABCIndex *and* has a non-None name. Closes #61443. * Apply pre-commit fixes: isort and remove unused type ignore * TST/CLN: Add issue reference in test and update whatsnew for GH#61443
Uh oh!
There was an error while loading. Please reload this page.
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Originally posted in pyvista/pyvista#7519
Issue Description
Wrapping a
DataFrame
with the array-like object above results in an unexpectedValueError
being raised. The cause is this line, which assumes that the input object must be aSeries
orIndex
type based on having a'name'
attribute.pandas/pandas/core/frame.py
Lines 798 to 799 in 41968a5
This assumption fails for the
VTKArray
poly.points
, which also has a'name'
attribute.Expected Behavior
No error should be raised, and the array-like input should be wrapped correctly by
DataFrame
Installed Versions
INSTALLED VERSIONS
commit : 0691c5c
python : 3.12.2
python-bits : 64
OS : Darwin
OS-release : 23.4.0
Version : Darwin Kernel Version 23.4.0: Fri Mar 15 00:19:22 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8112
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_CA.UTF-8
pandas : 2.2.3
numpy : 1.26.4
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 25.1.1
Cython : None
sphinx : 8.1.3
IPython : 8.36.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.4
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : 6.131.9
gcsfs : None
jinja2 : 3.1.6
lxml.etree : None
matplotlib : 3.10.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : 8.3.5
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.14.1
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: