-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
BUG: Switched shapes in ValueError msg in DataFrame construct (#20742) #24725
BUG: Switched shapes in ValueError msg in DataFrame construct (#20742) #24725
Conversation
doc/source/whatsnew/v0.24.0.rst
Outdated
@@ -1852,6 +1852,7 @@ 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`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be explicit as to how the dimensions are reported (i.e. their order) after the switch.
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
Codecov Report
@@ Coverage Diff @@
## master #24725 +/- ##
===========================================
- Coverage 92.39% 43.07% -49.33%
===========================================
Files 166 166
Lines 52358 52358
===========================================
- Hits 48374 22551 -25823
- Misses 3984 29807 +25823
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #24725 +/- ##
==========================================
- Coverage 92.38% 92.38% -0.01%
==========================================
Files 166 166
Lines 52382 52383 +1
==========================================
Hits 48395 48395
- Misses 3987 3988 +1
Continue to review full report at Codecov.
|
pandas/core/internals/managers.py
Outdated
@@ -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, [tot_items] + list(block_shape))) | |||
implied = tuple(map(int, [len(ax) for ax in axes])) | |||
passed = tuple(map(int, list(block_shape) + [tot_items])) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
CLN: removed issue number above new tests
doc/source/whatsnew/v0.24.0.rst
Outdated
@@ -1852,6 +1852,8 @@ Other | |||
^^^^^ | |||
|
|||
- Bug where C variables were declared with external linkage causing import errors if certain other C libraries were imported before Pandas. (:issue:`24113`) | |||
- Cleanup ``ValueError`` message thrown in creation of block manager: list block shape before number of total items in passed input shape and implied shape. (:issue:`20742`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to Reshaping section.
Reversed shapes in ValueError message when data shape does not match index shape in construction
pandas/core/internals/managers.py
Outdated
@@ -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, [tot_items] + list(block_shape))) | |||
implied = tuple(map(int, [len(ax) for ax in axes])) | |||
passed = tuple(map(int, list(block_shape) + [tot_items])) |
There was a problem hiding this comment.
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
pandas/tests/test_panel.py
Outdated
@@ -1143,20 +1143,20 @@ 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\), " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leave panel entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix a merge conflict.
doc/source/whatsnew/v0.24.0.rst
Outdated
@@ -1108,6 +1108,7 @@ update the ``ExtensionDtype._metadata`` tuple to match the signature of your | |||
- :meth:`~pandas.api.types.ExtensionArray.searchsorted` has been added (:issue:`24350`) | |||
- Support for reduction operations such as ``sum``, ``mean`` via opt-in base class method override (:issue:`22762`) | |||
- :func:`ExtensionArray.isna` is allowed to return an ``ExtensionArray`` (:issue:`22325`). | |||
- Cleanup ``ValueError`` message thrown in creation of block manager: list block shape before number of total items in passed input shape and implied shape. (:issue:`20742`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably shouldn't mention block manager in the release notes. Maybe just something about "fixed (or improved?) error message when ...)" where ... is a user action that would lead to the exception.
pandas/core/internals/managers.py
Outdated
@@ -1674,7 +1674,13 @@ 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, [tot_items] + list(block_shape))) | |||
implied = tuple(map(int, [len(ax) for ax in axes])) | |||
if len(passed) == 2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment on the reversing. (e.g. this is a user facing error message and this is a DataFrame construction)
you can do len(passed) <= 2
doc/source/whatsnew/v0.24.0.rst
Outdated
@@ -1816,6 +1816,7 @@ Reshaping | |||
- Bug in :func:`DataFrame.unstack` where a ``ValueError`` was raised when unstacking timezone aware values (:issue:`18338`) | |||
- Bug in :func:`DataFrame.stack` where timezone aware values were converted to timezone naive values (:issue:`19420`) | |||
- Bug in :func:`merge_asof` where a ``TypeError`` was raised when ``by_col`` were timezone aware values (:issue:`21184`) | |||
- Reversed shapes in ValueError message when data shape does not match index shape in construction. (:issue:`20742`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
say Incorrect shape in DataFrame construction error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whatsnew correction. ping on green.
doc/source/whatsnew/v0.24.0.rst
Outdated
@@ -1816,6 +1816,7 @@ Reshaping | |||
- Bug in :func:`DataFrame.unstack` where a ``ValueError`` was raised when unstacking timezone aware values (:issue:`18338`) | |||
- Bug in :func:`DataFrame.stack` where timezone aware values were converted to timezone naive values (:issue:`19420`) | |||
- Bug in :func:`merge_asof` where a ``TypeError`` was raised when ``by_col`` were timezone aware values (:issue:`21184`) | |||
- Bug incorrect shape in ``DataFrame`` construction ValueError message. (:issue:`20742`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug showing an incorrect shape when erroring during DataFrame
construction
Thanks @meiermark. |
…-dev#20742) (pandas-dev#24725) * BUG: Switched shapes in ValueError msg in DataFrame construct (pandas-dev#20742) * 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 * BUG: printed a list instead of a tuple in the ValueError msg * CLN: removed unnecessary list comprehension * DOC: Improved whatsnew message * CLN: readded deleted tests CLN: removed issue number above new tests * Bug: No changes for panel * DOC: improved whatsnew message for reversed shapes * DOC: improved comments and whatsnew message for df construction error * DOC: improved whatsnew message
…-dev#20742) (pandas-dev#24725) * BUG: Switched shapes in ValueError msg in DataFrame construct (pandas-dev#20742) * 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 * BUG: printed a list instead of a tuple in the ValueError msg * CLN: removed unnecessary list comprehension * DOC: Improved whatsnew message * CLN: readded deleted tests CLN: removed issue number above new tests * Bug: No changes for panel * DOC: improved whatsnew message for reversed shapes * DOC: improved comments and whatsnew message for df construction error * DOC: improved whatsnew message
git diff upstream/master -u -- "*.py" | flake8 --diff