Skip to content

Commit

Permalink
make tests make sense for pandas < and > 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kandersolar committed Jan 17, 2024
1 parent 356f5b7 commit 6f09d81
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pvlib/tests/test_solarposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 737 in pvlib/tests/test_solarposition.py

View check run for this annotation

Codecov / codecov/patch

pvlib/tests/test_solarposition.py#L735-L737

Added lines #L735 - L737 were not covered by tests
Expand Down

0 comments on commit 6f09d81

Please sign in to comment.