-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
tests for tslibs.conversion and tslibs.timezones #19642
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
984e94b
tslibs.conversions tests
jbrockmendel 48e2dd1
test tslibs.timezones
jbrockmendel 91787b1
parametrize
jbrockmendel 0179f57
requested edits, parametrization
jbrockmendel 6c30451
Merge branch 'master' of https://github.com/pandas-dev/pandas into it…
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
import pandas.util.testing as tm | ||
from pandas import date_range | ||
from pandas._libs.tslib import iNaT | ||
from pandas._libs.tslibs import conversion, timezones | ||
|
||
|
||
def compare_utc_to_local(tz_didx, utc_didx): | ||
f = lambda x: conversion.tz_convert_single(x, 'UTC', tz_didx.tz) | ||
result = conversion.tz_convert(tz_didx.asi8, 'UTC', tz_didx.tz) | ||
result_single = np.vectorize(f)(tz_didx.asi8) | ||
tm.assert_numpy_array_equal(result, result_single) | ||
|
||
|
||
def compare_local_to_utc(tz_didx, utc_didx): | ||
f = lambda x: conversion.tz_convert_single(x, tz_didx.tz, 'UTC') | ||
result = conversion.tz_convert(utc_didx.asi8, tz_didx.tz, 'UTC') | ||
result_single = np.vectorize(f)(utc_didx.asi8) | ||
tm.assert_numpy_array_equal(result, result_single) | ||
|
||
|
||
class TestTZConvert(object): | ||
|
||
@pytest.mark.parametrize('tz', ['UTC', 'Asia/Tokyo', | ||
'US/Eastern', 'Europe/Moscow']) | ||
def test_tz_convert_single_matches_tz_convert_hourly(self, tz): | ||
# US: 2014-03-09 - 2014-11-11 | ||
# MOSCOW: 2014-10-26 / 2014-12-31 | ||
tz_didx = date_range('2014-03-01', '2015-01-10', freq='H', tz=tz) | ||
utc_didx = date_range('2014-03-01', '2015-01-10', freq='H') | ||
compare_utc_to_local(tz_didx, utc_didx) | ||
|
||
# local tz to UTC can be differ in hourly (or higher) freqs because | ||
# of DST | ||
compare_local_to_utc(tz_didx, utc_didx) | ||
|
||
@pytest.mark.parametrize('tz', ['UTC', 'Asia/Tokyo', | ||
'US/Eastern', 'Europe/Moscow']) | ||
@pytest.mark.parametrize('freq', ['D', 'A']) | ||
def test_tz_convert_single_matches_tz_convert(self, tz, freq): | ||
tz_didx = date_range('2000-01-01', '2020-01-01', freq=freq, tz=tz) | ||
utc_didx = date_range('2000-01-01', '2020-01-01', freq=freq) | ||
compare_utc_to_local(tz_didx, utc_didx) | ||
compare_local_to_utc(tz_didx, utc_didx) | ||
|
||
@pytest.mark.parametrize('arr', [ | ||
pytest.param(np.array([], dtype=np.int64), id='empty'), | ||
pytest.param(np.array([iNaT], dtype=np.int64), id='all_nat')]) | ||
def test_tz_convert_corner(self, arr): | ||
result = conversion.tz_convert(arr, | ||
timezones.maybe_get_tz('US/Eastern'), | ||
timezones.maybe_get_tz('Asia/Tokyo')) | ||
tm.assert_numpy_array_equal(result, arr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
from datetime import datetime | ||
|
||
import pytest | ||
import pytz | ||
import dateutil.tz | ||
|
||
from pandas._libs.tslibs import timezones | ||
from pandas import Timestamp | ||
|
||
|
||
@pytest.mark.parametrize('tz_name', list(pytz.common_timezones)) | ||
def test_cache_keys_are_distinct_for_pytz_vs_dateutil(tz_name): | ||
if tz_name == 'UTC': | ||
# skip utc as it's a special case in dateutil | ||
return | ||
tz_p = timezones.maybe_get_tz(tz_name) | ||
tz_d = timezones.maybe_get_tz('dateutil/' + tz_name) | ||
if tz_d is None: | ||
# skip timezones that dateutil doesn't know about. | ||
return | ||
assert timezones._p_tz_cache_key(tz_p) != timezones._p_tz_cache_key(tz_d) | ||
|
||
|
||
def test_tzlocal(): | ||
# GH#13583 | ||
ts = Timestamp('2011-01-01', tz=dateutil.tz.tzlocal()) | ||
assert ts.tz == dateutil.tz.tzlocal() | ||
assert "tz='tzlocal()')" in repr(ts) | ||
|
||
tz = timezones.maybe_get_tz('tzlocal()') | ||
assert tz == dateutil.tz.tzlocal() | ||
|
||
# get offset using normal datetime for test | ||
offset = dateutil.tz.tzlocal().utcoffset(datetime(2011, 1, 1)) | ||
offset = offset.total_seconds() * 1000000000 | ||
assert ts.value + offset == Timestamp('2011-01-01').value |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's left in this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not much. I'll try to kill it off after clearing out the current PR backlog.