Skip to content

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

Merged
merged 4 commits into from
Jul 18, 2024
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 in ``index`` (:issue:`58594`)
-

Missing
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7473,9 +7473,12 @@ def ensure_index_from_sequences(sequences, names=None) -> Index:
--------
ensure_index
"""
from pandas.core.indexes.api import default_index
from pandas.core.indexes.multi import MultiIndex

if len(sequences) == 1:
if len(sequences) == 0:
return default_index(0)
elif len(sequences) == 1:
if names is not None:
names = names[0]
return Index(maybe_sequence_to_range(sequences[0]), name=names)
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/frame/constructors/test_from_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ def test_from_records_sequencelike_empty(self):
assert len(result) == 0
assert len(result.columns) == 0

def test_from_records_sequencelike_empty_index(self):
result = DataFrame.from_records([], index=[])
Copy link
Member

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?

assert len(result) == 0
assert len(result.columns) == 0
assert len(result.index) == 0

def test_from_records_dictlike(self):
# test the dict methods
df = DataFrame(
Expand Down