Skip to content

[ArrayManager] Fix DataFrame.from_records with emtpy size #40301

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 1 commit into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def arrays_to_mgr(
if typ == "block":
return create_block_manager_from_arrays(arrays, arr_names, axes)
elif typ == "array":
if len(columns) != len(arrays):
assert len(arrays) == 0
arrays = [np.array([], dtype=object) for _ in range(len(columns))]
return ArrayManager(arrays, [index, columns])
else:
raise ValueError(f"'typ' needs to be one of {{'block', 'array'}}, got '{typ}'")
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/frame/constructors/test_from_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pytz

from pandas.compat import is_platform_little_endian
import pandas.util._test_decorators as td

from pandas import (
CategoricalIndex,
Expand Down Expand Up @@ -120,7 +119,6 @@ def test_from_records_sequencelike(self):
tm.assert_series_equal(result["C"], df["C"])
tm.assert_series_equal(result["E1"], df["E1"].astype("float64"))

@td.skip_array_manager_not_yet_implemented # TODO(ArrayManager) empty from_records
def test_from_records_sequencelike_empty(self):
# empty case
result = DataFrame.from_records([], columns=["foo", "bar", "baz"])
Expand Down Expand Up @@ -217,7 +215,6 @@ def __iter__(self):
expected = DataFrame.from_records(tups)
tm.assert_frame_equal(result, expected)

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

@td.skip_array_manager_not_yet_implemented # TODO(ArrayManager) empty from_records
def test_from_records_misc_brokenness(self):
# GH#2179

Expand Down Expand Up @@ -440,7 +436,6 @@ def test_from_records_misc_brokenness(self):
)
tm.assert_series_equal(result, expected)

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