-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: incorrect type when indexing sparse dataframe with iterable #34908
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
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.
looks fine, can you create a test_sparse.py (in this directory) and move other sparse indexing tests as well (e.g. the one right above, maybe more)
@jreback Thanks for the review! I'll try fix the bug in the next few days. |
For the type inference logic, I wasn't sure which to use, |
Hi @jreback, just bringing this to your attention. I wasn't sure if you noticed it's ready for review (I used the "request review" option in the side panel). Apologies if this is already on your list. |
@suvayu can you add a whatsnew to 1.1.0.rst in the bug fixes section? |
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.
The changes look good, just need a release note. Make sure to include references to both issues fixed.
Hi @TomAugspurger, I added the the whatsnew entry. There was a merge conflict with master (another entry in the same section), so I had to force push after resolving it. |
Thanks @suvayu! |
closes #34526
closes #34540
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
The problem arose when indexing with an iterable. If the result consisted of columns which originally only had sparse values, the
dtype
was solely inferred from thefill_value
, which defaults to0
. Hence, the resulting columns have the dtypeSparse[int64, 0]
. This commit changes the type inference logic to use the numpy type promotion rules between the underlying subtype of theSparseArray.dtype
and the type of the fill value.