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 2 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 as an index (:issue:`58594`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 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`)

Copy link
Contributor Author

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!

-

Missing
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Copy link
Member

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

elif len(sequences) == 1:
if names is not None:
names = names[0]
return Index(maybe_sequence_to_range(sequences[0]), name=names)
Expand Down
5 changes: 5 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,11 @@ def test_from_records_sequencelike_empty(self):
assert len(result) == 0
assert len(result.columns) == 0

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