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 pygmt/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def registration(self):

@registration.setter
def registration(self, value):
if value not in (0, 1):
if value not in {0, 1}:
raise GMTInvalidInput(
f"Invalid grid registration value: {value}, should be either "
"0 for Gridline registration or 1 for Pixel registration."
Expand All @@ -157,7 +157,7 @@ def gtype(self):

@gtype.setter
def gtype(self, value):
if value not in (0, 1):
if value not in {0, 1}:
raise GMTInvalidInput(
f"Invalid coordinate system type: {value}, should be "
"either 0 for Cartesian or 1 for Geographic."
Expand Down
6 changes: 3 additions & 3 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ def put_vector(self, dataset, column, vector):
)

gmt_type = self._check_dtype_and_dim(vector, ndim=1)
if gmt_type in (self["GMT_TEXT"], self["GMT_DATETIME"]):
if gmt_type in {self["GMT_TEXT"], self["GMT_DATETIME"]}:
if gmt_type == self["GMT_DATETIME"]:
vector = np.datetime_as_string(array_to_datetime(vector))
vector_pointer = strings_to_ctypes_array(vector)
Expand Down Expand Up @@ -1622,7 +1622,7 @@ def virtualfile_in( # noqa: PLR0912
}[kind]

# Ensure the data is an iterable (Python list or tuple)
if kind in ("geojson", "grid", "image", "file", "arg"):
if kind in {"geojson", "grid", "image", "file", "arg"}:
if kind == "image" and data.dtype != "uint8":
msg = (
f"Input image has dtype: {data.dtype} which is unsupported, "
Expand Down Expand Up @@ -1849,7 +1849,7 @@ def read_virtualfile(
# _GMT_DATASET).
if kind is None: # Return the ctypes void pointer
return pointer
if kind in ["image", "cube"]:
if kind in {"image", "cube"}:
raise NotImplementedError(f"kind={kind} is not supported yet.")
dtype = {"dataset": _GMT_DATASET, "grid": _GMT_GRID}[kind]
return ctp.cast(pointer, ctp.POINTER(dtype))
Expand Down
2 changes: 1 addition & 1 deletion pygmt/datasets/load_remote_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def _load_remote_dataset(
if registration is None:
# Use gridline registration unless only pixel registration is available
registration = "gridline" if "gridline" in resinfo.registrations else "pixel"
elif registration in ("pixel", "gridline"):
elif registration in {"pixel", "gridline"}:
if registration not in resinfo.registrations:
raise GMTInvalidInput(
f"{registration} registration is not available for the "
Expand Down
8 changes: 4 additions & 4 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def psconvert(self, **kwargs):
kwargs["A"] = ""

prefix = kwargs.get("F")
if prefix in ["", None, False, True]:
if prefix in {"", None, False, True}:
raise GMTInvalidInput(
"The 'prefix' parameter must be specified with a valid value."
)
Expand Down Expand Up @@ -363,7 +363,7 @@ def savefig( # noqa: PLR0912
kwargs["Qg"] = 2

if worldfile:
if ext in ["eps", "kml", "pdf", "tiff"]:
if ext in {"eps", "kml", "pdf", "tiff"}:
raise GMTInvalidInput(
f"Saving a world file is not supported for '{ext}' format."
)
Expand Down Expand Up @@ -444,7 +444,7 @@ def show(self, dpi=300, width=500, method=None, waiting=0.5, **kwargs):
if method is None:
method = SHOW_CONFIG["method"]

if method not in ["external", "notebook", "none"]:
if method not in {"external", "notebook", "none"}:
raise GMTInvalidInput(
f"Invalid display method '{method}', "
"should be either 'notebook', 'external', or 'none'."
Expand Down Expand Up @@ -583,7 +583,7 @@ def set_display(method=None):
>>> pygmt.set_display(method=None)
>>> fig.show() # again, will show a PNG image in the current notebook
"""
if method in ["notebook", "external", "none"]:
if method in {"notebook", "external", "none"}:
SHOW_CONFIG["method"] = method
elif method is not None:
raise GMTInvalidInput(
Expand Down
4 changes: 2 additions & 2 deletions pygmt/helpers/tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ def tempfile_from_geojson(geojson):
geojson = geojson.reset_index(drop=False)
schema = gpd.io.file.infer_schema(geojson)
for col, dtype in schema["properties"].items():
if dtype in ("int", "int64"):
if dtype in {"int", "int64"}:
overflow = geojson[col].abs().max() > 2**31 - 1
schema["properties"][col] = "float" if overflow else "int32"
ogrgmt_kwargs["schema"] = schema
else: # GeoPandas v1.x.
# The default engine "pyogrio" doesn't support the 'schema' parameter
# but we can change the dtype directly.
for col in geojson.columns:
if geojson[col].dtype in ("int", "int64", "Int64"):
if geojson[col].dtype.name in {"int", "int64", "Int64"}:
overflow = geojson[col].abs().max() > 2**31 - 1
dtype = "float" if overflow else "int32"
geojson[col] = geojson[col].astype(dtype)
Expand Down
2 changes: 1 addition & 1 deletion pygmt/helpers/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def validate_output_table_type(
... assert len(w) == 1
'file'
"""
if output_type not in ["file", "numpy", "pandas"]:
if output_type not in {"file", "numpy", "pandas"}:
raise GMTInvalidInput(
"Must specify 'output_type' either as 'file', 'numpy', or 'pandas'."
)
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/meca.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def convention_code(convention, component="full"):
f"Invalid component '{component}' for convention '{convention}'."
)
return codes2[convention][component]
if convention in ["a", "c", "m", "d", "z", "p", "x", "y", "t"]:
if convention in {"a", "c", "m", "d", "z", "p", "x", "y", "t"}:
return convention
raise GMTInvalidInput(f"Invalid convention '{convention}'.")

Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/tilemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def tilemap(

# Only set region if no_clip is None or False, so that plot is clipped to exact
# bounding box region
if kwargs.get("N") in [None, False]:
if kwargs.get("N") in {None, False}:
kwargs["R"] = "/".join(str(coordinate) for coordinate in region)

with Session() as lib:
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def test_get_default():
Make sure get_default works without crashing and gives reasonable results.
"""
with clib.Session() as lib:
assert lib.get_default("API_GRID_LAYOUT") in ["rows", "columns"]
assert lib.get_default("API_GRID_LAYOUT") in {"rows", "columns"}
assert int(lib.get_default("API_CORES")) >= 1
assert Version(lib.get_default("API_VERSION")) >= Version("6.3.0")
assert lib.get_default("PROJ_LENGTH_UNIT") == "cm"
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_clib_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _mock_ctypes_cdll_return(self, libname):
# libname is a loaded GMT library
return self.loaded_libgmt

@pytest.fixture()
@pytest.fixture
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this change is to fix a PT001 rule violation that was triggered because of the preview mode setting. In non-preview mode, @pytest.fixture() is valid, but in preview mode, @pytest.fixture() is valid. See https://docs.astral.sh/ruff/rules/pytest-fixture-incorrect-parentheses-style/ and astral-sh/ruff#12106.

def _mock_ctypes(self, monkeypatch):
"""
Patch the ctypes.CDLL function.
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ select = [
"YTT", # flake8-2020
]
extend-select = [
"D213", # Summary lines should be positioned on the second physical line of the docstring.
"D410", # A blank line after section headings.
"D213", # Summary lines should be positioned on the second physical line of the docstring.
"D410", # A blank line after section headings.
"PLR6201", # Use a set literal when testing for membership
]
ignore = [
"D200", # One-line docstring should fit on one line
Expand All @@ -140,6 +141,8 @@ ignore = [
"S603", # Allow method calls that initiate a subprocess without a shell
"SIM117", # Allow nested `with` statements
]
preview = true
explicit-preview-rules = true

[tool.ruff.lint.isort]
known-third-party = ["pygmt"]
Expand Down