-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: pandas-dev#58594 #59258
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
BUG: pandas-dev#58594 #59258
Conversation
No errors raised for all cases noted in #58594.
|
@@ -148,6 +148,11 @@ def test_from_records_sequencelike_empty(self): | |||
assert len(result) == 0 | |||
assert len(result.columns) == 0 | |||
|
|||
result = DataFrame.from_records([], index=[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make this a separate test?
pandas/core/indexes/base.py
Outdated
@@ -7475,7 +7475,9 @@ def ensure_index_from_sequences(sequences, names=None) -> Index: | |||
""" | |||
from pandas.core.indexes.multi import MultiIndex | |||
|
|||
if len(sequences) == 1: | |||
if len(sequences) == 0: | |||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the typing, this should return an Index
doc/source/whatsnew/v3.0.0.rst
Outdated
@@ -546,6 +546,7 @@ Interval | |||
Indexing | |||
^^^^^^^^ | |||
- Bug in :meth:`DataFrame.__getitem__` returning modified columns when called with ``slice`` in Python 3.12 (:issue:`57500`) | |||
- Bug in :meth:`DataFrame.from_records()` throwing a ValueError when passed an empty list as an index (:issue:`58594`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Bug in :meth:`DataFrame.from_records()` throwing a ValueError when passed an empty list as an index (:issue:`58594`) | |
- Bug in :meth:`DataFrame.from_records` throwing a ``ValueError`` when passed an empty list in ``index`` (:issue:`58594`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mroeschke, I just pushed a commit to address all your feedback. Mind taking another look?
Thanks!
pandas/core/indexes/base.py
Outdated
@@ -7475,7 +7475,9 @@ def ensure_index_from_sequences(sequences, names=None) -> Index: | |||
""" | |||
from pandas.core.indexes.multi import MultiIndex | |||
|
|||
if len(sequences) == 1: | |||
if len(sequences) == 0: | |||
return Index([]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use default_index(0)
here? Can import it from pandas.core.indexes.api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not working since pandas.core.indexes.api
imports pandas.core.indexes.base
on L19 so I get the following error:
Traceback (most recent call last):
.
.
.
File "/home/op/git/pandas/pandas/core/indexes/base.py", line 177, in <module>
from pandas.core.indexes.api import default_index
ImportError: cannot import name 'default_index' from partially initialized module 'pandas.core.indexes.api' (most likely due to a circular import) (/home/op/git/pandas/pandas/core/indexes/api.py)
Just out of curiosity why is default_index(0)
preferred over Index([])
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll probably need to import it in the method.
default_index
is, as the name implies, the "default" implementation of an index used in constructors if not explicitly specified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying.
Thanks @kirill-bash |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.