pydata/pandas — pull request #8294 by ischwabacher (2014-09-17 16:22:35+00:00)
Title: ERR: DataFrame.from_records raises misleading exception on shape mismatch

Currently, `DataFrame.from_records` raises a misleading exception when the shape of the input data do not match the shape implied by the axes:

```python
In [1]: import pandas as pd

In [2]: pd.DataFrame.from_records([(0, 1), (0, 1), (0, 1)], index=[0, 1],
...: columns=['A', 'B'])
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
1 pd.DataFrame.from_records([(0, 1), (0, 1), (0, 1)], index=[0, 1],
----> 2 columns=['A', 'B'])

/Users/afni/homebrew/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/frame.pyc in from_records(cls, data, index, exclude, columns, coerce_float, nrows)
833
834 mgr = _arrays_to_mgr(arrays, arr_columns, result_index,
--> 835 columns)
836
837 return cls(mgr)

/Users/afni/homebrew/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/frame.pyc in _arrays_to_mgr(arrays, arr_names, index, columns, dtype)
4628 axes = [_ensure_index(columns), _ensure_index(index)]
4629
-> 4630 return create_block_manager_from_arrays(arrays, arr_names, axes)
4631
4632

/Users/afni/homebrew/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/internals.pyc in create_block_manager_from_arrays(arrays, names, axes)
3238 return mgr
3239 except (ValueError) as e:
-> 3240 construction_error(len(arrays), arrays[0].shape[1:], axes, e)
3241
3242

/Users/afni/homebrew/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/internals.pyc in construction_error(tot_items, block_shape, axes, e)
3209 raise e
3210 raise ValueError("Shape of passed values is {0}, indices imply {1}".format(
-> 3211 passed,implied))
3212
3213

ValueError: Shape of passed values is (2,), indices imply (2, 2)
```

This error message leads the user to believe that the error is internal (after all, the input data were *definitely* 2-dimensional) and hides the true error, which is that the shape of the passed values is actually `(2, 3)`.

For some reason, this behavior was explicitly specified by a test.