Skip to content

Commit

Permalink
BUG: Index created from FixedOffset tz without a name loses tz awaren…
Browse files Browse the repository at this point in the history
…ess #2604
  • Loading branch information
Chang She committed Dec 28, 2012
1 parent 63103c4 commit 009186c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions pandas/tseries/tests/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def dst(self, dt):
return timedelta(0)

fixed_off = FixedOffset(-420, '-07:00')
fixed_off_no_name = FixedOffset(-330, None)

class TestTimeZoneSupport(unittest.TestCase):
_multiprocess_can_split_ = True
Expand Down Expand Up @@ -190,6 +191,16 @@ def test_create_with_fixed_tz(self):
rng3 = date_range('3/11/2012 05:00:00+07:00', '6/11/2012 05:00:00+07:00')
self.assert_((rng.values == rng3.values).all())

def test_create_with_fixedoffset_noname(self):
off = fixed_off_no_name
start = datetime(2012, 3, 11, 5, 0, 0, tzinfo=off)
end = datetime(2012, 6, 11, 5, 0, 0, tzinfo=off)
rng = date_range(start=start, end=end)
self.assertEqual(off, rng.tz)

idx = Index([start, end])
self.assertEqual(off, idx.tz)

def test_date_range_localize(self):
rng = date_range('3/11/2012 03:00', periods=15, freq='H', tz='US/Eastern')
rng2 = DatetimeIndex(['3/11/2012 03:00', '3/11/2012 04:00'],
Expand Down
5 changes: 4 additions & 1 deletion pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,10 @@ cdef inline object _get_zone(object tz):
return 'UTC'
else:
try:
return tz.zone
zone = tz.zone
if zone is None:
return tz
return zone
except AttributeError:
return tz

Expand Down

0 comments on commit 009186c

Please sign in to comment.