Skip to content

to_msgpack() with DateTimeIndex: AttributeError: 'NoneType' object has no attribute 'freqstr' #5506

Closed
@acowlikeobject

Description

@acowlikeobject

Trying df.to_msgpack() on a DataFrame with a DateTimeIndex produces an AttributeError.

Setting the index to an Int64Index fixes the issue, so it seems like it has to do with DateTimeIndex.

pd.version = '0.12.0-1095-g3239b29'

In [130]: from pandas.io.data import DataReader

In [131]: from pandas.io.packers import pack, unpack

In [132]: goog = DataReader('goog', 'yahoo')

In [133]: buf = pack(goog)
AttributeError Traceback (most recent call last)
in ()
----> 1 buf = pack(goog)

/home/user/environments/python3/lib/python3.3/site-packages/pandas/io/packers.py in pack(o, default, encoding, unicode_errors, use_single_float)
507 return Packer(default=default, encoding=encoding,
508 unicode_errors=unicode_errors,
--> 509 use_single_float=use_single_float).pack(o)
510
511

/home/user/environments/python3/lib/python3.3/site-packages/pandas/msgpack.cpython-33m.so in pandas.msgpack.Packer.pack (pandas/msgpack.cpp:3509)()

/home/user/environments/python3/lib/python3.3/site-packages/pandas/msgpack.cpython-33m.so in pandas.msgpack.Packer.pack (pandas/msgpack.cpp:3372)()

/home/user/environments/python3/lib/python3.3/site-packages/pandas/msgpack.cpython-33m.so in pandas.msgpack.Packer._pack (pandas/msgpack.cpp:3251)()

/home/user/environments/python3/lib/python3.3/site-packages/pandas/msgpack.cpython-33m.so in pandas.msgpack.Packer._pack (pandas/msgpack.cpp:2882)()

/home/user/environments/python3/lib/python3.3/site-packages/pandas/msgpack.cpython-33m.so in pandas.msgpack.Packer._pack (pandas/msgpack.cpp:3189)()

/home/user/environments/python3/lib/python3.3/site-packages/pandas/msgpack.cpython-33m.so in pandas.msgpack.Packer._pack (pandas/msgpack.cpp:3236)()

/home/user/environments/python3/lib/python3.3/site-packages/pandas/io/packers.py in encode(obj)
273 'dtype': obj.dtype.num,
274 'data': convert(obj.asi8),
--> 275 'freq': obj.freqstr,
276 'tz': obj.tz}
277 elif isinstance(obj, MultiIndex):

/home/user/environments/python3/lib/python3.3/site-packages/pandas/tseries/index.py in freqstr(self)
1394 @Property
1395 def freqstr(self):
-> 1396 return self.offset.freqstr
1397
1398 year = _field_accessor('year', 'Y')

AttributeError: 'NoneType' object has no attribute 'freqstr'

In [134]: goog
Out[134]:
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 973 entries, 2010-01-04 00:00:00 to 2013-11-12 00:00:00
Data columns (total 6 columns):
Open 973 non-null values
High 973 non-null values
Low 973 non-null values
Close 973 non-null values
Volume 973 non-null values
Adj Close 973 non-null values
dtypes: float64(5), int64(1)

In [135]: goog.index = np.arange(973)

In [136]: buf = pack(goog)

In [137]: len(buf)
Out[137]: 54908

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