-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DataFrame pivot_table nunique aggfunc test GH#29080 #52082
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
liang3zy22
commented
Mar 20, 2023
- closes pandas pivot_table aggfunc/values parameters behaving oddly #29080 (Replace xxxx with the GitHub issue number)
- Tests added and passed if fixing a bug or adding a new feature
- All code checks passed.
pandas/tests/reshape/test_pivot.py
Outdated
"d": np.random.randint(0, 10, size=(10,)), | ||
} | ||
) | ||
expected = test.pivot_table( |
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.
Can you construct this without pivot_table
i.e. expected = pd.DataFrame(..., columns=...)
bbcc62f
to
0fbbbbd
Compare
pandas/tests/reshape/test_pivot.py
Outdated
"d": np.random.randint(0, 10, size=(10,)), | ||
} | ||
) | ||
a = test["a"] |
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.
Actually to avoid all this, just make test
non-random values e.g.
test = DataFrame({"a": range(10), ...)
pandas/tests/reshape/test_pivot.py
Outdated
nparr = np.full((10, 10), np.NaN) | ||
expected = DataFrame(nparr, index=Index(range(10), name="a"), columns=columnval) | ||
for i in range(10): | ||
expected.loc[i, ("nunique", "c", i)] = float(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.
Can you build these values in nparr
?
6a44fa8
to
45ac820
Compare
pandas/tests/reshape/test_pivot.py
Outdated
) | ||
|
||
nparr = np.full((10, 10), np.NaN) | ||
for i in range(10): |
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.
Nit: I think you can use https://numpy.org/doc/stable/reference/generated/numpy.fill_diagonal.html
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.
Thanks, @mroeschke . I know a new numpy function, and a new English word, :-).
Signed-off-by: Liang Yan <[email protected]>
Thanks @liang3zy22 |