From 6f09d81f727a44936411dd5196a2038eae926af9 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Wed, 17 Jan 2024 13:45:52 -0500 Subject: [PATCH] make tests make sense for pandas < and > 2 --- pvlib/tests/test_solarposition.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pvlib/tests/test_solarposition.py b/pvlib/tests/test_solarposition.py index c8fe13fd2c..63e32a4c3c 100644 --- a/pvlib/tests/test_solarposition.py +++ b/pvlib/tests/test_solarposition.py @@ -718,9 +718,20 @@ def test_sun_rise_set_transit_geometric(expected_rise_set_spa, golden_mst): atol=np.abs(expected_transit_error).max()) +@pytest.mark.parametrize('tz', [None, 'utc', 'US/Eastern']) +def test__datetime_to_unixtime(tz): + # for pandas < 2.0 where "unit" doesn't exist in pd.date_range. note that + # unit of ns is the only option in pandas<2, and the default in pandas 2.x + times = pd.date_range(start='2019-01-01', freq='h', periods=3, tz=tz) + expected = times.view(np.int64)/10**9 + actual = solarposition._datetime_to_unixtime(times) + np.testing.assert_equal(expected, actual) + + +@requires_pandas_2_0 @pytest.mark.parametrize('unit', ['ns', 'us', 's']) @pytest.mark.parametrize('tz', [None, 'utc', 'US/Eastern']) -def test__datetime_to_unixtime(unit, tz): +def test__datetime_to_unixtime_units(unit, tz): kwargs = dict(start='2019-01-01', freq='h', periods=3) times = pd.date_range(**kwargs, unit='ns', tz='UTC') expected = times.view(np.int64)/10**9