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

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

Closed
acowlikeobject opened this Issue Nov 13, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@acowlikeobject

acowlikeobject commented Nov 13, 2013

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

@jreback

This comment has been minimized.

Contributor

jreback commented Nov 13, 2013

thanks for the report....fixed in PR #5507 (as well as an slightly related bug)

@acowlikeobject

This comment has been minimized.

acowlikeobject commented Nov 13, 2013

Cheers Jeff. Will give it a go after it's been merged.

@jreback

This comment has been minimized.

Contributor

jreback commented Nov 13, 2013

@acowlikeobject already...give a try (this also changed df.to_msgpack() to return a string (I dropped the StringIO stuff externally...not necessary)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment