Skip to content
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

REGR: DataFrame.to_numpy(dtype=str) raises RuntimeError in pandas 1.1.0 #35455

Closed
1 task
aciba90 opened this issue Jul 29, 2020 · 3 comments
Closed
1 task
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@aciba90
Copy link

aciba90 commented Jul 29, 2020

  • [x ] I have checked that this issue has not already been reported.

  • [x ] 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

import pandas as pd

df = pd.DataFrame(data=[[pd.Timestamp('2011-07-03 00:00:00'), 6628480.0]])
print(df.to_numpy(dtype=str))

Problem description

I try to convert the DataFrame to a Numpy array with dtype equal to str and I got the next error.

Traceback (most recent call last):
  File "/main.py", line 4, in <module>
    df.to_numpy(dtype=str)
  File "/venv/lib/python3.7/site-packages/pandas/core/frame.py", line 1371, in to_numpy
    transpose=self._AXIS_REVERSED, dtype=dtype, copy=copy, na_value=na_value
  File "/venv/lib/python3.7/site-packages/pandas/core/internals/managers.py", line 826, in as_array
    arr = self._interleave(dtype=dtype, na_value=na_value)
  File "/venv/lib/python3.7/site-packages/pandas/core/internals/managers.py", line 864, in _interleave
    result[rl.indexer] = arr
RuntimeError: The string provided for NumPy ISO datetime formatting was too short, with length 1

Expected Output

[['2011-07-03 00:00:00' '6628480.0']]

Output of pd.show_versions()

INSTALLED VERSIONS

commit : d9fff27
python : 3.7.6.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.104-microsoft-standard
Version : #1 SMP Wed Feb 19 06:37:35 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.0
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 19.2.3
setuptools : 41.2.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
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@aciba90 aciba90 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 29, 2020
@simonjayhawkins
Copy link
Member

Thanks @aciba90 for the report. This is a regression from 1.0.5

>>> pd.__version__
'1.0.5'
>>>
>>> import pandas as pd
>>>
>>> df = pd.DataFrame(data=[[pd.Timestamp('2011-07-03 00:00:00'), 6628480.0]])
>>> print(df.to_numpy(dtype=str))
[['2011-07-03 00:00:00' '6628480.0']]

@simonjayhawkins simonjayhawkins added this to the 1.1.1 milestone Jul 29, 2020
@simonjayhawkins simonjayhawkins added Regression Functionality that used to work in a prior pandas version and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 29, 2020
@simonjayhawkins simonjayhawkins changed the title BUG: REGR: DataFrame.to_numpy(dtype=str) raises RuntimeError in pandas 1.1.0 Jul 29, 2020
@simonjayhawkins simonjayhawkins added the Dtype Conversions Unexpected or buggy dtype conversions label Jul 29, 2020
@simonjayhawkins
Copy link
Member

This is a regression from 1.0.5

it appears #33857 is the cause of this regression

4bd6905 is the first bad commit
commit 4bd6905
Author: Daniel Saxton 2658661+dsaxton@users.noreply.github.com
Date: Wed May 13 10:51:28 2020 -0500

ENH: Add na_value argument to DataFrame.to_numpy (#33857)

cc @dsaxton

@simonjayhawkins
Copy link
Member

fixed in #35473

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

No branches or pull requests

2 participants