Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cgangwar11 committed Feb 6, 2019
1 parent 93568cc commit 702d04f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pandas/io/packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

from pandas.io.common import _stringify_path, get_filepath_or_buffer
from pandas.io.msgpack import ExtType, Packer as _Packer, Unpacker as _Unpacker

from pytz import FixedOffset, _FixedOffset
# check which compression libs we have installed
try:
import zlib
Expand Down Expand Up @@ -390,7 +390,8 @@ def encode(obj):

# store tz info and data as UTC
if tz is not None:
tz = u(tz.zone)
tz = u(tz.zone) if not isinstance(tz, _FixedOffset) \
else u(tz._minutes)
obj = obj.tz_convert('UTC')
return {u'typ': u'datetime_index',
u'klass': u(obj.__class__.__name__),
Expand Down Expand Up @@ -608,7 +609,8 @@ def decode(obj):
data = unconvert(obj[u'data'], np.int64, obj.get(u'compress'))
d = dict(name=obj[u'name'], freq=obj[u'freq'])
result = DatetimeIndex(data, **d)
tz = obj[u'tz']
tz = FixedOffset(obj[u'tz']) if (isinstance(obj['tz'], int)) \
else obj[u'tz']

# reverse tz conversion
if tz is not None:
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/io/test_packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ def categorical_index(self):
result = self.encode_decode(df)
tm.assert_frame_equal(result, df)

def test_timezone_encode_decode(self):
expected = date_range(start='2018-12-02 14:50:00-07:00',
end='2018-12-03 03:11:00-07:00', freq='1min')
result = self.encode_decode(expected)
tm.assert_index_equal(result, expected)


class TestSeries(TestPackers):

Expand Down

0 comments on commit 702d04f

Please sign in to comment.