Skip to content

Commit 8f9adb7

Browse files
committed
Merge pull request #4727 from jtratner/fix-from-records-unstructured-ndarray
BUG: Fix DataFrame.from_records w/ normal ndarray.
2 parents 4532fe4 + d312a37 commit 8f9adb7

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

doc/source/release.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ See :ref:`Internal Refactoring<whatsnew_0130.refactoring>`
307307
- Fix boolean comparison with a DataFrame on the lhs, and a list/tuple on the rhs (:issue:`4576`)
308308
- Fix error/dtype conversion with setitem of ``None`` on ``Series/DataFrame`` (:issue:`4667`)
309309
- Fix decoding based on a passed in non-default encoding in ``pd.read_stata`` (:issue:`4626`)
310-
- Fix some inconsistencies with ``Index.rename`` and ``MultiIndex.rename``,
311-
etc. (:issue:`4718`, :issue:`4628`)
310+
- Fix some inconsistencies with ``Index.rename`` and ``MultiIndex.rename`` (:issue:`4718`, :issue:`4628`)
311+
- Fix ``DataFrame.from_records`` with a plain-vanilla ``ndarray``. (:issue:`4727`)
312312

313313
pandas 0.12
314314
===========

pandas/core/frame.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4876,7 +4876,9 @@ def _to_arrays(data, columns, coerce_float=False, dtype=None):
48764876
return _list_of_series_to_arrays(data, columns,
48774877
coerce_float=coerce_float,
48784878
dtype=dtype)
4879-
elif isinstance(data, (np.ndarray, Series)):
4879+
elif (isinstance(data, (np.ndarray, Series))
4880+
and data.dtype.names is not None):
4881+
48804882
columns = list(data.dtype.names)
48814883
arrays = [data[k] for k in columns]
48824884
return arrays, columns

pandas/tests/test_frame.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3468,12 +3468,15 @@ def test_from_records_to_records(self):
34683468
indexed_frame = DataFrame.from_records(arr, index=index)
34693469
self.assert_(np.array_equal(indexed_frame.index, index))
34703470

3471+
# without names, it should go to last ditch
3472+
arr2 = np.zeros((2,3))
3473+
tm.assert_frame_equal(DataFrame.from_records(arr2), DataFrame(arr2))
3474+
34713475
# wrong length
34723476
self.assertRaises(Exception, DataFrame.from_records, arr,
34733477
index=index[:-1])
34743478

34753479
indexed_frame = DataFrame.from_records(arr, index='f1')
3476-
self.assertRaises(Exception, DataFrame.from_records, np.zeros((2, 3)))
34773480

34783481
# what to do?
34793482
records = indexed_frame.to_records()

0 commit comments

Comments
 (0)