mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-05 12:50:21 +08:00
TST: expand tests
DOC: add comment to workaround line
This commit is contained in:
@@ -6,6 +6,7 @@ import itertools
|
||||
from itertools import product
|
||||
|
||||
import blaze as bz
|
||||
from nose_parameterized import parameterized
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from pandas.util.testing import assert_series_equal
|
||||
@@ -462,31 +463,44 @@ class BlazeEventsLoaderTestCase(EventsLoaderTestCase):
|
||||
|
||||
|
||||
class EventLoaderUtilsTestCase(ZiplineTestCase):
|
||||
dates = [pd.Timestamp('2013-01-04 3:00:00'), pd.Timestamp('2013-01-24'),
|
||||
pd.Timestamp('2013-04-04'), pd.Timestamp('2013-04-21')]
|
||||
combos = list(itertools.permutations(dates))
|
||||
|
||||
def test_normalize_to_query_time(self):
|
||||
# Order matters in pandas 18.0.2. Prior to that, using tz_convert on
|
||||
# a DatetimeIndex with DST/EST timestamps mixed resulted in some of
|
||||
# them being an hour off (1 hour past midnight).
|
||||
expected = pd.Series(
|
||||
[pd.Timestamp('2013-01-04'),
|
||||
dates = [pd.Timestamp('2013-01-04 3:00:00'),
|
||||
pd.Timestamp('2013-01-24'),
|
||||
pd.Timestamp('2013-01-31 20:00:00'),
|
||||
pd.Timestamp('2013-04-04'),
|
||||
pd.Timestamp('2013-04-21')]
|
||||
).reset_index(drop=True)
|
||||
combos = list(itertools.permutations(dates))
|
||||
|
||||
expected_us = pd.Series(
|
||||
[pd.Timestamp('2013-01-04'),
|
||||
pd.Timestamp('2013-01-24'),
|
||||
pd.Timestamp('2013-02-01'),
|
||||
pd.Timestamp('2013-04-04'),
|
||||
pd.Timestamp('2013-04-21')]
|
||||
)
|
||||
|
||||
# Russia's TZ offset is +3
|
||||
expected_russia = pd.Series(
|
||||
[pd.Timestamp('2013-01-04'),
|
||||
pd.Timestamp('2013-01-24'),
|
||||
pd.Timestamp('2013-01-31'),
|
||||
pd.Timestamp('2013-04-04'),
|
||||
pd.Timestamp('2013-04-21')]
|
||||
)
|
||||
|
||||
# Test with timezones on either side of the meridian
|
||||
@parameterized.expand([(expected_us, 'US/Eastern', time(8, 45)),
|
||||
(expected_russia, 'Europe/Moscow', time(16, 45))])
|
||||
def test_normalize_to_query_time(self, expected, tz, query_time):
|
||||
# Order matters in pandas 0.18.2. Prior to that, using tz_convert on
|
||||
# a DatetimeIndex with DST/EST timestamps mixed resulted in some of
|
||||
# them being an hour off (1 hour past midnight).
|
||||
for combo in self.combos:
|
||||
df = pd.DataFrame({"timestamp": combo})
|
||||
tz = 'US/Eastern'
|
||||
query_time = time(8, 45)
|
||||
result = normalize_timestamp_to_query_time(df,
|
||||
query_time,
|
||||
tz,
|
||||
inplace=False,
|
||||
ts_field='timestamp')
|
||||
result = result.sort("timestamp").reset_index(drop=True)
|
||||
assert_series_equal(result['timestamp'], expected)
|
||||
|
||||
|
||||
|
||||
assert_series_equal(result['timestamp'], expected,
|
||||
check_names=False)
|
||||
|
||||
Reference in New Issue
Block a user