Skip to content

Commit a681b47

Browse files
[ArrayManager] Fix DataFrame.from_records with emtpy size (#40301)
1 parent d910a44 commit a681b47

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

pandas/core/internals/construction.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ def arrays_to_mgr(
128128
if typ == "block":
129129
return create_block_manager_from_arrays(arrays, arr_names, axes)
130130
elif typ == "array":
131+
if len(columns) != len(arrays):
132+
assert len(arrays) == 0
133+
arrays = [np.array([], dtype=object) for _ in range(len(columns))]
131134
return ArrayManager(arrays, [index, columns])
132135
else:
133136
raise ValueError(f"'typ' needs to be one of {{'block', 'array'}}, got '{typ}'")

pandas/tests/frame/constructors/test_from_records.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import pytz
77

88
from pandas.compat import is_platform_little_endian
9-
import pandas.util._test_decorators as td
109

1110
from pandas import (
1211
CategoricalIndex,
@@ -120,7 +119,6 @@ def test_from_records_sequencelike(self):
120119
tm.assert_series_equal(result["C"], df["C"])
121120
tm.assert_series_equal(result["E1"], df["E1"].astype("float64"))
122121

123-
@td.skip_array_manager_not_yet_implemented # TODO(ArrayManager) empty from_records
124122
def test_from_records_sequencelike_empty(self):
125123
# empty case
126124
result = DataFrame.from_records([], columns=["foo", "bar", "baz"])
@@ -217,7 +215,6 @@ def __iter__(self):
217215
expected = DataFrame.from_records(tups)
218216
tm.assert_frame_equal(result, expected)
219217

220-
@td.skip_array_manager_not_yet_implemented # TODO(ArrayManager) empty from_records
221218
def test_from_records_len0_with_columns(self):
222219
# GH#2633
223220
result = DataFrame.from_records([], index="foo", columns=["foo", "bar"])
@@ -401,7 +398,6 @@ def create_dict(order_id):
401398
result = DataFrame.from_records(documents, index=["order_id", "quantity"])
402399
assert result.index.names == ("order_id", "quantity")
403400

404-
@td.skip_array_manager_not_yet_implemented # TODO(ArrayManager) empty from_records
405401
def test_from_records_misc_brokenness(self):
406402
# GH#2179
407403

@@ -440,7 +436,6 @@ def test_from_records_misc_brokenness(self):
440436
)
441437
tm.assert_series_equal(result, expected)
442438

443-
@td.skip_array_manager_not_yet_implemented # TODO(ArrayManager) empty from_records
444439
def test_from_records_empty(self):
445440
# GH#3562
446441
result = DataFrame.from_records([], columns=["a", "b", "c"])

0 commit comments

Comments
 (0)