-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: "ValueError: Must provide strings." when using "string" as dtype #42918
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
They are not. str is object dtype and string is our new StringDtype. Sorry for the confusion. I think the error you are getting is because StringArrays cannot be created from a numpy array with nans. Haven't looked in depth closely though. |
Oh, sorry then. |
I'll take a closer look soon. Will keep you updated. |
I get the same error message when I use |
@HansBambel This has been fixed in the meantime (testing with pandas 2.2.3): In [18]: ser = pd.Series(["a", "b", "c"], dtype="string")
In [19]: ser.replace(r"^a", np.nan, regex=True)
Out[19]:
0 <NA>
1 b
2 c
dtype: string (the NaN gets converted to the missing value sentinel for the
@omgMath It seems that this no longer raises as well. Not sure what changed, but it seems we no longer treat In [33]: ser = pd.Series(["a", None], dtype="string")
In [34]: ser.fillna({})
Out[34]:
0 a
1 <NA>
dtype: string
In [35]: ser = pd.Series(["a", None], dtype="object")
In [36]: ser.fillna({})
Out[36]:
0 a
1 None
dtype: object |
Going to close this issue, because I think replacing with |
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 acsv
) with the following content:Problem description
Above code fails with an error
ValueError: Must provide strings.
. Full traceback below in the details.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
The text was updated successfully, but these errors were encountered: