Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__

Expand Down
6 changes: 2 additions & 4 deletions examples/gallery/embellishments/solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""

# %%
import datetime
import datetime as dt

import pygmt

Expand All @@ -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"]:
Expand Down
6 changes: 3 additions & 3 deletions examples/gallery/symbols/datetime_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""

# %%
import datetime
import datetime as dt

import numpy as np
import pandas as pd
Expand All @@ -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)),
)

Expand All @@ -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")

Expand Down
40 changes: 20 additions & 20 deletions examples/tutorials/advanced/date_time_charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""

# %%
import datetime
import datetime as dt

import numpy as np
import pandas as pd
Expand All @@ -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,
Expand All @@ -64,19 +64,19 @@
# 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]

fig = pygmt.Figure()
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,
],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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,
],
Expand Down
4 changes: 2 additions & 2 deletions pygmt/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import contextlib
import datetime
import datetime as dt
import importlib
import os
from collections.abc import Sequence
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pygmt/tests/test_clib_put_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
],
]

Expand Down
22 changes: 11 additions & 11 deletions pygmt/tests/test_clib_to_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
),
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pygmt/tests/test_clib_vectors_to_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]",
),
]
Expand Down
4 changes: 2 additions & 2 deletions pygmt/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test Figure.plot.
"""

import datetime
import datetime as dt
from pathlib import Path

import numpy as np
Expand Down Expand Up @@ -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")

Expand Down
12 changes: 6 additions & 6 deletions pygmt/tests/test_solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test Figure.solar.
"""

import datetime
import datetime as dt

import pytest
from packaging.version import Version
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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",
)
Expand Down
Loading