-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: misleading error creating df from 2d array #42646
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
Conversation
debnathshoham
commented
Jul 21, 2021
•
edited
Loading
edited
- closes BUG: Constructing a df using 2D numpy arrays raises misleading error #42463
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
@@ -615,6 +615,8 @@ def _extract_index(data) -> Index: | |||
elif is_list_like(val) and getattr(val, "ndim", 1) == 1: | |||
have_raw_arrays = True | |||
raw_lengths.append(len(val)) | |||
elif isinstance(val, np.ndarray) and getattr(val, "ndim", 1) > 1: |
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.
after the isinstance check the getattr can check can just be val.ndim > 1
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.
amended
|
@@ -615,6 +615,8 @@ def _extract_index(data) -> Index: | |||
elif is_list_like(val) and getattr(val, "ndim", 1) == 1: | |||
have_raw_arrays = True | |||
raw_lengths.append(len(val)) | |||
elif isinstance(val, np.ndarray) and val.ndim > 1: | |||
raise ValueError("Data must be 1-dimensional") |
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.
maybe something like "Per-column arrays must each be 1-dimensional"?
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.
amended
], | ||
) | ||
def test_error_from_2darray(self, col_a, col_b): | ||
msg = "Data must be 1-dimensional" |
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 need to update the message 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.
My bad. Updated the msg in test.
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.
LGTM
@debnathshoham lgtm. can you add a whatsnew note (bug fixes for reshaping for 1.4 is good), a short note about the revised error that a user would see. ping on green. |
@jreback Green-ish (unrelated failures) |
thanks @debnathshoham |
BUG: misleading error creating df from 2d array (pandas-dev#42646)