-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: apply on Series of dtype category produces dtype category when float was expected #39580
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
Comments
So cut returns a Categorical Series, which while the individual items might be float64 I think it is expected behavior that you can't add a value. I.e., what if the categories were 'cat' and 'dog', you should not be able to add 1 to 'dog'. I think you could either set labels = False when calling cut or cast the result s to type float if you want. The FutureWarning though seems like its from:
It seems like this might still be fine even after ravel returns a view on self, so could maybe be muted? But I'm not sure |
It seems wildly inconsistent to me that Series of dtype category are the ONLY Series where |
Are you sure no other dtype behaves likes this? Tracing the function identifies a check performed on the series:
It seems that extension arrays are classified as:
In the case that it is an extension array the function is applied and no conversion takes place. In the case that it is not one of the above, there is some dtype conversion taking place. [see core/apply.py lines 855-860] |
Thank you, that's good to know. If "never convert" is really intended for these dtypes, maybe it should be mentioned in the For example: convert_dtype : bool, default True Try to find better dtype for elementwise function results. If False, leave as dtype=object. For the dtypes X, Y and Z the original dtype is kept. |
Yes indeed, a good opportunity for contributions perhaps :) |
take |
take |
I'm trying to get the left edge from a Series of Intervals. Unexpectedly, the result is a Series of dtype category. I'm also getting a FutureWarning.
Interestingly, the individual cells have objects with the correct dtype:
However, operations you would expect from a Series of floats to work do not work:
pd.show_versions()
INSTALLED VERSIONS------------------
commit : 9d598a5
python : 3.8.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : AMD64 Family 23 Model 96 Stepping 1, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
pandas : 1.2.1
numpy : 1.20.0
pytz : 2021.1
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.1.2
Cython : None
pytest : 6.2.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.20.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.0
sqlalchemy : 1.3.23
tables : None
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: