From a0df42e3149afe09d69a11499dbc0ee07f447474 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sat, 10 Oct 2026 15:45:39 +0800 Subject: [PATCH] Fix ICN001 (flake8-import-conventions) violations in ruff v0.17.0 --- doc/conf.py | 4 +- examples/gallery/embellishments/solar.py | 6 +-- examples/gallery/symbols/datetime_inputs.py | 6 +-- .../tutorials/advanced/date_time_charts.py | 40 +++++++++---------- pygmt/_typing.py | 4 +- pygmt/tests/test_clib_put_vector.py | 4 +- pygmt/tests/test_clib_to_numpy.py | 22 +++++----- pygmt/tests/test_clib_vectors_to_arrays.py | 6 +-- pygmt/tests/test_plot.py | 4 +- pygmt/tests/test_solar.py | 12 +++--- 10 files changed, 53 insertions(+), 55 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index f0dd032e038..25dfb416977 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -4,7 +4,7 @@ Reference: https://www.sphinx-doc.org/en/master/usage/configuration.html """ -import datetime +import datetime as dt import re from docutils import nodes @@ -28,7 +28,7 @@ # Projection information. project = "PyGMT" author = "The PyGMT Developers" -copyright = f"2017-{datetime.date.today().year}, {author}" # ruff: ignore[builtin-variable-shadowing] +copyright = f"2017-{dt.date.today().year}, {author}" # ruff: ignore[builtin-variable-shadowing] version = "dev" if isdev else __version__ release = __version__ diff --git a/examples/gallery/embellishments/solar.py b/examples/gallery/embellishments/solar.py index f19d5b1e023..c9502dba797 100644 --- a/examples/gallery/embellishments/solar.py +++ b/examples/gallery/embellishments/solar.py @@ -10,7 +10,7 @@ """ # %% -import datetime +import datetime as dt import pygmt @@ -21,9 +21,7 @@ fig.coast(land="darkgreen", water="lightblue") # Set a time for the day-night terminator and twilights to 17:00 UTC on January 1, 2000 -reference_time = datetime.datetime( - year=2000, month=1, day=1, hour=17, minute=0, second=0 -) +reference_time = dt.datetime(year=2000, month=1, day=1, hour=17, minute=0, second=0) # Plot the day-night terminator and twilights for terminator in ["day_night", "civil", "nautical", "astronomical"]: diff --git a/examples/gallery/symbols/datetime_inputs.py b/examples/gallery/symbols/datetime_inputs.py index 6d564a6f02a..e7a8580ee8d 100644 --- a/examples/gallery/symbols/datetime_inputs.py +++ b/examples/gallery/symbols/datetime_inputs.py @@ -22,7 +22,7 @@ """ # %% -import datetime +import datetime as dt import numpy as np import pandas as pd @@ -36,7 +36,7 @@ # 0 to 10 on the y-axis fig.basemap( projection="X15c/5c", - region=[datetime.date(2010, 1, 1), datetime.date(2020, 6, 1), 0, 10], + region=[dt.date(2010, 1, 1), dt.date(2020, 6, 1), 0, 10], frame=Frame(axes="WSen", axis=Axis(annot=True, tick=True)), ) @@ -63,7 +63,7 @@ fig.plot(x=x, y=y, style="a0.4c", pen="1p", fill="dodgerblue") # the Python built-in datetime and date -x = [datetime.date(2018, 1, 1), datetime.datetime(2019, 6, 1, 20, 5, 45)] +x = [dt.date(2018, 1, 1), dt.datetime(2019, 6, 1, 20, 5, 45)] y = [6.5, 4.5] fig.plot(x=x, y=y, style="i0.4c", pen="1p", fill="seagreen") diff --git a/examples/tutorials/advanced/date_time_charts.py b/examples/tutorials/advanced/date_time_charts.py index 0f650a5aac3..c65477f2274 100644 --- a/examples/tutorials/advanced/date_time_charts.py +++ b/examples/tutorials/advanced/date_time_charts.py @@ -13,7 +13,7 @@ """ # %% -import datetime +import datetime as dt import numpy as np import pandas as pd @@ -32,17 +32,17 @@ # data points are plotted as circles with a diameter of 0.3 centimeters. x = [ - datetime.date(2010, 6, 1), - datetime.date(2011, 6, 1), - datetime.date(2012, 6, 1), - datetime.date(2013, 6, 1), + dt.date(2010, 6, 1), + dt.date(2011, 6, 1), + dt.date(2012, 6, 1), + dt.date(2013, 6, 1), ] y = [1, 2, 3, 5] fig = pygmt.Figure() fig.plot( projection="X10c/5c", - region=[datetime.date(2010, 1, 1), datetime.date(2014, 12, 1), 0, 6], + region=[dt.date(2010, 1, 1), dt.date(2014, 12, 1), 0, 6], frame=Frame(axes="WSen", axis=Axis(annot=True, tick=True, grid=True)), x=x, y=y, @@ -64,10 +64,10 @@ # the ``style`` parameter x = [ - datetime.datetime(2021, 1, 1, 3, 45, 1), - datetime.datetime(2021, 1, 1, 6, 15, 1), - datetime.datetime(2021, 1, 1, 13, 30, 1), - datetime.datetime(2021, 1, 1, 20, 30, 1), + dt.datetime(2021, 1, 1, 3, 45, 1), + dt.datetime(2021, 1, 1, 6, 15, 1), + dt.datetime(2021, 1, 1, 13, 30, 1), + dt.datetime(2021, 1, 1, 20, 30, 1), ] y = [5, 3, 1, 2] @@ -75,8 +75,8 @@ fig.plot( projection="X10c/5c", region=[ - datetime.datetime(2021, 1, 1, 0, 0, 0), - datetime.datetime(2021, 1, 2, 0, 0, 0), + dt.datetime(2021, 1, 1, 0, 0, 0), + dt.datetime(2021, 1, 2, 0, 0, 0), 0, 6, ], @@ -139,13 +139,13 @@ # different sources, meaning conversions do not need to take place between ISO and # datetime in order to create valid plots. -x = ["2020-02-01", "2020-06-04", "2020-10-04", datetime.datetime(2021, 1, 15)] +x = ["2020-02-01", "2020-06-04", "2020-10-04", dt.datetime(2021, 1, 15)] y = [1.3, 2.2, 4.1, 3] fig = pygmt.Figure() fig.plot( projection="X10c/5c", - region=[datetime.datetime(2020, 1, 1), datetime.datetime(2021, 3, 1), 0, 6], + region=[dt.datetime(2020, 1, 1), dt.datetime(2021, 3, 1), 0, 6], frame=Frame(axes="WSen", axis=Axis(annot=True, tick=True, grid=True)), x=x, y=y, @@ -175,7 +175,7 @@ fig = pygmt.Figure() fig.plot( projection="X10c/10c", - region=[datetime.datetime(2017, 12, 31), datetime.datetime(2019, 12, 31), 0, 10], + region=[dt.datetime(2017, 12, 31), dt.datetime(2019, 12, 31), 0, 10], frame=Frame(axes="WSen", axis=Axis(annot=True, grid=True)), x=x, y=y, @@ -203,7 +203,7 @@ fig = pygmt.Figure() fig.plot( projection="X10c/10c", - region=[datetime.datetime(2020, 1, 1), datetime.datetime(2021, 4, 1), 0, 10], + region=[dt.datetime(2020, 1, 1), dt.datetime(2021, 4, 1), 0, 10], frame=Frame(axes="WSen", axis=Axis(annot=True, grid=True)), x=x, y=y, @@ -231,7 +231,7 @@ fig = pygmt.Figure() fig.plot( projection="X10c/10c", - region=[datetime.datetime(2010, 1, 1), datetime.datetime(2012, 6, 1), 0, 10], + region=[dt.datetime(2010, 1, 1), dt.datetime(2012, 6, 1), 0, 10], frame=Frame(axes="WS", axis=Axis(annot=True, grid=True)), x=x, y=y, @@ -308,7 +308,7 @@ with pygmt.config(FORMAT_DATE_MAP="o"): fig.plot( projection="X15c/10c", - region=[datetime.datetime(2013, 5, 1), datetime.datetime(2013, 5, 25), 0, 10], + region=[dt.datetime(2013, 5, 1), dt.datetime(2013, 5, 25), 0, 10], frame=Frame( axes="WS", xaxis=Axis(annot="5d"), @@ -345,8 +345,8 @@ fig.plot( projection="X15c/10c", region=[ - datetime.datetime(2021, 4, 14, 23, 0, 0), - datetime.datetime(2021, 4, 17), + dt.datetime(2021, 4, 14, 23, 0, 0), + dt.datetime(2021, 4, 17), 0, 10, ], diff --git a/pygmt/_typing.py b/pygmt/_typing.py index 7e9cd0617f7..849d1ae5d1a 100644 --- a/pygmt/_typing.py +++ b/pygmt/_typing.py @@ -3,7 +3,7 @@ """ import contextlib -import datetime +import datetime as dt import importlib import os from collections.abc import Sequence @@ -17,7 +17,7 @@ AnchorCode = Literal["TL", "TC", "TR", "ML", "MC", "MR", "BL", "BC", "BR"] # Datetime-like scalars accepted by pandas.to_datetime. -DatetimeLike = str | datetime.date | datetime.datetime | np.datetime64 | pd.Timestamp +DatetimeLike = str | dt.date | dt.datetime | np.datetime64 | pd.Timestamp # String array types StringArrayTypes = Sequence[str] | np.ndarray diff --git a/pygmt/tests/test_clib_put_vector.py b/pygmt/tests/test_clib_put_vector.py index f48f4ef80d9..999a7e02f34 100644 --- a/pygmt/tests/test_clib_put_vector.py +++ b/pygmt/tests/test_clib_put_vector.py @@ -2,7 +2,7 @@ Test the functions that put vector data into GMT. """ -import datetime +import datetime as dt import itertools import numpy as np @@ -126,7 +126,7 @@ def test_put_vector_string_dtype(): "2021-02-03T00:00:00", "2021-02-03T04:00:00", "2021-02-03T04:05:06", - f"{datetime.datetime.now(tz=datetime.UTC).strftime('%Y-%m-%d')}T04:50:06", + f"{dt.datetime.now(tz=dt.UTC).strftime('%Y-%m-%d')}T04:50:06", ], ] diff --git a/pygmt/tests/test_clib_to_numpy.py b/pygmt/tests/test_clib_to_numpy.py index a50a45356c0..f7f003c5a2d 100644 --- a/pygmt/tests/test_clib_to_numpy.py +++ b/pygmt/tests/test_clib_to_numpy.py @@ -2,7 +2,7 @@ Tests for the _to_numpy function in the clib.conversion module. """ -import datetime +import datetime as dt import numpy as np import numpy.testing as npt @@ -75,10 +75,10 @@ def test_to_numpy_python_types(data, expected_dtype): [ pytest.param( [ - datetime.date(2018, 1, 1), - datetime.datetime(2018, 2, 1), - datetime.date(2018, 3, 1), - datetime.datetime(2018, 4, 1, 1, 2, 3), + dt.date(2018, 1, 1), + dt.datetime(2018, 2, 1), + dt.date(2018, 3, 1), + dt.datetime(2018, 4, 1, 1, 2, 3), ], id="datetime", ), @@ -104,7 +104,7 @@ def test_to_numpy_python_types(data, expected_dtype): [ "2018-01-01", np.datetime64("2018-02-01"), - datetime.datetime(2018, 3, 1), + dt.datetime(2018, 3, 1), pd.Timestamp("2018-04-01T01:02:03"), ], id="mixed", @@ -629,9 +629,9 @@ def test_to_numpy_pyarrow_date(dtype, expected_dtype): Here we explicitly check the dtype and date unit of the result. """ data = [ - datetime.date(2024, 1, 1), - datetime.datetime(2024, 1, 2), - datetime.datetime(2024, 1, 3), + dt.date(2024, 1, 1), + dt.datetime(2024, 1, 2), + dt.datetime(2024, 1, 3), ] array = pa.array(data, type=dtype) result = _to_numpy(array) @@ -676,8 +676,8 @@ def test_to_numpy_pyarrow_timestamp(dtype, expected_dtype): Reference: https://arrow.apache.org/docs/python/generated/pyarrow.timestamp.html """ data = [ - datetime.datetime(2024, 1, 2, 3, 4, 5), - datetime.datetime(2024, 1, 2, 3, 4, 6), + dt.datetime(2024, 1, 2, 3, 4, 5), + dt.datetime(2024, 1, 2, 3, 4, 6), ] array = pa.array(data, type=dtype) result = _to_numpy(array) diff --git a/pygmt/tests/test_clib_vectors_to_arrays.py b/pygmt/tests/test_clib_vectors_to_arrays.py index f99a3dcd480..801018f8bc7 100644 --- a/pygmt/tests/test_clib_vectors_to_arrays.py +++ b/pygmt/tests/test_clib_vectors_to_arrays.py @@ -2,7 +2,7 @@ Test the vectors_to_arrays function in the clib.conversion module. """ -import datetime +import datetime as dt import importlib.util import numpy as np @@ -77,11 +77,11 @@ def test_vectors_to_arrays_pyarrow_datetime(): """ vectors = [ pd.Series( - data=[datetime.date(2020, 1, 1), datetime.date(2021, 12, 31)], + data=[dt.date(2020, 1, 1), dt.date(2021, 12, 31)], dtype="date32[day][pyarrow]", ), pd.Series( - data=[datetime.date(2022, 1, 1), datetime.date(2023, 12, 31)], + data=[dt.date(2022, 1, 1), dt.date(2023, 12, 31)], dtype="date64[ms][pyarrow]", ), ] diff --git a/pygmt/tests/test_plot.py b/pygmt/tests/test_plot.py index 11a8e59a663..b8f796f8445 100644 --- a/pygmt/tests/test_plot.py +++ b/pygmt/tests/test_plot.py @@ -2,7 +2,7 @@ Test Figure.plot. """ -import datetime +import datetime as dt from pathlib import Path import numpy as np @@ -482,7 +482,7 @@ def test_plot_datetime(): fig.plot(x=x, y=y, style="a0.2c", pen="1p") # the Python built-in datetime and date - x = [datetime.date(2018, 1, 1), datetime.datetime(2019, 1, 1, 0, 0, 0)] + x = [dt.date(2018, 1, 1), dt.datetime(2019, 1, 1, 0, 0, 0)] y = [8.5, 9.5] fig.plot(x=x, y=y, style="i0.2c", pen="1p") diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 447f7b12b76..644cd2803c1 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -2,7 +2,7 @@ Test Figure.solar. """ -import datetime +import datetime as dt import pytest from packaging.version import Version @@ -39,7 +39,7 @@ def test_solar_terminators(): "terminator_datetime", [ pytest.param("1990-02-17 04:25:00", id="terminator_datetime_string"), - datetime.datetime(year=1990, month=2, day=17, hour=4, minute=25, second=0), + dt.datetime(year=1990, month=2, day=17, hour=4, minute=25, second=0), ], ) def test_solar_set_terminator_datetime(terminator_datetime): @@ -104,14 +104,14 @@ def test_solar_terminator_datetime_timezone(): fig.solar(terminator_datetime="2020-01-01T01:02:03+01:00", pen="1p,red") fig.solar(terminator_datetime="2020-01-01T01:02:03-01:00", pen="1p,blue") fig.solar( - terminator_datetime=datetime.datetime( - 2020, 1, 1, 1, 2, 3, tzinfo=datetime.timezone(datetime.timedelta(hours=2)) + terminator_datetime=dt.datetime( + 2020, 1, 1, 1, 2, 3, tzinfo=dt.timezone(dt.timedelta(hours=2)) ), pen="1p,lightred", ) fig.solar( - terminator_datetime=datetime.datetime( - 2020, 1, 1, 1, 2, 3, tzinfo=datetime.timezone(datetime.timedelta(hours=-2)) + terminator_datetime=dt.datetime( + 2020, 1, 1, 1, 2, 3, tzinfo=dt.timezone(dt.timedelta(hours=-2)) ), pen="1p,lightblue", )