Skip to content

Commit 949274d

Browse files
authored
Merge branch 'main' into to_numpy/pandas_numeric
2 parents bb1cb07 + dff8e77 commit 949274d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+157
-112
lines changed

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dependencies:
2727
# Dev dependencies (style checks)
2828
- codespell
2929
- pre-commit
30-
- ruff>=0.3.0
30+
- ruff>=0.8.0
3131
# Dev dependencies (unit testing)
3232
- matplotlib-base
3333
- pytest>=6.0

pygmt/accessors.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ def registration(self):
138138
@registration.setter
139139
def registration(self, value):
140140
if value not in {0, 1}:
141-
raise GMTInvalidInput(
141+
msg = (
142142
f"Invalid grid registration value: {value}, should be either "
143143
"0 for Gridline registration or 1 for Pixel registration."
144144
)
145+
raise GMTInvalidInput(msg)
145146
self._registration = value
146147

147148
@property
@@ -154,8 +155,9 @@ def gtype(self):
154155
@gtype.setter
155156
def gtype(self, value):
156157
if value not in {0, 1}:
157-
raise GMTInvalidInput(
158+
msg = (
158159
f"Invalid coordinate system type: {value}, should be "
159160
"either 0 for Cartesian or 1 for Geographic."
160161
)
162+
raise GMTInvalidInput(msg)
161163
self._gtype = value

pygmt/clib/loading.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def clib_names(os_name: str) -> list[str]:
118118
case "win32": # Windows
119119
libnames = ["gmt.dll", "gmt_w64.dll", "gmt_w32.dll"]
120120
case _:
121-
raise GMTOSError(f"Operating system '{os_name}' is not supported.")
121+
msg = f"Operating system '{os_name}' is not supported."
122+
raise GMTOSError(msg)
122123
return libnames
123124

124125

pygmt/clib/session.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ def session_pointer(self) -> ctp.c_void_p:
173173
the context manager).
174174
"""
175175
if getattr(self, "_session_pointer", None) is None:
176-
raise GMTCLibNoSessionError("No currently open GMT API session.")
176+
msg = "No currently open GMT API session."
177+
raise GMTCLibNoSessionError(msg)
177178
return self._session_pointer
178179

179180
@session_pointer.setter
@@ -276,7 +277,8 @@ def get_enum(self, name: str) -> int:
276277
session = None
277278
value = c_get_enum(session, name.encode())
278279
if value is None or value == -99999:
279-
raise GMTCLibError(f"Constant '{name}' doesn't exist in libgmt.")
280+
msg = f"Constant '{name}' doesn't exist in libgmt."
281+
raise GMTCLibError(msg)
280282
return value
281283

282284
def get_libgmt_func(
@@ -558,7 +560,8 @@ def get_common(self, option: str) -> bool | int | float | np.ndarray:
558560
pygmt.exceptions.GMTInvalidInput: Unknown GMT common option flag 'A'.
559561
"""
560562
if option not in "BIJRUVXYabfghinoprst:":
561-
raise GMTInvalidInput(f"Unknown GMT common option flag '{option}'.")
563+
msg = f"Unknown GMT common option flag '{option}'."
564+
raise GMTInvalidInput(msg)
562565

563566
c_get_common = self.get_libgmt_func(
564567
"GMT_Get_Common",
@@ -1194,7 +1197,8 @@ def read_data(
11941197
data,
11951198
)
11961199
if data_ptr is None:
1197-
raise GMTCLibError(f"Failed to read dataset from '{infile}'.")
1200+
msg = f"Failed to read dataset from '{infile}'."
1201+
raise GMTCLibError(msg)
11981202
return ctp.cast(data_ptr, ctp.POINTER(dtype))
11991203

12001204
def write_data(self, family, geometry, mode, wesn, output, data):
@@ -1264,7 +1268,8 @@ def write_data(self, family, geometry, mode, wesn, output, data):
12641268
data,
12651269
)
12661270
if status != 0:
1267-
raise GMTCLibError(f"Failed to write dataset to '{output}'")
1271+
msg = f"Failed to write dataset to '{output}'."
1272+
raise GMTCLibError(msg)
12681273

12691274
@contextlib.contextmanager
12701275
def open_virtualfile(
@@ -1856,9 +1861,8 @@ def virtualfile_in(
18561861
elif check_kind == "vector":
18571862
valid_kinds += ("empty", "matrix", "vectors", "geojson")
18581863
if kind not in valid_kinds:
1859-
raise GMTInvalidInput(
1860-
f"Unrecognized data type for {check_kind}: {type(data)}"
1861-
)
1864+
msg = f"Unrecognized data type for {check_kind}: {type(data)}."
1865+
raise GMTInvalidInput(msg)
18621866

18631867
# Decide which virtualfile_from_ function to use
18641868
_virtualfile_from = {
@@ -2110,7 +2114,8 @@ def read_virtualfile(
21102114
if kind is None: # Return the ctypes void pointer
21112115
return pointer
21122116
if kind == "cube":
2113-
raise NotImplementedError(f"kind={kind} is not supported yet.")
2117+
msg = f"kind={kind} is not supported yet."
2118+
raise NotImplementedError(msg)
21142119
dtype = {"dataset": _GMT_DATASET, "grid": _GMT_GRID, "image": _GMT_IMAGE}[kind]
21152120
return ctp.cast(pointer, ctp.POINTER(dtype))
21162121

@@ -2378,5 +2383,6 @@ def extract_region(self) -> np.ndarray:
23782383
region.ctypes.data_as(ctp.POINTER(ctp.c_double)),
23792384
)
23802385
if status != 0:
2381-
raise GMTCLibError("Failed to extract region from current figure.")
2386+
msg = "Failed to extract region from current figure."
2387+
raise GMTCLibError(msg)
23822388
return region

pygmt/datasets/earth_magnetic_anomaly.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,11 @@ def load_earth_magnetic_anomaly(
139139
"wdmam": "earth_wdmam",
140140
}.get(data_source)
141141
if prefix is None:
142-
raise GMTInvalidInput(
142+
msg = (
143143
f"Invalid earth magnetic anomaly data source '{data_source}'. "
144144
"Valid values are 'emag2', 'emag2_4km', and 'wdmam'."
145145
)
146+
raise GMTInvalidInput(msg)
146147
grid = _load_remote_dataset(
147148
name="earth_wdmam" if data_source == "wdmam" else "earth_mag",
148149
prefix=prefix,

pygmt/datasets/earth_relief.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,19 @@ def load_earth_relief(
155155
"synbath": "earth_synbath",
156156
}.get(data_source)
157157
if prefix is None:
158-
raise GMTInvalidInput(
158+
msg = (
159159
f"Invalid earth relief data source '{data_source}'. "
160160
"Valid values are 'igpp', 'gebco', 'gebcosi', and 'synbath'."
161161
)
162+
raise GMTInvalidInput(msg)
162163
# Use SRTM or not.
163164
if use_srtm and resolution in land_only_srtm_resolutions:
164165
if data_source != "igpp":
165-
raise GMTInvalidInput(
166-
f"Option 'use_srtm=True' doesn't work with data source '{data_source}'."
167-
" Please set 'data_source' to 'igpp'."
166+
msg = (
167+
f"Option 'use_srtm=True' doesn't work with data source '{data_source}'. "
168+
"Please set 'data_source' to 'igpp'."
168169
)
170+
raise GMTInvalidInput(msg)
169171
prefix = "srtm_relief"
170172
# Choose earth relief dataset
171173
match data_source:

pygmt/datasets/samples.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,5 +347,6 @@ def load_sample_data(
347347
>>> data = load_sample_data("bathymetry")
348348
""" # noqa: W505
349349
if name not in datasets:
350-
raise GMTInvalidInput(f"Invalid dataset name '{name}'.")
350+
msg = f"Invalid dataset name '{name}'."
351+
raise GMTInvalidInput(msg)
351352
return datasets[name].func()

pygmt/helpers/decorators.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,11 @@ def new_module(*args, **kwargs):
569569
"""
570570
for short_param, long_alias in aliases.items():
571571
if long_alias in kwargs and short_param in kwargs:
572-
raise GMTInvalidInput(
572+
msg = (
573573
f"Parameters in short-form ({short_param}) and "
574574
f"long-form ({long_alias}) can't coexist."
575575
)
576+
raise GMTInvalidInput(msg)
576577
if long_alias in kwargs:
577578
kwargs[short_param] = kwargs.pop(long_alias)
578579
elif short_param in kwargs:
@@ -721,9 +722,8 @@ def kwargs_to_strings(**conversions):
721722

722723
for arg, fmt in conversions.items():
723724
if fmt not in separators:
724-
raise GMTInvalidInput(
725-
f"Invalid conversion type '{fmt}' for argument '{arg}'."
726-
)
725+
msg = f"Invalid conversion type '{fmt}' for argument '{arg}'."
726+
raise GMTInvalidInput(msg)
727727

728728
# Make the actual decorator function
729729
def converter(module_func):
@@ -837,9 +837,8 @@ def new_module(*args, **kwargs):
837837
"""
838838
if oldname in kwargs:
839839
if newname in kwargs:
840-
raise GMTInvalidInput(
841-
f"Can't provide both '{newname}' and '{oldname}'."
842-
)
840+
msg = f"Can't provide both '{newname}' and '{oldname}'."
841+
raise GMTInvalidInput(msg)
843842
msg = (
844843
f"The '{oldname}' parameter has been deprecated since {deprecate_version}"
845844
f" and will be removed in {remove_version}."

pygmt/helpers/tempfile.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,11 @@ def tempfile_from_image(image):
203203
try:
204204
image.rio.to_raster(raster_path=tmpfile.name)
205205
except AttributeError as e: # object has no attribute 'rio'
206-
raise ImportError(
206+
msg = (
207207
"Package `rioxarray` is required to be installed to use this function. "
208208
"Please use `python -m pip install rioxarray` or "
209209
"`mamba install -c conda-forge rioxarray` "
210210
"to install the package."
211-
) from e
211+
)
212+
raise ImportError(msg) from e
212213
yield tmpfile.name

pygmt/helpers/testing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ def wrapper(*args, ext="png", request=None, **kwargs):
112112
else: # Images are not the same
113113
for key in ["actual", "expected", "diff"]:
114114
err[key] = Path(err[key]).relative_to(".")
115-
raise GMTImageComparisonFailure(
115+
msg = (
116116
f"images not close (RMS {err['rms']:.3f}):\n"
117117
f"\t{err['actual']}\n"
118118
f"\t{err['expected']}"
119119
)
120+
raise GMTImageComparisonFailure(msg)
120121
finally:
121122
del fig_ref
122123
del fig_test

0 commit comments

Comments
 (0)