Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
DatetimeIndex,
Index,
PeriodIndex,
RangeIndex,
default_index,
ensure_index,
ensure_index_from_sequences,
Expand Down Expand Up @@ -2283,7 +2284,7 @@ def maybe_reorder(
result_index = None
if len(arrays) == 0 and index is None and length == 0:
# for backward compat use an object Index instead of RangeIndex
result_index = Index([])
result_index = RangeIndex(start=0, stop=0, step=1)

arrays, arr_columns = reorder_arrays(arrays, arr_columns, columns, length)
return arrays, arr_columns, result_index
Expand Down
9 changes: 6 additions & 3 deletions pandas/tests/frame/constructors/test_from_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,10 @@ def test_from_records_misc_brokenness(self):
# GH#2179

data = {1: ["foo"], 2: ["bar"]}
index = RangeIndex(start=0, stop=0, step=1)

result = DataFrame.from_records(data, columns=["a", "b"])
exp = DataFrame(data, columns=["a", "b"])
exp = DataFrame(data, columns=["a", "b"], index=index)
tm.assert_frame_equal(result, exp)

# overlap in index/index_names
Expand Down Expand Up @@ -432,12 +433,14 @@ def test_from_records_misc_brokenness(self):

def test_from_records_empty(self):
# GH#3562
index = RangeIndex(start=0, stop=0, step=1)

result = DataFrame.from_records([], columns=["a", "b", "c"])
expected = DataFrame(columns=["a", "b", "c"])
expected = DataFrame(columns=["a", "b", "c"], index=index)
tm.assert_frame_equal(result, expected)

result = DataFrame.from_records([], columns=["a", "b", "b"])
expected = DataFrame(columns=["a", "b", "b"])
expected = DataFrame(columns=["a", "b", "b"], index=index)
tm.assert_frame_equal(result, expected)

def test_from_records_empty_with_nonempty_fields_gh3682(self):
Expand Down