From 3cd2fb06bd652d5c13dd992679da8b1ac2f6e12c Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Thu, 18 Jul 2019 11:26:39 +0200 Subject: [PATCH] Add timezone test at temporal matching --- tests/test_temporal_matching.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_temporal_matching.py b/tests/test_temporal_matching.py index ca75e94a..bbd011a5 100644 --- a/tests/test_temporal_matching.py +++ b/tests/test_temporal_matching.py @@ -31,6 +31,7 @@ ''' +import pytz import pytesmo.temporal_matching as tmatching import pandas as pd from datetime import datetime @@ -244,3 +245,22 @@ def test_matching_tz(): np.nan, np.nan]), matched.matched_data) assert len(matched) == 10 + + +def test_timezone_handling(): + data = np.arange(5.0) + data[3] = np.nan + + match_df = pd.DataFrame({"data": data}, index=pd.date_range(datetime(2007, 1, 1, 0), + "2007-01-05", freq="D", tz="UTC")) + timezone = pytz.timezone("UTC") + ref_df = pd.DataFrame({"matched_data": np.arange(5)}, + index=[timezone.localize(datetime(2007, 1, 1, 9)), + timezone.localize(datetime(2007, 1, 2, 9)), + timezone.localize(datetime(2007, 1, 3, 9)), + timezone.localize(datetime(2007, 1, 4, 9)), + timezone.localize(datetime(2007, 1, 5, 9))]) + matched = tmatching.matching(ref_df, match_df) + + nptest.assert_allclose(np.array([0, 1, 2, 4]), matched.matched_data) + assert len(matched) == 4