8000 BUG: fix NaT support for msgpack format. by llllllllll · Pull Request #12307 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
BUG: fix NaT support for msgpack format.
  • Loading branch information
Joe Jevnik committed Feb 12, 2016
commit d0fd21558ee23b7fefc9746cafa12a4b9b9d1e78
5 changes: 5 additions & 0 deletions doc/source/whatsnew/v0.18.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -967,4 +967,9 @@ Bug Fixes
- Bug in ``.skew`` and ``.kurt`` due to roundoff error for highly similar values (:issue:`11974`)

- Bug in ``buffer_rd_bytes`` src->buffer could be freed more than once if reading failed, causing a segfault (:issue:`12098`)

- Bug in ``crosstab`` where arguments with non-overlapping indexes would return a ``KeyError`` (:issue:`10291`)


- Bug in ``to_msgpack`` and ``from_msgpack`` which did not correctly serialize
or deserialize ``NaT`` (:issue:`12307`).
9 changes: 7 additions & 2 deletions pandas/io/packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
from pandas.compat import u
from pandas import (Timestamp, Period, Series, DataFrame, # noqa
Index, MultiIndex, Float64Index, Int64Index,
Panel, RangeIndex, PeriodIndex, DatetimeIndex)
Panel, RangeIndex, PeriodIndex, DatetimeIndex, NaT)
from pandas.tslib import NaTType
from pandas.sparse.api import SparseSeries, SparseDataFrame, SparsePanel
from pandas.sparse.array import BlockIndex, IntIndex
from pandas.core.generic import NDFrame
Expand Down Expand Up @@ -383,7 +384,7 @@ def encode(obj):
} for b in data.blocks]}

elif isinstance(obj, (datetime, date, np.datetime64, timedelta,
np.timedelta64)):
np.timedelta64, NaTType)):
if isinstance(obj, Timestamp):
tz = obj.tzinfo
if tz is not None:
Expand All @@ -395,6 +396,8 @@ def encode(obj):
'value': obj.value,
'offset': offset,
'tz': tz}
if isinstance(obj, NaTType):
return {'typ': 'nat'}
elif isinstance(obj, np.timedelta64):
return {'typ': 'timedelta64',
'data': obj.view('i8')}
Expand Down Expand Up @@ -462,6 +465,8 @@ def decode(obj):
return obj
elif typ == 'timestamp':
return Timestamp(obj['value'], tz=obj['tz'], offset=obj['offset'])
elif typ == 'nat':
return NaT
elif typ == 'period':
return Period(ordinal=obj['ordinal'], freq=obj['freq'])
elif typ == 'index':
Expand Down
6 changes: 5 additions & 1 deletion pandas/io/tests/test_packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pandas.tests.test_panel import assert_panel_equal

import pandas
from pandas import Timestamp, tslib
from pandas import Timestamp, NaT, tslib

nan = np.nan

Expand Down Expand Up @@ -225,6 +225,10 @@ def test_timestamp(self):
i_rec = self.encode_decode(i)
self.assertEqual(i, i_rec)

def test_nat(self):
nat_rec = self.encode_decode(NaT)
self.assertIs(NaT, nat_rec)

def test_datetimes(self):

# fails under 2.6/win32 (np.datetime64 seems broken)
Expand Down
0