diff --git a/doc/conf.py b/doc/conf.py index 4dc619ad2..964ef6880 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -4,7 +4,7 @@ # # This code is part of the Fatiando a Terra project (https://www.fatiando.org) # -import datetime +import datetime as dt import pygmt.sphinx_gallery import pyvista @@ -16,8 +16,7 @@ # ----------------------------------------------------------------------------- project = "Harmonica" copyright_info = ( - f"2018-{datetime.datetime.now(tz=datetime.timezone.utc).year}," - f" The {project} Developers" + f"2018-{dt.datetime.now(tz=dt.timezone.utc).year}, The {project} Developers" ) if len(harmonica.__version__.split("+")) > 1 or harmonica.__version__ == "unknown": version = "dev" diff --git a/env/requirements-style.txt b/env/requirements-style.txt index a531bcc89..1328b5c25 100644 --- a/env/requirements-style.txt +++ b/env/requirements-style.txt @@ -1,4 +1,4 @@ # Requirements for checking code style -ruff==0.16.* +ruff==0.17.* burocrata==0.2.* zizmor==1.30.* diff --git a/environment.yml b/environment.yml index 4a0d3c2ad..967276387 100644 --- a/environment.yml +++ b/environment.yml @@ -46,6 +46,6 @@ dependencies: - gdal - trame # needed by pyvista # Code style checks and autoformat - - ruff==0.16.* + - ruff==0.17.* - burocrata==0.2.* - zizmor==1.30.* diff --git a/src/harmonica/_spherical_harmonics/igrf.py b/src/harmonica/_spherical_harmonics/igrf.py index 325c050b2..e6cd7ea2f 100644 --- a/src/harmonica/_spherical_harmonics/igrf.py +++ b/src/harmonica/_spherical_harmonics/igrf.py @@ -8,7 +8,7 @@ Calculation of the IGRF magnetic field. """ -import datetime +import datetime as dt import pathlib import bordado as bd @@ -120,17 +120,17 @@ def interpolate_coefficients(date, max_degree, years, g, h, g_sv, h_sv): raise ValueError(message) # Find out which epoch is the last compatible one. index = int((date.year - years[0]) // 5) - start_of_epoch = datetime.datetime( + start_of_epoch = dt.datetime( year=years[index], month=1, day=1, # Specify start of the year in UTC time if date has timezone information - tzinfo=datetime.timezone.utc if date.tzinfo is not None else None, + tzinfo=dt.timezone.utc if date.tzinfo is not None else None, ) seconds_since_epoch = (date - start_of_epoch).total_seconds() epoch = ( - datetime.datetime(year=years[index] + 5, month=1, day=1) # ruff: ignore[DTZ001] - - datetime.datetime(year=years[index], month=1, day=1) # ruff: ignore[DTZ001] + dt.datetime(year=years[index] + 5, month=1, day=1) + - dt.datetime(year=years[index], month=1, day=1) ).total_seconds() year_in_seconds = 365.25 * 24 * 60 * 60 g_date = np.zeros((max_degree + 1, max_degree + 1)) @@ -291,7 +291,7 @@ def __init__( ellipsoid=boule.WGS84, ): if isinstance(date, str): - self.date = datetime.datetime.fromisoformat(date) + self.date = dt.datetime.fromisoformat(date) else: self.date = date self.max_degree = max_degree diff --git a/test/test_igrf.py b/test/test_igrf.py index 926d14eda..7b97227be 100644 --- a/test/test_igrf.py +++ b/test/test_igrf.py @@ -6,7 +6,7 @@ # """Test the IGRF results against the ones calculated by the BGS.""" -import datetime +import datetime as dt import pathlib import bordado as bd @@ -123,7 +123,7 @@ ["2021-02-01", 35605.6, 1421.6, 1788.7], ["2026-08-02", 35675.0, 1368.9, 2067.7], ] -UTC = datetime.timezone.utc +UTC = dt.timezone.utc def test_igrf14__fetch_coefficients(): @@ -166,7 +166,7 @@ def test_interpolate_coefficients(tzinfo): years, g, h, g_sv, h_sv = load_igrf(IGRF14("2020-02-10")._fetch_coefficient_file()) for i, year in enumerate(years): g_date, h_date = interpolate_coefficients( - datetime.datetime( + dt.datetime( year, month=1, day=1, hour=0, minute=1, second=0, tzinfo=tzinfo ), g.shape[1] - 1, @@ -188,7 +188,7 @@ def test_interpolate_coefficients_max_degree(tzinfo): max_degree = 13 years, g, h, g_sv, h_sv = load_igrf(IGRF14("2020-02-10")._fetch_coefficient_file()) g_date, h_date = interpolate_coefficients( - datetime.datetime( + dt.datetime( year=2023, month=1, day=20, hour=0, minute=1, second=0, tzinfo=tzinfo ), max_degree, @@ -205,10 +205,10 @@ def test_interpolate_coefficients_max_degree(tzinfo): @pytest.mark.parametrize( "date", [ - datetime.datetime(1800, month=1, day=1, tzinfo=UTC), - datetime.datetime(2030, month=1, day=1, tzinfo=UTC), - datetime.datetime(1800, month=1, day=1, tzinfo=None), # ruff: ignore[DTZ001] - datetime.datetime(2030, month=1, day=1, tzinfo=None), # ruff: ignore[DTZ001] + dt.datetime(1800, month=1, day=1, tzinfo=UTC), + dt.datetime(2030, month=1, day=1, tzinfo=UTC), + dt.datetime(1800, month=1, day=1, tzinfo=None), + dt.datetime(2030, month=1, day=1, tzinfo=None), ], ) def test_interpolate_coefficients_invalid_date(date): @@ -254,8 +254,8 @@ def test_igrf_points(data, coordinates): "date", [ "2020-04-15", - datetime.datetime(2029, month=1, day=1, tzinfo=UTC), - datetime.datetime(2029, month=1, day=1, tzinfo=None), # ruff: ignore[DTZ001] + dt.datetime(2029, month=1, day=1, tzinfo=UTC), + dt.datetime(2029, month=1, day=1, tzinfo=None), ], ) def test_igrf_grid(date): @@ -291,10 +291,10 @@ def test_interpolate_coefficients_on_dates_with_timezones(): Test if coefficients are the same on equivalent dates on different timezones. """ # Define the same date on two different timezones - utc = datetime.timezone.utc - pt = datetime.timezone(-datetime.timedelta(hours=7)) # UTC-7 - date_utc = datetime.datetime(year=2020, month=4, day=15, hour=14, tzinfo=utc) - date_pt = datetime.datetime(year=2020, month=4, day=15, hour=14 - 7, tzinfo=pt) + utc = dt.timezone.utc + pt = dt.timezone(-dt.timedelta(hours=7)) # UTC-7 + date_utc = dt.datetime(year=2020, month=4, day=15, hour=14, tzinfo=utc) + date_pt = dt.datetime(year=2020, month=4, day=15, hour=14 - 7, tzinfo=pt) # Compute cofficients for both dates years, g, h, g_sv, h_sv = load_igrf(IGRF14("2020-04-15")._fetch_coefficient_file())