BUG: reindex (and atleast several other methods) do not respect fill_value=None #61291
Open
3 tasks done
Labels
Bug
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Needs Discussion
Requires discussion from core team before further action
PDEP missing values
Issues that would be addressed by the Ice Cream Agreement from the Aug 2023 sprint
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
User-facing bug placing
NaN
into df instead ofNone
and the underlyingExtensionArray.take
method (with a more contrived example to ensure the types are valid) which is a significant cause of the behaviour.This is less of a bug and more a discussion on default behaviour in pandas. It is impossible to "fill" a value of
None
in an already existing dataframe/array as far as I can see in pandas, althoughNone
is often the default value used to fill during dataframe creation1. The reason for this behaviour seems to run very deeply and shows active choices by implementors to have this behaviour, see: example witharr.take
(with an implementors note which I did not completely understand), alsoBaseArrayManager._make_na_array
and the optimised code forNDFrame._reindex_multi
.This problem seems to have been almost seen but brushed past in #20640 where
fill_value
is recognised to not always be honored due to compatibility with the underlying arrays. However, as shown there are also cases whereNone
is a valid entry in the array which are blanket ignored (even though I'd argue that the array type should possibly be adjusted to fit the fill value). Some complexity also comes from there not being aNone
in C however I strongly dislike this argument as there seems to be standins/a way to work with them throughout the rest of the library. Note I have not dug deeply into the C/Cython code myself.In closing, I think
None
should be able to be used as afill_value
when reindexing but it is currently intentionally and unecessarily mangled intonp.nan
at many levels. Discussion is strongly encouraged as any actual changes WOULD subtly change existing behaviour and at some point I just want to understand why these choices were made.Expected Behavior
0
0 1
1 None
<NumpyExtensionArray>
[None, (1+0j)]
Length: 2, dtype: object
<NumpyExtensionArray>
[None, None]
Length: 2, dtype: object
Installed Versions
INSTALLED VERSIONS
commit : 0691c5c
python : 3.12.9
python-bits : 64
OS : Windows
OS-release : 11
Version : 10.0.26100
machine : AMD64
processor : AMD64 Family 25 Model 97 Stepping 2, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_New Zealand.1252
pandas : 2.2.3
numpy : 2.1.0
pytz : 2024.1
dateutil : 2.9.0.post0
pip : 25.0.1
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.3
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : 3.9.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.14.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
Footnotes
Which is where I ran into this problem, creating a dataframe of strings with holes, then trying to consistently reshape it. Of course there are plenty of ways for me to circumvent this problem but I want to demonstrate this is not arbitrary/irrelevant. ↩
The text was updated successfully, but these errors were encountered: