-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Description
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
import pandas as pd
import pyarrow as pa
df = pd.DataFrame({"x": [1, 2, 3], "y": ["foo", "bar", "baz"]})
with pd.option_context("mode.dtype_backend", "pyarrow"):
df = df.convert_dtypes()
assert df.y.dtype == pd.ArrowDtype(pa.string()) # this passes
assert df.y.dtype == pd.StringDtype("pyarrow") # this raises
Issue Description
The DataFrame.convert_dtypes()
docstring describes the convert_string=
keyword as
convert_string: bool, default True
Whether object dtypes should be converted to `StringDtype()`.
However, when using the pyarrow
dtype backend, it looks like convert_dtypes()
is actually converting to pd.ArrowDtype(pa.string())
instead of pd.StringDtype("pyarrow")
. This seems to differ from the docstring description. It's also my current understanding (which could totally be wrong), that we should generally prefer pd.StringDtype("pyarrow")
today as it's more feature complete (xref #50074 (comment))
cc @mroeschke @phofl for visibility
Expected Behavior
DataFrame.convert_dtypes()
should convert to pd.StringDtype("pyarrow")
instead of pd.ArrowDtype(pa.string())
when using the pyarrow
dtype backend
Installed Versions
INSTALLED VERSIONS
------------------
commit : 7f2aa8f46a4a36937b1be8ec2498c4ff2dd4cf34
python : 3.10.4.final.0
python-bits : 64
OS : Darwin
OS-release : 22.2.0
Version : Darwin Kernel Version 22.2.0: Fri Nov 11 02:08:47 PST 2022; root:xnu-8792.61.2~4/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.0.dev0+1309.g7f2aa8f46a
numpy : 1.24.1
pytz : 2022.1
dateutil : 2.8.2
setuptools : 59.8.0
pip : 22.0.4
Cython : None
pytest : 7.1.3
hypothesis : None
sphinx : 4.5.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.2.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli :
fastparquet : 2022.12.1.dev6
fsspec : 2023.1.0+5.g012816b
gcsfs : None
matplotlib : 3.5.1
numba : None
numexpr : 2.8.0
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 11.0.0.dev316
pyreadstat : None
pyxlsb : None
s3fs : 2022.10.0
scipy : 1.9.0
snappy :
sqlalchemy : 1.4.35
tables : 3.7.0
tabulate : None
xarray : 2022.3.0
xlrd : None
zstandard : None
tzdata : None
qtpy : None
pyqt5 : None