Skip to content

BUG: crosstab fails with lists/tuples #44076

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

Closed
3 tasks done
rhshadrach opened this issue Oct 18, 2021 · 1 comment · Fixed by #44088
Closed
3 tasks done

BUG: crosstab fails with lists/tuples #44076

rhshadrach opened this issue Oct 18, 2021 · 1 comment · Fixed by #44088
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug
Milestone

Comments

@rhshadrach
Copy link
Member

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

df = pd.DataFrame({'a': [1, 1, 2], 'b': [3, 4, 5]})
print(pd.crosstab(df["a"].to_list(), df["b"].to_list()))

Issue Description

The example raises a ValueError, whereas using to_numpy instead of to_list successfully produces the correct output. This is due to the use of maybe_make_list treating lists/tuples differently than other list-likes, and is related to #44056.

Expected Behavior

col_0  3  4  5
row_0         
1      1  1  0
2      0  0  1

Installed Versions

Replace this line with the output of pd.show_versions()

@rhshadrach rhshadrach added Bug Needs Triage Issue that has not been reviewed by a pandas team member Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 18, 2021
@rhshadrach rhshadrach added this to the Contributions Welcome milestone Oct 18, 2021
@rhshadrach
Copy link
Member Author

Instead of using maybe_make_list here, I think the correct behavior is to use is_nested_list_like and pack into a list if this returns False.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants