Skip to content

Commit 6f09d81

Browse files
committed
make tests make sense for pandas < and > 2
1 parent 356f5b7 commit 6f09d81

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pvlib/tests/test_solarposition.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,20 @@ def test_sun_rise_set_transit_geometric(expected_rise_set_spa, golden_mst):
718718
atol=np.abs(expected_transit_error).max())
719719

720720

721+
@pytest.mark.parametrize('tz', [None, 'utc', 'US/Eastern'])
722+
def test__datetime_to_unixtime(tz):
723+
# for pandas < 2.0 where "unit" doesn't exist in pd.date_range. note that
724+
# unit of ns is the only option in pandas<2, and the default in pandas 2.x
725+
times = pd.date_range(start='2019-01-01', freq='h', periods=3, tz=tz)
726+
expected = times.view(np.int64)/10**9
727+
actual = solarposition._datetime_to_unixtime(times)
728+
np.testing.assert_equal(expected, actual)
729+
730+
731+
@requires_pandas_2_0
721732
@pytest.mark.parametrize('unit', ['ns', 'us', 's'])
722733
@pytest.mark.parametrize('tz', [None, 'utc', 'US/Eastern'])
723-
def test__datetime_to_unixtime(unit, tz):
734+
def test__datetime_to_unixtime_units(unit, tz):
724735
kwargs = dict(start='2019-01-01', freq='h', periods=3)
725736
times = pd.date_range(**kwargs, unit='ns', tz='UTC')
726737
expected = times.view(np.int64)/10**9

0 commit comments

Comments
 (0)