Skip to content
Browse files

BUG: always store UTC datetime64 value in Timestamp, test comparisons…

…. close #1260
  • Loading branch information...
1 parent 04c8457 commit 9f71e0ff635af08c56d1264cc38dd9c3c185cd95 @wesm wesm committed May 25, 2012
Showing with 20 additions and 19 deletions.
  1. +1 −0 TODO.rst
  2. +5 −7 pandas/src/datetime.pyx
  3. +14 −12 pandas/tseries/tests/test_timezones.py
View
1 TODO.rst
@@ -57,3 +57,4 @@ Performance blog
- Take
git log v0.6.1..master --pretty=format:%aN | sort | uniq -c | sort -rn
+git log a8c2f88..master --pretty=format:%aN | sort | uniq -c | sort -rn
View
12 pandas/src/datetime.pyx
@@ -333,7 +333,8 @@ cpdef convert_to_tsobject(object ts, object tz=None):
elif PyDateTime_Check(ts):
obj.value = _pydatetime_to_dts(ts, &obj.dts)
obj.tzinfo = ts.tzinfo
- utc_convert = 0
+ if obj.tzinfo is not None:
+ obj.value -= _delta_to_nanoseconds(obj.tzinfo._utcoffset)
elif PyDate_Check(ts):
obj.value = _date_to_datetime64(ts, &obj.dts)
else:
@@ -350,12 +351,9 @@ cpdef convert_to_tsobject(object ts, object tz=None):
pos = trans.searchsorted(obj.value) - 1
inf = tz._transition_info[pos]
- obj.value = obj.value + deltas[pos]
-
- if utc_convert:
- pandas_datetime_to_datetimestruct(obj.value, PANDAS_FR_ns,
- &obj.dts)
- obj.tzinfo = tz._tzinfos[inf]
+ pandas_datetime_to_datetimestruct(obj.value + deltas[pos],
+ PANDAS_FR_ns, &obj.dts)
+ obj.tzinfo = tz._tzinfos[inf]
return obj
View
26 pandas/tseries/tests/test_timezones.py
@@ -318,18 +318,20 @@ def test_intersection(self):
result = left.intersection(right)
self.assert_(result.tz == left.tz)
- def test_tz_timestamp_eq(self):
- dt = datetime.today()
- utc = lib.Timestamp(dt, tz=pytz.timezone('UTC'))
- for z in pytz.all_timezones:
- zts = utc.tz_convert(pytz.timezone(z))
- self.assert_(utc == zts)
-
- rng = date_range('3/1/2001', '4/1/2001', freq='H', tz='utc')
- for z in pytz.all_timezones:
- rng_z = rng.tz_convert(z)
- for k1, k2 in zip(rng, rng_z):
- self.assert_(k1 == k2)
+ def test_timestamp_equality_different_timezones(self):
+ utc_range = date_range('1/1/2000', periods=20, tz='UTC')
+
+ eastern_range = utc_range.tz_convert('US/Eastern')
+ berlin_range = utc_range.tz_convert('Europe/Berlin')
+
+ for a, b, c in zip(utc_range, eastern_range, berlin_range):
+ self.assertEquals(a, b)
+ self.assertEquals(b, c)
+ self.assertEquals(a, c)
+
+ self.assert_((utc_range == eastern_range).all())
+ self.assert_((utc_range == berlin_range).all())
+ self.assert_((berlin_range == eastern_range).all())
if __name__ == '__main__':
nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],

0 comments on commit 9f71e0f

Please sign in to comment.
Something went wrong with that request. Please try again.