Skip to content

BUG: (GH4851) path for 0-dim arrays in DataFrame construction were incorrect #4852

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
Sep 16, 2013
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
2 changes: 1 addition & 1 deletion doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Improvements to existing features
- ``Panel.to_excel()`` now accepts keyword arguments that will be passed to
its ``DataFrame``'s ``to_excel()`` methods. (:issue:`4750`)
- allow DataFrame constructor to accept more list-like objects, e.g. list of
``collections.Sequence`` and ``array.Array`` objects (:issue:`3783`,:issue:`42971`),
``collections.Sequence`` and ``array.Array`` objects (:issue:`3783`,:issue:`4297`, :issue:`4851`),
thanks @lgautier
- DataFrame constructor now accepts a numpy masked record array (:issue:`3478`),
thanks @jnothman
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
if index is None and isinstance(data[0], Series):
index = _get_names_from_index(data)

if is_list_like(data[0]) and getattr(data[0],'ndim',0) <= 1:
if is_list_like(data[0]) and getattr(data[0],'ndim',1) == 1:
arrays, columns = _to_arrays(data, columns, dtype=dtype)
columns = _ensure_index(columns)

Expand Down Expand Up @@ -4710,7 +4710,7 @@ def extract_index(data):
elif isinstance(v, dict):
have_dicts = True
indexes.append(list(v.keys()))
elif is_list_like(v) and getattr(v,'ndim',0) <= 1:
elif is_list_like(v) and getattr(v,'ndim',1) == 1:
have_raw_arrays = True
raw_lengths.append(len(v))

Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2675,6 +2675,13 @@ def test_constructor_list_of_lists(self):
self.assert_(com.is_integer_dtype(df['num']))
self.assert_(df['str'].dtype == np.object_)

# GH 4851
# list of 0-dim ndarrays
expected = DataFrame({ 0: range(10) })
data = [np.array(x) for x in range(10)]
result = DataFrame(data)
assert_frame_equal(result, expected)

def test_constructor_sequence_like(self):
# GH 3783
# collections.Squence like
Expand Down