Skip to content

Commit

Permalink
BUG: tz aware Timestamp field accessors returns local values (pandas-…
Browse files Browse the repository at this point in the history
…dev#13303)

Add whatsnew
  • Loading branch information
mroeschke committed Mar 20, 2017
1 parent 9ab57dc commit 4391f3b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ Bug Fixes
~~~~~~~~~

- Bug in ``Timestamp.replace`` now raises ``TypeError`` when incorrect argument names are given; previously this raised ``ValueError`` (:issue:`15240`)
- Bug in ``Timestamp`` returning UTC based time/date attributes when a timezone was provided (:issue:`13303`)
- Bug in ``Index`` power operations with reversed operands (:issue:`14973`)
- Bug in ``TimedeltaIndex`` addition where overflow was being allowed without error (:issue:`14816`)
- Bug in ``TimedeltaIndex`` raising a ``ValueError`` when boolean indexing with ``loc`` (:issue:`14946`)
Expand Down
5 changes: 4 additions & 1 deletion pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,10 @@ cdef class _Timestamp(datetime):
return datetime.__sub__(self, other)

cpdef _get_field(self, field):
out = get_date_field(np.array([self.value], dtype=np.int64), field)
val = self.value
if self.tz is not None and not _is_utc(self.tz):
val = tz_convert_single(self.value, 'UTC', self.tz)
out = get_date_field(np.array([val], dtype=np.int64), field)
return int(out[0])

cpdef _get_start_end_field(self, field):
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/scalar/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,23 @@ def check(value, equal):
check(ts.daysinmonth, 31)
check(ts.daysinmonth, 31)

# GH 13303
ts = Timestamp('2014-12-31 23:59:00-05:00', tz='US/Eastern')
check(ts.year, 2014)
check(ts.month, 12)
check(ts.day, 31)
check(ts.hour, 23)
check(ts.minute, 59)
check(ts.second, 0)
self.assertRaises(AttributeError, lambda: ts.millisecond)
check(ts.microsecond, 0)
check(ts.nanosecond, 0)
check(ts.dayofweek, 2)
check(ts.quarter, 4)
check(ts.dayofyear, 365)
check(ts.week, 1)
check(ts.daysinmonth, 31)

def test_nat_fields(self):
# GH 10050
ts = Timestamp('NaT')
Expand Down

0 comments on commit 4391f3b

Please sign in to comment.