Skip to content

Commit d890e91

Browse files
authored
Use TODO comments to track deprecations and workarounds (#3722)
1 parent e5efc91 commit d890e91

17 files changed

+42
-13
lines changed

pygmt/clib/conversion.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,11 @@ def _to_numpy(data: Any) -> np.ndarray:
173173
# The numpy dtype for the result numpy array, but can be None.
174174
numpy_dtype = dtypes.get(str(dtype))
175175

176+
# TODO(pandas>=2.2): Remove the workaround for pandas<2.2.
177+
#
176178
# pandas numeric dtypes were converted to np.object_ dtype prior pandas 2.2, and are
177179
# converted to suitable NumPy dtypes since pandas 2.2. Refer to the following link
178180
# for details: https://pandas.pydata.org/docs/whatsnew/v2.2.0.html#to-numpy-for-numpy-nullable-and-arrow-types-converts-to-suitable-numpy-dtype
179-
#
180-
# Workarounds for pandas < 2.2. Following SPEC 0, pandas 2.1 should be dropped in
181-
# 2025 Q3, so it's likely we can remove the workaround in PyGMT v0.17.0.
182181
if (
183182
Version(pd.__version__) < Version("2.2") # pandas < 2.2 only.
184183
and hasattr(data, "dtype") # NumPy array or pandas objects only.

pygmt/clib/session.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ def print_func(file_pointer, message): # noqa: ARG001
384384
We'll capture the messages and print them to stderr so that they will show
385385
up on the Jupyter notebook.
386386
"""
387-
# Have to use try..except due to upstream GMT bug in GMT <= 6.5.0.
387+
# TODO(GMT>6.5.0): Remove the workaround for upstream bug in GMT<=6.5.0.
388+
# Have to use try..except due to upstream GMT bug in GMT<=6.5.0.
388389
# See https://github.com/GenericMappingTools/pygmt/issues/3205.
389390
try:
390391
message = message.decode().strip()
@@ -1388,6 +1389,7 @@ def open_virtualfile(
13881389
msg = f"Failed to close virtual file '{vfname}'."
13891390
raise GMTCLibError(msg)
13901391

1392+
# TODO(PyGMT>=0.15.0): Remove the deprecated open_virtual_file method.
13911393
def open_virtual_file(self, family, geometry, direction, data):
13921394
"""
13931395
Open a GMT virtual file associated with a data object for reading or writing.
@@ -1454,9 +1456,9 @@ def virtualfile_from_vectors(
14541456
... print(fout.read().strip())
14551457
<vector memory>: N = 3 <1/3> <4/6> <7/9>
14561458
"""
1459+
# TODO(PyGMT>=0.16.0): Remove the "*args" parameter and related codes.
14571460
# "*args" is added in v0.14.0 for backward-compatibility with the deprecated
14581461
# syntax of passing multiple vectors as positional arguments.
1459-
# Remove it in v0.16.0.
14601462
if len(args) > 0:
14611463
msg = (
14621464
"Passing multiple arguments to Session.virtualfile_from_vectors is "
@@ -1918,6 +1920,7 @@ def virtualfile_in(
19181920
file_context = _virtualfile_from(_data)
19191921
return file_context
19201922

1923+
# TODO(PyGMT>=0.15.0): Remove the deprecated virtualfile_from_data method.
19211924
def virtualfile_from_data(
19221925
self,
19231926
check_kind=None,

pygmt/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66
from packaging.version import Version
77

8-
# Keep this until we require numpy to be >=2.0
8+
# TODO(NumPy>=2.0): Remove the conftest.py file.
99
# Address https://github.com/GenericMappingTools/pygmt/issues/2628.
1010
if Version(np.__version__) >= Version("2.0.0.dev0+git20230726"):
1111
np.set_printoptions(legacy="1.25") # type: ignore[arg-type]

pygmt/datasets/tile_map.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def load_tile_map(
166166
"wait": wait,
167167
"max_retries": max_retries,
168168
}
169+
# TODO(contextily>=1.5.0): Remove the check for the 'zoom_adjust' parameter.
169170
if zoom_adjust is not None:
170171
if Version(contextily.__version__) < Version("1.5.0"):
171172
msg = (

pygmt/figure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def savefig(
248248
kwargs.pop("metadata", None)
249249
self.psconvert(prefix=prefix, fmt=fmts[ext], crop=crop, **kwargs)
250250

251+
# TODO(GMT>=6.5.0): Remve the workaround for upstream bug in GMT<6.5.0.
251252
# Remove the .pgw world file if exists. Not necessary after GMT 6.5.0.
252253
# See upstream fix https://github.com/GenericMappingTools/gmt/pull/7865
253254
if ext == "tiff":

pygmt/helpers/tempfile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ def tempfile_from_geojson(geojson):
144144
# https://github.com/geopandas/geopandas/issues/967#issuecomment-842877704
145145
# https://github.com/GenericMappingTools/pygmt/issues/2497
146146
int32_info = np.iinfo(np.int32)
147+
# TODO(GeoPandas>=1.0): Remove the workaround for GeoPandas < 1.
148+
# The default engine is "fiona" in v0.x and "pyogrio" in v1.x.
147149
if Version(gpd.__version__).major < 1: # GeoPandas v0.x
148150
# The default engine 'fiona' supports the 'schema' parameter.
149151
if geojson.index.name is None:

pygmt/src/ternary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def ternary(
8787
if any(v is not None for v in labels):
8888
kwargs["L"] = "/".join(str(v) if v is not None else "-" for v in labels)
8989

90-
# Patch for GMT < 6.5.0.
90+
# TODO(GMT>=6.5.0): Remove the patch for upstream bug fixed in GMT 6.5.0.
9191
# See https://github.com/GenericMappingTools/pygmt/pull/2138
9292
if Version(__gmt_version__) < Version("6.5.0") and isinstance(data, pd.DataFrame):
9393
data = data.to_numpy()

pygmt/src/timestamp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def timestamp(
8484
kwdict["U"] += f"{label}"
8585
kwdict["U"] += f"+j{justify}"
8686

87+
# TODO(GMT>=6.5.0): Remove the patch for upstream bug fixed in GMT 6.5.0.
8788
if Version(__gmt_version__) < Version("6.5.0") and "/" not in str(offset):
8889
# Giving a single offset doesn't work in GMT < 6.5.0.
8990
# See https://github.com/GenericMappingTools/gmt/issues/7107.
@@ -99,6 +100,7 @@ def timestamp(
99100
"The given text string will be truncated to 64 characters."
100101
)
101102
warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2)
103+
# TODO(GMT>=6.5.0): Remove the workaround for the new '+t' modifier.
102104
if Version(__gmt_version__) < Version("6.5.0"):
103105
# Workaround for GMT<6.5.0 by overriding the 'timefmt' parameter
104106
timefmt = text[:64]

pygmt/tests/test_accessor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def test_accessor_set_non_boolean():
7373
grid.gmt.gtype = 2
7474

7575

76+
# TODO(GMT>=6.5.0): Remove the xfail marker for GMT>=6.5.0.
7677
@pytest.mark.xfail(
7778
condition=sys.platform == "win32" and Version(__gmt_version__) < Version("6.5.0"),
7879
reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/7573",

pygmt/tests/test_clib_to_numpy.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def _check_result(result, expected_dtype):
5454
@pytest.mark.parametrize(
5555
("data", "expected_dtype"),
5656
[
57+
# TODO(NumPy>=2.0): Remove the if-else statement after NumPy>=2.0.
5758
pytest.param(
5859
[1, 2, 3],
5960
np.int32
@@ -218,9 +219,10 @@ def test_to_numpy_pandas_numeric(dtype, expected_dtype):
218219
Test the _to_numpy function with pandas.Series of numeric dtypes.
219220
"""
220221
data = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
222+
# TODO(pandas>=2.2): Remove the workaround for float16 dtype in pandas<2.2.
223+
# float16 needs special handling for pandas < 2.2.
224+
# Example from https://arrow.apache.org/docs/python/generated/pyarrow.float16.html
221225
if dtype == "float16[pyarrow]" and Version(pd.__version__) < Version("2.2"):
222-
# float16 needs special handling for pandas < 2.2.
223-
# Example from https://arrow.apache.org/docs/python/generated/pyarrow.float16.html
224226
data = np.array(data, dtype=np.float16)
225227
series = pd.Series(data, dtype=dtype)[::2] # Not C-contiguous
226228
result = _to_numpy(series)
@@ -264,9 +266,10 @@ def test_to_numpy_pandas_numeric_with_na(dtype, expected_dtype):
264266
dtypes and missing values (NA).
265267
"""
266268
data = [1.0, 2.0, None, 4.0, 5.0, 6.0]
269+
# TODO(pandas>=2.2): Remove the workaround for float16 dtype in pandas<2.2.
270+
# float16 needs special handling for pandas < 2.2.
271+
# Example from https://arrow.apache.org/docs/python/generated/pyarrow.float16.html
267272
if dtype == "float16[pyarrow]" and Version(pd.__version__) < Version("2.2"):
268-
# float16 needs special handling for pandas < 2.2.
269-
# Example from https://arrow.apache.org/docs/python/generated/pyarrow.float16.html
270273
data = np.array(data, dtype=np.float16)
271274
series = pd.Series(data, dtype=dtype)[::2] # Not C-contiguous
272275
assert series.isna().any()
@@ -287,6 +290,7 @@ def test_to_numpy_pandas_numeric_with_na(dtype, expected_dtype):
287290
"string[pyarrow_numpy]",
288291
marks=[
289292
skip_if_no(package="pyarrow"),
293+
# TODO(pandas>=2.1): Remove the skipif marker for pandas<2.1.
290294
pytest.mark.skipif(
291295
Version(pd.__version__) < Version("2.1"),
292296
reason="string[pyarrow_numpy] was added since pandas 2.1",
@@ -426,6 +430,7 @@ def test_to_numpy_pyarrow_numeric_with_na(dtype, expected_dtype):
426430
"large_utf8", # alias for large_string
427431
pytest.param(
428432
"string_view",
433+
# TODO(pyarrow>=16): Remove the skipif marker for pyarrow<16.
429434
marks=pytest.mark.skipif(
430435
Version(pa.__version__) < Version("16"),
431436
reason="string_view type was added since pyarrow 16",

0 commit comments

Comments
 (0)