Skip to content

ruff: Ignore the B018 rule (useless expressions) in examples #3750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion examples/gallery/images/rgb_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Subset to area of Lāhainā in EPSG:32604 coordinates
image = img.rio.clip_box(minx=738000, maxx=755000, miny=2300000, maxy=2318000)
image = image.load() # Force loading the DataArray into memory
image # noqa: B018
image

# %%
# Plot the RGB imagery:
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/lines/linestrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

# Convert object to EPSG 4326 coordinate system
gdf = gdf.to_crs("EPSG:4326")
print(gdf.head())
gdf.head()
Copy link
Member

Choose a reason for hiding this comment

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

Hm. My background off using print was that if running the complete script as "normal" Python script no output is shown, only when running this specific section separately (see comment #3711 (comment)).

Copy link
Member Author

@seisman seisman Jan 7, 2025

Choose a reason for hiding this comment

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

Yes, output the data head information makes little sense when running the example as a normal Python script.

For this example, we have the # %% cell separator at line 30, so the gdf.head information will be shown in the docs.


# %%
fig = pygmt.Figure()
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/maps/choropleth_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# Read the example dataset provided by geodatasets.
gdf = gpd.read_file(geodatasets.get_path("geoda airbnb"))
print(gdf)
gdf
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
gdf
gdf.head()

Copy link
Member

@yvonnefroehlich yvonnefroehlich Jan 7, 2025

Choose a reason for hiding this comment

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

Maybe keep the .head() to show only the first rows, but use it with print. Then the output is adjusted and the wide table fits on the page:

gpd_polyong_ouput

Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestion. Done in 7e2cace.


# %%
fig = pygmt.Figure()
Expand Down
6 changes: 3 additions & 3 deletions examples/tutorials/basics/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
# The data are loaded as a :class:`pandas.DataFrame`.

data = pygmt.datasets.load_sample_data(name="japan_quakes")
data.head()

# %%
# Set the region for the plot to be slightly larger than the data bounds.
region = [
data.longitude.min() - 1,
data.longitude.max() + 1,
data.latitude.min() - 1,
data.latitude.max() + 1,
]

print(region)
print(data.head())
region

# %%
# We'll use the :meth:`pygmt.Figure.plot` method to plot circles on the
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ known-third-party = ["pygmt"]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"] # Ignore `F401` (unused-import) in all `__init__.py` files
"*/tests/test_*.py" = ["S101"] # Ignore `S101` (use of assert) in all tests files
"examples/**/*.py" = ["T201"] # Allow `print` in examples
"examples/**/*.py" = [ # Ignore rules in examples
"B018", # Allow useless expressions in Jupyter Notebooks
"T201", # Allow `print` statements
]

[tool.ruff.lint.pycodestyle]
max-doc-length = 88
Expand Down
Loading