-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: unstack on 'int' dtype prevent fillna to work #37115
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
Labels
Regression
Functionality that used to work in a prior pandas version
Reshaping
Concat, Merge/Join, Stack/Unstack, Explode
Milestone
Comments
This seems like a duplicate of #36495, also caused by #34389. @simonjayhawkins has a PR #36668 that fixes this which I think could be reopened and merged now for 1.1.4. |
simonjayhawkins
added a commit
to simonjayhawkins/pandas
that referenced
this issue
Nov 25, 2020
@simonjayhawkins I think I did do a bisect if I'm remembering correctly, but I would trust your analysis over mine |
Merged
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Regression
Functionality that used to work in a prior pandas version
Reshaping
Concat, Merge/Join, Stack/Unstack, Explode
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Problem description
df.unstack
is creating columns from a int column, but adds some NaNs as expected.Trying to get rid of the NaN is not possible as
fillna
will silently fail and leave the column values as is.Potential Source of the Problem
It looks like with this configuration, the Block for this
df1[('is_', 'ca')]
Series in the BlockManager is actuallyIntBlock
, but holds a float dtypenp.ndarray
(!?).From what I understand, as soon as the BlockManager operates a block consolidation (with the _consolidate function), the Block is converted to a
FloatBlock
and everything is OK.e.g. a call to
cat2._is_mixed_type
will trigger a_consolidate
and thus clear the issue.Potential Solution Suggestion
Should the unstack function fires a consolidation of blocks, especially for column types that do not accept NaN values (like 'int' and 'bool' from numpy)?
Some potential workarounds identified so far
fillna
before adding a column, but not aftercat2._is_mixed_type
df1.infos()
: this was the most surprising one (it is because if triggersdf.count()
and thus consolidation)df1['is_'] = 1.0
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : db08276
python : 3.8.3.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : fr_FR.UTF-8
LOCALE : fr_FR.cp1252
pandas : 1.1.3
numpy : 1.19.0
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : 0.4.1
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.2.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.4
pandas_gbq : None
pyarrow : 1.0.1
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: