Skip to content

Commit 941d079

Browse files
authored
BUG: #58594 (#59258)
* BUG: #58594 * updating whatsnew doc * updates based on feedback from @mroeschke * switching to default_index()
1 parent a94dd99 commit 941d079

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ Interval
547547
Indexing
548548
^^^^^^^^
549549
- Bug in :meth:`DataFrame.__getitem__` returning modified columns when called with ``slice`` in Python 3.12 (:issue:`57500`)
550+
- Bug in :meth:`DataFrame.from_records` throwing a ``ValueError`` when passed an empty list in ``index`` (:issue:`58594`)
550551
-
551552

552553
Missing

pandas/core/indexes/base.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -7473,9 +7473,12 @@ def ensure_index_from_sequences(sequences, names=None) -> Index:
74737473
--------
74747474
ensure_index
74757475
"""
7476+
from pandas.core.indexes.api import default_index
74767477
from pandas.core.indexes.multi import MultiIndex
74777478

7478-
if len(sequences) == 1:
7479+
if len(sequences) == 0:
7480+
return default_index(0)
7481+
elif len(sequences) == 1:
74797482
if names is not None:
74807483
names = names[0]
74817484
return Index(maybe_sequence_to_range(sequences[0]), name=names)

pandas/tests/frame/constructors/test_from_records.py

+6
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ def test_from_records_sequencelike_empty(self):
148148
assert len(result) == 0
149149
assert len(result.columns) == 0
150150

151+
def test_from_records_sequencelike_empty_index(self):
152+
result = DataFrame.from_records([], index=[])
153+
assert len(result) == 0
154+
assert len(result.columns) == 0
155+
assert len(result.index) == 0
156+
151157
def test_from_records_dictlike(self):
152158
# test the dict methods
153159
df = DataFrame(

0 commit comments

Comments
 (0)