Skip to content

Commit

Permalink
Merge pull request #7478 from ahlmss/TST7420
Browse files Browse the repository at this point in the history
Fix cache key collision and add test for cache key distinctness.
  • Loading branch information
jreback committed Jun 17, 2014
2 parents 68c9807 + 94c73ec commit 4db22f4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions pandas/tseries/tests/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,21 @@ def test_utc_with_system_utc(self):
self.assertEqual(ts, ts.tz_convert(dateutil.tz.tzutc()))


class TestTimeZoneCacheKey(tm.TestCase):
def test_cache_keys_are_distinct_for_pytz_vs_dateutil(self):
tzs = pytz.common_timezones
for tz_name in tzs:
if tz_name == 'UTC':
# skip utc as it's a special case in dateutil
continue
tz_p = tslib.maybe_get_tz(tz_name)
tz_d = tslib.maybe_get_tz('dateutil/' + tz_name)
if tz_d is None:
# skip timezones that dateutil doesn't know about.
continue
self.assertNotEqual(tslib._p_tz_cache_key(tz_p), tslib._p_tz_cache_key(tz_d))


class TestTimeZones(tm.TestCase):
_multiprocess_can_split_ = True

Expand Down
7 changes: 6 additions & 1 deletion pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1962,6 +1962,11 @@ cdef inline bint _treat_tz_as_dateutil(object tz):
return hasattr(tz, '_trans_list') and hasattr(tz, '_trans_idx')


def _p_tz_cache_key(tz):
''' Python interface for cache function to facilitate testing.'''
return _tz_cache_key(tz)


cdef inline object _tz_cache_key(object tz):
"""
Return the key in the cache for the timezone info object or None if unknown.
Expand All @@ -1982,7 +1987,7 @@ cdef inline object _tz_cache_key(object tz):
raise ValueError('Bad tz filename. Dateutil on python 3 on windows has a bug which causes tzfile._filename to be the same for all '
'timezone files. Please construct dateutil timezones implicitly by passing a string like "dateutil/Europe/London" '
'when you construct your pandas objects instead of passing a timezone object. See https://github.com/pydata/pandas/pull/7362')
return tz._filename
return 'dateutil' + tz._filename
else:
return None

Expand Down

0 comments on commit 4db22f4

Please sign in to comment.