Pandas version checks
- [X] I have checked that the issue still exists on the latest versions of the docs on
main
here
Location of the documentation
https://pandas.pydata.org/docs/user_guide/basics.html#dtypes
Documentation problem
Upcasting is discussed, but not downcasting.
Suggested fix for documentation
It is fine not to implement a warning when downcasting will cause data loss, but the fact that this is not implemented means the user should be advised that they assume the risk.
In short, the behavior when downcasting a column should be discussed antonymously to the upcasting section in the documentation.
Resulting from https://github.com/pandas-dev/pandas/issues/50214.
Comment From: MarcoGorelli
hi - what do you mean by "downcasting" a column?
could you please provide a simple example, like: - here's what I ran - here's what happened - here's what I expected
Comment From: mcp292
Please see the issue linked in the original post and let me know if that's what you're looking for.
Comment From: MarcoGorelli
Which downcasting are you referring to?
From https://github.com/pandas-dev/pandas/issues/50125#issuecomment-1342886489 , as far as I can tell, it's just what numpy does
In [28]: arr[2]
Out[28]: array([11.11], dtype=float16)
In [29]: arr[2].item()
Out[29]: 11.109375
And regarding the inequality, this reproduces in pure numpy, so isn't an issue in pandas
In [30]: arr = np.array(data, dtype=np.float16)
In [31]: arr[arr <= 99.99]
Out[31]:
array([ 0. , 10.25 , 11.11 , 5.555, 50.56 , 70.75 , 99. ,
100. , 100. , 100. ], dtype=float16)
In [32]: arr
Out[32]:
array([ 0. , 10.25 , 11.11 , 5.555, 50.56 , 70.75 , 99. ,
100. , 100. , 100. ], dtype=float16)
Comment From: MarcoGorelli
And regarding the inequality, this reproduces in pure numpy, so isn't an issue in pandas
As per the above, pandas did not do any downcasting here
Closing then, but thanks for the report