@@ -142,20 +142,15 @@ def test_spa_python_numpy_physical_dst(expected_solpos, golden):
142142
143143@pytest .mark .parametrize ('delta_t' , [65.0 , None , np .array ([65 , 65 ])])
144144def test_sun_rise_set_transit_spa (expected_rise_set_spa , golden , delta_t ):
145- # solution from NREL SAP web calculator
145+ # solution from NREL SPA web calculator
146146 south = Location (- 35.0 , 0.0 , tz = 'UTC' )
147- times = pd .DatetimeIndex ([datetime .datetime (1996 , 7 , 5 , 0 ),
148- datetime .datetime (2004 , 12 , 4 , 0 )]
149- ).tz_localize ('UTC' )
150- sunrise = pd .DatetimeIndex ([datetime .datetime (1996 , 7 , 5 , 7 , 8 , 15 ),
151- datetime .datetime (2004 , 12 , 4 , 4 , 38 , 57 )]
152- ).tz_localize ('UTC' ).tolist ()
153- sunset = pd .DatetimeIndex ([datetime .datetime (1996 , 7 , 5 , 17 , 1 , 4 ),
154- datetime .datetime (2004 , 12 , 4 , 19 , 2 , 3 )]
155- ).tz_localize ('UTC' ).tolist ()
156- transit = pd .DatetimeIndex ([datetime .datetime (1996 , 7 , 5 , 12 , 4 , 36 ),
157- datetime .datetime (2004 , 12 , 4 , 11 , 50 , 22 )]
158- ).tz_localize ('UTC' ).tolist ()
147+ times = pd .to_datetime (["1996-07-05" , "2004-12-04" ], utc = True )
148+ sunrise = pd .to_datetime (["1996-07-05 07:08:15" , "2004-12-04 04:38:57" ],
149+ utc = True )
150+ sunset = pd .to_datetime (["1996-07-05 17:01:04" , "2004-12-04 19:02:03" ],
151+ utc = True )
152+ transit = pd .to_datetime (["1996-07-05 12:04:36" , "2004-12-04 11:50:22" ],
153+ utc = True )
159154 frame = pd .DataFrame ({'sunrise' : sunrise ,
160155 'sunset' : sunset ,
161156 'transit' : transit }, index = times )
@@ -169,7 +164,9 @@ def test_sun_rise_set_transit_spa(expected_rise_set_spa, golden, delta_t):
169164 for col , data in result .items ():
170165 result_rounded [col ] = data .dt .round ('1s' )
171166
172- assert_frame_equal (frame , result_rounded )
167+ assert_frame_equal (frame , result_rounded ,
168+ check_dtype = False # ignore us/ns dtypes
169+ )
173170
174171 # test for Golden, CO compare to NREL SPA
175172 result = solarposition .sun_rise_set_transit_spa (
@@ -182,7 +179,9 @@ def test_sun_rise_set_transit_spa(expected_rise_set_spa, golden, delta_t):
182179 for col , data in result .items ():
183180 result_rounded [col ] = data .dt .round ('s' ).tz_convert ('MST' )
184181
185- assert_frame_equal (expected_rise_set_spa , result_rounded )
182+ assert_frame_equal (expected_rise_set_spa , result_rounded ,
183+ check_dtype = False # ignore us/ns dtypes
184+ )
186185
187186
188187@requires_ephem
@@ -726,7 +725,10 @@ def test_hour_angle_with_tricky_timezones():
726725 '2014-09-07 02:00:00' ,
727726 ]).tz_localize ('America/Santiago' , nonexistent = 'shift_forward' )
728727
729- with pytest .raises (pytz .exceptions .NonExistentTimeError ):
728+ with pytest .raises ((
729+ pytz .exceptions .NonExistentTimeError , # pandas 1.x, 2.x
730+ ValueError , # pandas 3.x
731+ )):
730732 times .normalize ()
731733
732734 # should not raise `pytz.exceptions.NonExistentTimeError`
@@ -740,7 +742,10 @@ def test_hour_angle_with_tricky_timezones():
740742 '2014-11-02 02:00:00' ,
741743 ]).tz_localize ('America/Havana' , ambiguous = [True , True , False , False ])
742744
743- with pytest .raises (pytz .exceptions .AmbiguousTimeError ):
745+ with pytest .raises ((
746+ pytz .exceptions .AmbiguousTimeError , # pandas 1.x, 2.x
747+ ValueError , # pandas 3.x
748+ )):
744749 solarposition .hour_angle (times , longitude , eot )
745750
746751
@@ -798,8 +803,13 @@ def test_sun_rise_set_transit_geometric(expected_rise_set_spa, golden_mst):
798803@pytest .mark .parametrize ('tz' , [None , 'utc' , 'US/Eastern' ])
799804def test__datetime_to_unixtime (tz ):
800805 # for pandas < 2.0 where "unit" doesn't exist in pd.date_range. note that
801- # unit of ns is the only option in pandas<2, and the default in pandas 2.x
802- times = pd .date_range (start = '2019-01-01' , freq = 'h' , periods = 3 , tz = tz )
806+ # unit of ns is the only option in pandas<2, and the default in pandas 2.x,
807+ # but the default is us in pandas 3.x
808+ kwargs = dict (start = '2019-01-01' , freq = 'h' , periods = 3 , tz = tz )
809+ try :
810+ times = pd .date_range (** kwargs , unit = 'ns' ) # pandas 2.x, 3.x
811+ except :
812+ times = pd .date_range (** kwargs ) # pandas 1.x
803813 expected = times .view (np .int64 )/ 10 ** 9
804814 actual = solarposition ._datetime_to_unixtime (times )
805815 np .testing .assert_equal (expected , actual )
0 commit comments