Skip to content
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

Conversation

meiermark
Copy link
Contributor

@meiermark meiermark commented Jan 11, 2019

@gfyoung gfyoung added Error Reporting Incorrect or improved errors from pandas DataFrame DataFrame data structure labels Jan 11, 2019
@@ -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`)
Copy link
Member

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
Copy link

codecov bot commented Jan 12, 2019

Codecov Report

Merging #24725 into master will decrease coverage by 49.32%.
The diff coverage is 0%.

Impacted file tree graph

@@             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
Flag Coverage Δ
#multiple ?
#single 43.07% <0%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/internals/managers.py 66.49% <0%> (-29.56%) ⬇️
pandas/io/formats/latex.py 0% <0%> (-100%) ⬇️
pandas/core/categorical.py 0% <0%> (-100%) ⬇️
pandas/io/sas/sas_constants.py 0% <0%> (-100%) ⬇️
pandas/tseries/plotting.py 0% <0%> (-100%) ⬇️
pandas/tseries/converter.py 0% <0%> (-100%) ⬇️
pandas/io/formats/html.py 0% <0%> (-99.35%) ⬇️
pandas/core/groupby/categorical.py 0% <0%> (-95.46%) ⬇️
pandas/io/sas/sas7bdat.py 0% <0%> (-91.17%) ⬇️
pandas/io/sas/sas_xport.py 0% <0%> (-90.15%) ⬇️
... and 124 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c1a81fe...46d4d55. Read the comment docs.

@codecov
Copy link

codecov bot commented Jan 12, 2019

Codecov Report

Merging #24725 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 90.81% <100%> (ø) ⬆️
#single 42.91% <0%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/internals/managers.py 96.06% <100%> (+0.01%) ⬆️
pandas/util/testing.py 88.04% <0%> (-0.1%) ⬇️
pandas/core/indexes/timedeltas.py 90.22% <0%> (-0.03%) ⬇️
pandas/core/computation/pytables.py 92.35% <0%> (-0.03%) ⬇️
pandas/core/dtypes/cast.py 88.7% <0%> (-0.02%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 17a6bc5...cb282dc. Read the comment docs.

doc/source/whatsnew/v0.24.0.rst Outdated Show resolved Hide resolved
@@ -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]))
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

pandas/tests/frame/test_constructors.py Outdated Show resolved Hide resolved
pandas/tests/test_panel.py Outdated Show resolved Hide resolved
@@ -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`)
Copy link
Contributor

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

@@ -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]))
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

@@ -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\), "
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.

Copy link
Contributor

@TomAugspurger TomAugspurger left a 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.

@@ -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`)
Copy link
Contributor

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.

@@ -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:
Copy link
Contributor

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

@@ -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`)
Copy link
Contributor

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.

@jreback jreback added this to the 0.24.0 milestone Jan 17, 2019
Copy link
Contributor

@jreback jreback left a 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.

@@ -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`)
Copy link
Contributor

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

@TomAugspurger TomAugspurger merged commit 08f92c4 into pandas-dev:master Jan 18, 2019
@TomAugspurger
Copy link
Contributor

Thanks @meiermark.

Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
…-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
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
…-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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DataFrame DataFrame data structure Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFrame creation incorrect error message
4 participants