-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Description
-
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.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Given a csv file test.csv
(sorry, didn't manage to reproduce without reading a csv
) with the following content:
x,y
00000114136524405793555657657729584885,
df = pd.read_csv('test.csv', dtype={'x': 'string', 'y': 'string'})
df['y'].fillna({}, inplace=True)
Problem description
Above code fails with an error ValueError: Must provide strings.
. Full traceback below in the details.
Traceback (most recent call last):
File "test.py", line 3, in <module>
df['y'].fillna({}, inplace=True)
File "/home/user/.local/lib/python3.8/site-packages/pandas/core/series.py", line 4529, in fillna
return super().fillna(
File "/home/user/.local/lib/python3.8/site-packages/pandas/core/generic.py", line 6057, in fillna
new_data = self._mgr.fillna(
File "/home/user/.local/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 585, in fillna
return self.apply(
File "/home/user/.local/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 406, in apply
applied = getattr(b, f)(**kwargs)
File "/home/user/.local/lib/python3.8/site-packages/pandas/core/internals/blocks.py", line 1779, in fillna
values = values.fillna(value=value, limit=limit)
File "/home/user/.local/lib/python3.8/site-packages/pandas/core/arrays/string_.py", line 262, in fillna
return super().fillna(value, method, limit)
File "/home/user/.local/lib/python3.8/site-packages/pandas/core/arrays/numpy_.py", line 307, in fillna
new_values[mask] = value
File "/home/user/.local/lib/python3.8/site-packages/pandas/core/arrays/string_.py", line 256, in __setitem__
raise ValueError("Must provide strings.")
ValueError: Must provide strings.
On the other hand, when the dtype
object is {'x': str, 'y': str}
, the error is not raised - from the docs I understood both versions should be equivalent?
Expected Output
Both versions have the same behavior.
Output of pd.show_versions()
INSTALLED VERSIONS
commit : c7f7443
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.11.0-25-generic
Version : #27~20.04.1-Ubuntu SMP Tue Jul 13 17:41:23 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.3.1
numpy : 1.21.1
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.2
setuptools : 44.0.0
Cython : None
pytest : 6.2.4
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.07.0
fastparquet : None
gcsfs : 2021.07.0
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
None