Skip to content
Prev Previous commit
Next Next commit
DOC: improved docu of the value error msg changes
TST: adjusted panel test for change in value error msg in block manager TST: adjusted dataframe init test from json for change in value error msg in block manager
  • Loading branch information
meiermark committed Jan 12, 2019
commit 46d4d55c2776ab8c6750017ba7de6b4b39621f70
4 changes: 3 additions & 1 deletion doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,9 @@ Other
^^^^^

- Bug where C variables were declared with external linkage causing import errors if certain other C libraries were imported before Pandas. (:issue:`24113`)
- Switched shape in ``ValueError`` message when constructiong a :class:`DataFrame` with parameters ``columns`` and ``index`` not matching the shape of the input data. (:issue:`20742`)
- Changed ``ValueError`` message when constructiong a :class:`DataFrame` with parameters ``columns`` and ``index`` not matching the shape of the input data. New message: "Shape of passed values is (``index``, ``columns``), indices imply (``index``, ``columns``)" (:issue:`20742`)
- Changed ``ValueError`` message when constructiong a :class:`Panel` with parameters ``items``, ``major index`` and ``minor index`` not matching the shape of the input data. New message: "Shape of passed values is (``major``, ``minor``, ``items``), indices imply (``major``, ``minor``, ``items``)" (related to :issue:`20742`)


.. _whatsnew_0.24.0.contributors:

Expand Down
6 changes: 4 additions & 2 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1673,8 +1673,10 @@ def create_block_manager_from_arrays(arrays, names, axes):

def construction_error(tot_items, block_shape, axes, e=None):
""" raise a helpful message about our construction """
passed = tuple(map(int, reversed([tot_items] + list(block_shape))))
implied = tuple(map(int, reversed([len(ax) for ax in axes])))
passed = tuple(map(int, list(block_shape) + [tot_items]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just do a reverse if ndim == 2 here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not a good idea for panels with 3 dimensions (items, major, minor)
with reversed for ndim == 2: (items, major, minor)
current: (major, minor, items)

The current version is the intended behavior, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care about Panels, they are being removed shortly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only affect ndim==2


implied = [] if len(axes) == 0 \
else [len(ax) for ax in axes[1:] + [axes[0]]]
if passed == implied and e is not None:
raise e
if block_shape[0] == 0:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def test_frame_from_json_bad_data(self):
json = StringIO('{"columns":["A","B"],'
'"index":["2","3"],'
'"data":[[1.0,"1"],[2.0,"2"],[null,"3"]]}')
msg = r"Shape of passed values is \(2, 3\), indices imply \(2, 2\)"
msg = r"Shape of passed values is \(3, 2\), indices imply \(2, 2\)"
with pytest.raises(ValueError, match=msg):
read_json(json, orient="split")

Expand Down
18 changes: 3 additions & 15 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,23 +1143,11 @@ def test_from_dict_mixed_orient(self):
assert panel['A'].values.dtype == np.float64

def test_constructor_error_msgs(self):
msg = (r"Shape of passed values is \(3, 4, 5\), "
r"indices imply \(4, 5, 5\)")
msg = (r"Shape of passed values is \(4, 5, 3\), "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave panel entirely.

r"indices imply \(5, 6, 4\)")
with pytest.raises(ValueError, match=msg):
Panel(np.random.randn(3, 4, 5),
lrange(4), lrange(5), lrange(5))

msg = (r"Shape of passed values is \(3, 4, 5\), "
r"indices imply \(5, 4, 5\)")
with pytest.raises(ValueError, match=msg):
Panel(np.random.randn(3, 4, 5),
lrange(5), lrange(4), lrange(5))

msg = (r"Shape of passed values is \(3, 4, 5\), "
r"indices imply \(5, 5, 4\)")
with pytest.raises(ValueError, match=msg):
Panel(np.random.randn(3, 4, 5),
lrange(5), lrange(5), lrange(4))
lrange(4), lrange(5), lrange(6))

def test_conform(self):
df = self.panel['ItemA'][:-5].filter(items=['A', 'B'])
Expand Down