Skip to content

str.extract(expand=False) on a string typed series returns an object typed dataframe #30969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tsvikas opened this issue Jan 13, 2020 · 1 comment · Fixed by #31018
Closed
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Strings String extension data type and string data
Milestone

Comments

@tsvikas
Copy link
Contributor

tsvikas commented Jan 13, 2020

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.Series(['a1', 'b2', 'c3'], dtype="string").str.extract(r'([ab])(\d)', expand=False)
df.dtypes

returns

0    object
1    object
dtype: object

Problem description

the str accessor, when working on string-typed series, should return a string-typed dataframe. It seems that extract(expand=False) returns an object-typed dataframe

see @TomAugspurger in #30966 (comment)

Expected Output

0    string
1    string
dtype: object

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit           : None
python           : 3.8.0.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.0.0-38-generic
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_IL
LOCALE           : en_IL.UTF-8

pandas           : 1.0.0rc0
numpy            : 1.18.1
pytz             : 2019.3
dateutil         : 2.8.1
pip              : 18.1
setuptools       : 40.8.0
Cython           : None
pytest           : None
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
fastparquet      : None
gcsfs            : None
lxml.etree       : None
matplotlib       : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pytables         : None
pytest           : None
s3fs             : None
scipy            : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
xlsxwriter       : None
numba            : None
@TomAugspurger
Copy link
Contributor

Thanks for the report. I could have sworn that .str.extract(r'(\w)(\w)', expand=False) would return a Series with object dtype where each value was a list, but apparently not.

@TomAugspurger TomAugspurger added this to the 1.0.0 milestone Jan 14, 2020
TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Jan 14, 2020
specifically with multiple capture groups and expand=False

Closes pandas-dev#30969
@simonjayhawkins simonjayhawkins added ExtensionArray Extending pandas with custom dtypes or arrays. Strings String extension data type and string data labels Jan 14, 2020
jreback pushed a commit that referenced this issue Jan 15, 2020
specifically with multiple capture groups and expand=False

Closes #30969
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Strings String extension data type and string data
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants