Skip to content

Commit f224dad

Browse files
Terji PetersenTerji Petersen
Terji Petersen
authored and
Terji Petersen
committed
BUG/API: Indexes on empty frames/series should be RangeIndex, are Index[object]
1 parent f09d514 commit f224dad

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

pandas/core/frame.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2232,8 +2232,7 @@ def maybe_reorder(
22322232

22332233
result_index = None
22342234
if len(arrays) == 0 and index is None and length == 0:
2235-
# for backward compat use an object Index instead of RangeIndex
2236-
result_index = Index([])
2235+
result_index = default_index(0)
22372236

22382237
arrays, arr_columns = reorder_arrays(arrays, arr_columns, columns, length)
22392238
return arrays, arr_columns, result_index

pandas/core/internals/construction.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def dict_to_mgr(
435435

436436
else:
437437
keys = list(data.keys())
438-
columns = Index(keys)
438+
columns = Index(keys) if len(keys) else default_index(0)
439439
arrays = [com.maybe_iterable_to_list(data[k]) for k in keys]
440440
arrays = [arr if not isinstance(arr, Index) else arr._data for arr in arrays]
441441

@@ -582,7 +582,7 @@ def _extract_index(data) -> Index:
582582
"""
583583
index = None
584584
if len(data) == 0:
585-
index = Index([])
585+
index = default_index(0)
586586
else:
587587
raw_lengths = []
588588
indexes: list[list[Hashable] | Index] = []

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def _init_dict(
512512
values = []
513513
keys = index
514514
else:
515-
keys, values = (), []
515+
keys, values = default_index(0), []
516516

517517
# Input is now list-like, so rely on "standard" construction:
518518

0 commit comments

Comments
 (0)