Skip to content

Fix cache key collision and add test for cache key distinctness. #7478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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