Skip to content

Commit 12413a8

Browse files
committed
Fix DataFrame.from_records error message
Make `create_block_manager_from_arrays` error message use the correct dimensions. This is different from the situation in `create_block_manager_from_blocks` because in that method the blocks are concatenated along their first dimension, whereas in this method the arrays are concatenated along a new dimension. Also fix `test_from_records_to_records`, which specified a misleading error message when the shape of the input data did not match the shape implied by the indices. In particular, the error message omitted the offending dimension entirely!
1 parent ef1fb2d commit 12413a8

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

pandas/core/internals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3507,7 +3507,7 @@ def create_block_manager_from_arrays(arrays, names, axes):
35073507
mgr._consolidate_inplace()
35083508
return mgr
35093509
except (ValueError) as e:
3510-
construction_error(len(arrays), arrays[0].shape[1:], axes, e)
3510+
construction_error(len(arrays), arrays[0].shape, axes, e)
35113511

35123512

35133513
def form_blocks(arrays, names, axes):

pandas/tests/test_frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4032,7 +4032,7 @@ def test_from_records_to_records(self):
40324032
tm.assert_frame_equal(DataFrame.from_records(arr2), DataFrame(arr2))
40334033

40344034
# wrong length
4035-
msg = r'Shape of passed values is \(3,\), indices imply \(3, 1\)'
4035+
msg = r'Shape of passed values is \(3, 2\), indices imply \(3, 1\)'
40364036
with assertRaisesRegexp(ValueError, msg):
40374037
DataFrame.from_records(arr, index=index[:-1])
40384038

0 commit comments

Comments
 (0)