Skip to content

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

Merged
merged 6 commits into from
Jul 28, 2021

Conversation

debnathshoham
Copy link
Member

@debnathshoham debnathshoham commented Jul 21, 2021

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

amended

@debnathshoham
Copy link
Member Author

FAILED pandas/core/groupby/groupby.py::pandas.core.groupby.groupby.GroupBy.apply
Failure unrelated to my change

@@ -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")
Copy link
Member

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"?

Copy link
Member Author

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

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?

Copy link
Member Author

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.

Copy link
Member

@jbrockmendel jbrockmendel left a comment

Choose a reason for hiding this comment

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

LGTM

@jreback jreback added this to the 1.4 milestone Jul 28, 2021
@jreback jreback added Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Jul 28, 2021
@jreback
Copy link
Contributor

jreback commented Jul 28, 2021

@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.

@debnathshoham
Copy link
Member Author

@jreback Green-ish (unrelated failures)

@jreback jreback merged commit 8924277 into pandas-dev:master Jul 28, 2021
@jreback
Copy link
Contributor

jreback commented Jul 28, 2021

thanks @debnathshoham

@debnathshoham debnathshoham deleted the 42463 branch July 28, 2021 13:04
sthagen added a commit to sthagen/pandas-dev-pandas that referenced this pull request Jul 28, 2021
BUG: misleading error creating df from 2d array (pandas-dev#42646)
CGe0516 pushed a commit to CGe0516/pandas that referenced this pull request Jul 29, 2021
feefladder pushed a commit to feefladder/pandas that referenced this pull request Sep 7, 2021
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 Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Constructing a df using 2D numpy arrays raises misleading error
3 participants