11import calendar
22import datetime
3+ import math
34import warnings
5+ import zoneinfo
6+ from datetime import timezone
47
58import numpy as np
69import pandas as pd
7-
8- from .conftest import assert_frame_equal , assert_series_equal
9- from numpy .testing import assert_allclose
1010import pytest
11- import pytz
11+ from numpy . testing import assert_allclose
1212
13- from pvlib .location import Location
1413from pvlib import solarposition , spa
14+ from pvlib .location import Location
1515
16- from .conftest import (
17- requires_ephem , requires_spa_c , requires_numba , requires_pandas_2_0
18- )
16+ from .conftest import (assert_frame_equal , assert_series_equal , requires_ephem ,
17+ requires_numba , requires_pandas_2_0 , requires_spa_c )
1918
2019# setup times and locations to be tested.
2120times = pd .date_range (start = datetime .datetime (2014 , 6 , 24 ),
@@ -343,29 +342,26 @@ def test_pyephem_physical_dst(expected_solpos, golden):
343342
344343@requires_ephem
345344def test_calc_time ():
346- import pytz
347- import math
348345 # validation from USNO solar position calculator online
349346
350- epoch = datetime .datetime (1970 , 1 , 1 )
351- epoch_dt = pytz .utc .localize (epoch )
347+ epoch = datetime .datetime (1970 , 1 , 1 , tzinfo = timezone .utc )
352348
353349 loc = tus
354350 loc .pressure = 0
355- actual_time = pytz . timezone (loc .tz ). localize (
356- datetime .datetime (2014 , 10 , 10 , 8 , 30 ) )
357- lb = pytz . timezone ( loc . tz ). localize ( datetime .datetime (2014 , 10 , 10 , tol ) )
358- ub = pytz . timezone ( loc . tz ). localize ( datetime .datetime (2014 , 10 , 10 , 10 ) )
351+ tz = zoneinfo . ZoneInfo (loc .tz )
352+ actual_time = datetime .datetime (2014 , 10 , 10 , 8 , 30 , tzinfo = tz )
353+ lb = datetime .datetime (2014 , 10 , 10 , tol , tzinfo = tz )
354+ ub = datetime .datetime (2014 , 10 , 10 , 10 , tzinfo = tz )
359355 alt = solarposition .calc_time (lb , ub , loc .latitude , loc .longitude ,
360356 'alt' , math .radians (24.7 ))
361357 az = solarposition .calc_time (lb , ub , loc .latitude , loc .longitude ,
362358 'az' , math .radians (116.3 ))
363- actual_timestamp = (actual_time - epoch_dt ).total_seconds ()
359+ actual_timestamp = (actual_time - epoch ).total_seconds ()
364360
365361 assert_allclose ((alt .replace (second = 0 , microsecond = 0 ) -
366- epoch_dt ).total_seconds (), actual_timestamp )
362+ epoch ).total_seconds (), actual_timestamp )
367363 assert_allclose ((az .replace (second = 0 , microsecond = 0 ) -
368- epoch_dt ).total_seconds (), actual_timestamp )
364+ epoch ).total_seconds (), actual_timestamp )
369365
370366
371367@requires_ephem
@@ -715,6 +711,15 @@ def test_hour_angle_with_tricky_timezones():
715711 # GH 2132
716712 # tests timezones that have a DST shift at midnight
717713
714+ try : # transitive dependency to pytz through pandas < 3
715+ import pytz
716+ _NonExistentTimeError = pytz .exceptions .NonExistentTimeError
717+ _AmbiguousTimeError = pytz .exceptions .AmbiguousTimeError
718+ except ImportError : # pragma: no cover
719+ # pandas 3.x dropped pytz; these are now raised as ValueError
720+ _NonExistentTimeError = ValueError
721+ _AmbiguousTimeError = ValueError
722+
718723 eot = np .array ([- 3.935172 , - 4.117227 , - 4.026295 , - 4.026295 ])
719724
720725 longitude = 70.6693
@@ -726,7 +731,7 @@ def test_hour_angle_with_tricky_timezones():
726731 ]).tz_localize ('America/Santiago' , nonexistent = 'shift_forward' )
727732
728733 with pytest .raises ((
729- pytz . exceptions . NonExistentTimeError , # pandas 1.x, 2.x
734+ _NonExistentTimeError , # pandas 1.x, 2.x
730735 ValueError , # pandas 3.x
731736 )):
732737 times .normalize ()
@@ -743,7 +748,7 @@ def test_hour_angle_with_tricky_timezones():
743748 ]).tz_localize ('America/Havana' , ambiguous = [True , True , False , False ])
744749
745750 with pytest .raises ((
746- pytz . exceptions . AmbiguousTimeError , # pandas 1.x, 2.x
751+ _AmbiguousTimeError , # pandas 1.x, 2.x
747752 ValueError , # pandas 3.x
748753 )):
749754 solarposition .hour_angle (times , longitude , eot )
0 commit comments