Skip to content
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

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

Merged
merged 7 commits into from
Jan 8, 2025
Merged

Conversation

seisman
Copy link
Member

@seisman seisman commented Jan 7, 2025

Our examples are written as Python scripts but are rendered like Jupyter Notebooks.

In Notebooks, the expression in the last notebook cell will be evaluated and printed as the cell's output, which is commonly used, but ruff complains that the expressions are unused (B018), thus we have to use print instead.

In this PR, the rule B018 is ignored in examples.

Previews:

@seisman seisman added maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog needs review This PR has higher priority and needs review. labels Jan 7, 2025
@seisman seisman added this to the 0.15.0 milestone Jan 7, 2025
@@ -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.

@@ -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.

@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Jan 7, 2025
@seisman seisman merged commit 664a9ed into main Jan 8, 2025
10 checks passed
@seisman seisman deleted the ruff/B018 branch January 8, 2025 13:43
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants