Skip to content

AttributeError on datetime.timedelta assignment after reindex #8209

Closed
@flaviovs

Description

@flaviovs

In the code below, I expected that the assignment didn't fail, since everything seems "right" . However, AttributeError is being raised.

A bug? Am I doing something wrong?

In [106]: import pandas as pd

In [107]: import datetime as dt

In [108]: s = pd.Series([])

In [109]: s
Out[109]: Series([], dtype: float64)

In [110]: s.loc['B'] = dt.timedelta(1)

In [111]: s
Out[111]: 
B   1 days
dtype: timedelta64[ns]

In [112]: s = s.reindex(s.index.insert(0, 'A'))

In [113]: s
Out[113]: 
A      NaT
B   1 days
dtype: timedelta64[ns]

In [114]: s.loc['A'] = dt.timedelta(1)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-114-f662acce72ae> in <module>()
----> 1 s.loc['A'] = dt.timedelta(1)
/home/flaviovs/.virtualenv/hm/local/lib/python2.7/site-packages/pandas-0.14.1_354_g12248ff-py2.7-linux-x86_64.egg/pandas/core/indexing.pyc in __setitem__(self, key, value)

/home/flaviovs/.virtualenv/hm/local/lib/python2.7/site-packages/pandas-0.14.1_354_g12248ff-py2.7-linux-x86_64.egg/pandas/core/indexing.pyc in _setitem_with_indexer(self, indexer, value)

/home/flaviovs/.virtualenv/hm/local/lib/python2.7/site-packages/pandas-0.14.1_354_g12248ff-py2.7-linux-x86_64.egg/pandas/core/internals.pyc in setitem(self, **kwargs)

/home/flaviovs/.virtualenv/hm/local/lib/python2.7/site-packages/pandas-0.14.1_354_g12248ff-py2.7-linux-x86_64.egg/pandas/core/internals.pyc in apply(self, f, axes, filter, do_integrity_check, **kwargs)

/home/flaviovs/.virtualenv/hm/local/lib/python2.7/site-packages/pandas-0.14.1_354_g12248ff-py2.7-linux-x86_64.egg/pandas/core/internals.pyc in setitem(self, indexer, value)

/home/flaviovs/.virtualenv/hm/local/lib/python2.7/site-packages/pandas-0.14.1_354_g12248ff-py2.7-linux-x86_64.egg/pandas/core/internals.pyc in _try_coerce_args(self, values, other)

/home/flaviovs/.virtualenv/hm/local/lib/python2.7/site-packages/pandas-0.14.1_354_g12248ff-py2.7-linux-x86_64.egg/pandas/core/internals.pyc in masker(v)

AttributeError: 'datetime.timedelta' object has no attribute 'view'

Tried with 0.14.1 and latest on GH (v0.15pre) , to no avail.

I'm so sorry I'm not able to provide a patch right now (still wrapping my head around pandas internals -- any directions about how to fix this is issue will be appreciated, though).

Versions:

In [125]: pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.3.final.0
python-bits: 64
OS: Linux
OS-release: 3.2.60
machine: x86_64
processor: 
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8

pandas: 0.14.1-354-g12248ff
nose: None
Cython: 0.20.1
numpy: 1.8.1
scipy: None
statsmodels: None
IPython: 2.1.0
sphinx: None
patsy: None
scikits.timeseries: None
dateutil: 2.2
pytz: 2014.3
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.1.1rc2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
rpy2: None
sqlalchemy: None
pymysql: None
psycopg2: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions