Skip to content

TypeError bug when using pandas.to_timedelta (astype() unexpected argument 'copy') #14175

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
kappapee opened this issue Sep 7, 2016 · 5 comments
Labels
Bug Timedelta Timedelta data type

Comments

@kappapee
Copy link

kappapee commented Sep 7, 2016

Code Sample

Running the following code:

import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randn(6,4),columns=list('ABCD'))
pd.to_timedelta(df.index,unit='s')

returns a TypeError:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-cf2e27d56944> in <module>()
      1 df = pd.DataFrame(np.random.randn(6,4),columns=list('ABCD'))
----> 2 pd.to_timedelta(df.index,unit='s')

~/anaconda/lib/python3.5/site-packages/pandas/util/decorators.py in wrapper(*args, **kwargs)
     89                 else:
     90                     kwargs[new_arg_name] = new_arg_value
---> 91             return func(*args, **kwargs)
     92         return wrapper
     93     return _deprecate_kwarg

~/anaconda/lib/python3.5/site-packages/pandas/tseries/timedeltas.py in to_timedelta(arg, unit, box, errors, coerce)
     91         return Series(values, index=arg.index, name=arg.name, dtype='m8[ns]')
     92     elif isinstance(arg, ABCIndexClass):
---> 93         return _convert_listlike(arg, box=box, unit=unit, name=arg.name)
     94     elif is_list_like(arg) and getattr(arg, 'ndim', 1) == 1:
     95         return _convert_listlike(arg, box=box, unit=unit)

~/anaconda/lib/python3.5/site-packages/pandas/tseries/timedeltas.py in _convert_listlike(arg, box, unit, name)
     73         elif is_integer_dtype(arg):
     74             value = arg.astype('timedelta64[{0}]'.format(
---> 75                 unit)).astype('timedelta64[ns]', copy=False)
     76         else:
     77             value = tslib.array_to_timedelta64(

TypeError: astype() got an unexpected keyword argument 'copy'

Expected Output

Should instead return the following:

TimedeltaIndex(['00:00:00', '00:00:01', '00:00:02', '00:00:03', '00:00:04',
                '00:00:05'],
               dtype='timedelta64[ns]', freq=None)

which is what I get if I manually (for testing) remove the copy argument in the timedeltas.py

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Darwin
OS-release: 14.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 26.1.1
Cython: 0.24.1
numpy: 1.11.1
scipy: 0.18.0
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.4.6
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: 1.1.0
tables: 3.2.3.1
numexpr: 2.6.1
matplotlib: 1.5.2
openpyxl: 2.3.5
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.3
lxml: 3.6.4
bs4: 4.5.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.15
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.42.0
pandas_datareader: None
@jreback
Copy link
Contributor

jreback commented Sep 7, 2016

This is fixed in master/0.19.0 (rc1 coming this week).

In [1]: pd.__version__
Out[1]: '0.18.1+438.g8023029'

In [2]: df = pd.DataFrame(np.random.randn(6,4),columns=list('ABCD'))
   ...: pd.to_timedelta(df.index,unit='s')
   ...: 
Out[2]: TimedeltaIndex(['00:00:00', '00:00:01', '00:00:02', '00:00:03', '00:00:04', '00:00:05'], dtype='timedelta64[ns]', freq=None)

@jreback jreback closed this as completed Sep 7, 2016
@jreback
Copy link
Contributor

jreback commented Sep 7, 2016

If you wan to look thru tests, we'd accept a PR for one (though I suspect this IS now tested already).

@jreback jreback added Bug Timedelta Timedelta data type labels Sep 7, 2016
@jreback
Copy link
Contributor

jreback commented Sep 7, 2016

#13832 cleaned up the interface and added some tests.

@jreback jreback added this to the No action milestone Sep 7, 2016
@kappapee
Copy link
Author

kappapee commented Sep 7, 2016

Thank you @jreback for the immediate response. Much appreciated.

@jreback
Copy link
Contributor

jreback commented Sep 7, 2016

hah happened to be looking when it popped up

trying to push out the rc1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timedelta Timedelta data type
Projects
None yet
Development

No branches or pull requests

2 participants