Skip to content

DataFrames don't handle input arrays of dtype str/bytes consistently. #24085

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
coady opened this issue Dec 4, 2018 · 2 comments
Closed

DataFrames don't handle input arrays of dtype str/bytes consistently. #24085

coady opened this issue Dec 4, 2018 · 2 comments
Labels
Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request Strings String extension data type and string data

Comments

@coady
Copy link

coady commented Dec 4, 2018

Code Sample, a copy-pastable example if possible

In [3]: arr = np.array(['ab', 'bc', 'cd'], bytes)                                                                                                                                                                                               

In [4]: arr.dtype                                                                                                                                                                                                                               
Out[4]: dtype('S2')

In [5]: pd.DataFrame(arr)[0].dtype                                                                                                                                                                                                              
Out[5]: dtype('S2')

In [6]: pd.DataFrame(arr, columns=['x'])['x'].dtype                                                                                                                                                                                             
Out[6]: dtype('S2')

In [7]: pd.DataFrame({'x': arr})['x'].dtype                                                                                                                                                                                                     
Out[7]: dtype('O')

Problem description

DataFrames appear to automatically convert numpy arrays of dtype U to O. But whether they allow columns of dtype S is inconsistent.

Expected Output

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 3.7.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.9.125-linuxkit
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.4
pytest: None
pip: 18.1
setuptools: 40.6.2
Cython: None
numpy: 1.15.4
scipy: None
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: None
patsy: None
dateutil: 2.7.5
pytz: 2018.7
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@chris-b1
Copy link
Contributor

chris-b1 commented Dec 4, 2018

Rolling this under #5261 - in general we don't support numpy string dtypes, but in some construction paths where we try to be zero-copy, they can make it into a DataFrame.

@chris-b1 chris-b1 closed this as completed Dec 4, 2018
@chris-b1 chris-b1 added Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request Strings String extension data type and string data labels Dec 4, 2018
@chris-b1 chris-b1 added this to the No action milestone Dec 4, 2018
@chris-b1
Copy link
Contributor

chris-b1 commented Dec 4, 2018

(feel free to comment there if you have more specific suggestions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request Strings String extension data type and string data
Projects
None yet
Development

No branches or pull requests

2 participants