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

DataFrame creation incorrect error message #20742

Closed
sergei-sh opened this issue Apr 19, 2018 · 1 comment · Fixed by #24725
Closed

DataFrame creation incorrect error message #20742

sergei-sh opened this issue Apr 19, 2018 · 1 comment · Fixed by #24725
Labels
Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@sergei-sh
Copy link

sergei-sh commented Apr 19, 2018

The problem was already mentioned as part of other issues, but still persists in 0.22

#8020
blaze/blaze#466

Reported both expected shape and input data shape are both transposed which causes a lot of confusion. In my opinion, the reference value should be DataFrame.shape.

my_arr = np.array([1, 2, 3])
print("my_arr.shape: {}".format(my_arr.shape))
df = pd.DataFrame(index=[0], columns=range(0, 4), data=my_arr)
my_arr.shape: (3,)
Traceback (most recent call last):
...
ValueError: Shape of passed values is (1, 3), indices imply (4, 1)

Below are shapes which are expected to be reported:

my_arr = np.array([[0, 1, 2, 3]])
print("my_arr.shape: {}".format(my_arr.shape))
df = pd.DataFrame(index=[0], columns=range(0, 4), data=my_arr)
print(df.shape)`
my_arr.shape: (1, 4)
(1, 4)

I'm not sure, whether this is another issue, but in the first example, the error cause is 1-dimensional data while constructor expects 2-dimensional data. The user gets no hint about this from the error message.

@jreback
Copy link
Contributor

jreback commented Apr 20, 2018

the first example is wrong. The block manager reports this, but doesn't flip the dim (like we do for everything else), so would welcome a PR to correct that.

I don't see a problem with the 2nd. You gave a 1, 4 array. That's the same as the dim of the frame, so it constructs.

@jreback jreback added Error Reporting Incorrect or improved errors from pandas Difficulty Intermediate labels Apr 20, 2018
@jreback jreback added this to the Next Major Release milestone Apr 20, 2018
@jreback jreback modified the milestones: Contributions Welcome, 0.24.0 Jan 17, 2019
TomAugspurger pushed a commit that referenced this issue Jan 18, 2019
#24725)

* BUG: Switched shapes in ValueError msg in DataFrame construct (#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 issue 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 issue 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
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
2 participants