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

Update failing doctests with upstream dataset changes #2988

Merged
merged 9 commits into from
Jan 15, 2024
Merged

Conversation

seisman
Copy link
Member

@seisman seisman commented Jan 11, 2024

Description of proposed changes

Address #2961 (comment).

@seisman
Copy link
Member Author

seisman commented Jan 11, 2024

There are still two failures:

=================================== FAILURES ===================================
_______________ [doctest] pygmt.datasets.tile_map.load_tile_map ________________
105     Raises
106     ------
107     ImportError
108         If ``contextily`` is not installed or can't be imported. Follow
109         :doc:`install instructions for contextily <contextily:index>`, (e.g.
110         via ``python -m pip install contextily``) before using this function.
111 
112     Examples
113     --------
114     >>> import contextily
UNEXPECTED EXCEPTION: ModuleNotFoundError("No module named 'contextily'")
Traceback (most recent call last):
  File "/home/runner/micromamba/envs/pygmt/lib/python3.9/doctest.py", line 1334, in __run
    exec(compile(example.source, filename, "single",
  File "<doctest pygmt.datasets.tile_map.load_tile_map[0]>", line 1, in <module>
ModuleNotFoundError: No module named 'contextily'
/home/runner/work/pygmt/pygmt/pygmt/datasets/tile_map.py:114: UnexpectedException
__________________ [doctest] pygmt.src.grdproject.grdproject ___________________
179 >>> import pygmt
180 >>> # Load a grid of @earth_relief_30m data, with a longitude range of
181 >>> # 10° E to 30° E, and a latitude range of 15° N to 25° N
182 >>> grid = pygmt.datasets.load_earth_relief(
183 ...     resolution="30m", region=[10, 30, 15, 25]
184 ... )
185 >>> # Create a new grid from the input grid, set the projection to
186 >>> # Mercator, and set inverse to "True" to change from "geographic"
187 >>> # to "rectangular"
188 >>> new_grid = pygmt.grdproject(grid=grid, projection="M10c", inverse=True)
Error: TED EXCEPTION: GMTCLibError("Module 'grdproject' failed with status code 72:\ngrdproject [ERROR]: Option -J: If map width is given you must also specify a region with -R")
Traceback (most recent call last):
  File "/home/runner/micromamba/envs/pygmt/lib/python3.9/doctest.py", line 1334, in __run
    exec(compile(example.source, filename, "single",
  File "<doctest pygmt.src.grdproject.grdproject[2]>", line 1, in <module>
  File "/home/runner/work/pygmt/pygmt/pygmt/helpers/decorators.py", line 603, in new_module
    return module_func(*args, **kwargs)
  File "/home/runner/work/pygmt/pygmt/pygmt/helpers/decorators.py", line 776, in new_module
    return module_func(*bound.args, **bound.kwargs)
  File "/home/runner/work/pygmt/pygmt/pygmt/src/grdproject.py", line 122, in grdproject
    lib.call_module(
  File "/home/runner/work/pygmt/pygmt/pygmt/clib/session.py", line 624, in call_module
    raise GMTCLibError(
pygmt.exceptions.GMTCLibError: Module 'grdproject' failed with status code 72:
Error: ect [ERROR]: Option -J: If map width is given you must also specify a region with -R
/home/runner/work/pygmt/pygmt/pygmt/src/grdproject.py:188: UnexpectedException
----------------------------- Captured stderr call -----------------------------
Error: ect [ERROR]: Option -J: If map width is given you must also specify a region with -R

@seisman
Copy link
Member Author

seisman commented Jan 11, 2024

The pygmt.datasets.tile_map.load_tile_map failure is because contextily is an optional dependency and is not installed in the Python 3.9 job run. It also means we can't run full tests in the Tests workflow, but fortunately we can still run them in GMT Legacy Tests and Dev Tests.

The pygmt.src.grdproject.grdproject is likely an upstream bug, reported in GenericMappingTools/gmt#8273.

@seisman seisman changed the title Fix failing inline doctests Update failing doctests with upstream dataset changes Jan 11, 2024
@seisman seisman marked this pull request as ready for review January 11, 2024 14:15
@seisman seisman added maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog labels Jan 11, 2024
@seisman seisman added this to the 0.11.0 milestone Jan 11, 2024
@seisman seisman added the needs review This PR has higher priority and needs review. label Jan 14, 2024
@weiji14
Copy link
Member

weiji14 commented Jan 15, 2024

The pygmt.datasets.tile_map.load_tile_map failure is because contextily is an optional dependency and is not installed in the Python 3.9 job run. It also means we can't run full tests in the Tests workflow, but fortunately we can still run them in GMT Legacy Tests and Dev Tests.

This doctest should be skipped with the __doctest_requires__ = {("load_tile_map"): ["contextily"]} line (see https://github.com/scientific-python/pytest-doctestplus/tree/v1.1.0#doctest-dependencies and #2125 (comment)). I thought we had pytest-doctestplus installed here:

pytest-doctestplus

Is that doctest still being run somehow?

@seisman
Copy link
Member Author

seisman commented Jan 15, 2024

The pygmt.datasets.tile_map.load_tile_map failure is because contextily is an optional dependency and is not installed in the Python 3.9 job run. It also means we can't run full tests in the Tests workflow, but fortunately we can still run them in GMT Legacy Tests and Dev Tests.

This doctest should be skipped with the __doctest_requires__ = {("load_tile_map"): ["contextily"]} line (see https://github.com/scientific-python/pytest-doctestplus/tree/v1.1.0#doctest-dependencies and #2125 (comment)). I thought we had pytest-doctestplus installed here:

pytest-doctestplus

Is that doctest still being run somehow?

The doctest will be skipped only if the --doctest-plus option is given. So, the doctest is skipped for make test but will be run for make fulltest (see

pygmt/Makefile

Line 45 in 621d6da

test: PYTEST_ARGS=--doctest-plus $(PYTEST_COV_ARGS) ${PYTEST_EXTRA}
).

@weiji14
Copy link
Member

weiji14 commented Jan 15, 2024

The doctest will be skipped only if the --doctest-plus option is given. So, the doctest is skipped for make test but will be run for make fulltest (see

pygmt/Makefile

Line 45 in 621d6da

test: PYTEST_ARGS=--doctest-plus $(PYTEST_COV_ARGS) ${PYTEST_EXTRA}

Hmm, you mentioned at #1790 (comment) that we were using --doctest-modules --doctest-plus for make fulltest, but looking at the code, it looks like only --doctest-modules is applied (from pyproject.toml).

It also means we can't run full tests in the Tests workflow, but fortunately we can still run them in GMT Legacy Tests and Dev Tests.

Do we need to run the full tests on GMT Legacy/Dev? The ci_doctests.yaml should cover the doctests, and ci_tests.yaml should cover the non-doctest tests already right?

@seisman
Copy link
Member Author

seisman commented Jan 15, 2024

The doctest will be skipped only if the --doctest-plus option is given. So, the doctest is skipped for make test but will be run for make fulltest (see

pygmt/Makefile

Line 45 in 621d6da

test: PYTEST_ARGS=--doctest-plus $(PYTEST_COV_ARGS) ${PYTEST_EXTRA}

Hmm, you mentioned at #1790 (comment) that we were using --doctest-modules --doctest-plus for make fulltest, but looking at the code, it looks like only --doctest-modules is applied (from pyproject.toml).

Hmm, I think the description in #1790 (comment) is incorrect. make test uses --doctest-modules --doctest-plus and make fulltest uses --doctest-modules. I've updated the comment.

It also means we can't run full tests in the Tests workflow, but fortunately we can still run them in GMT Legacy Tests and Dev Tests.

Do we need to run the full tests on GMT Legacy/Dev? The ci_doctests.yaml should cover the doctests, and ci_tests.yaml should cover the non-doctest tests already right?

You're right, I almost forgot this workflow. I was looking at the checklist at #2843, which only mentions "GMT Legacy" and "GMT Tests" but not "Doctests".

I think we should mention the "DocTests" workflow in both checklists (#2843 and #2961).

@weiji14
Copy link
Member

weiji14 commented Jan 15, 2024

It also means we can't run full tests in the Tests workflow, but fortunately we can still run them in GMT Legacy Tests and Dev Tests.

Do we need to run the full tests on GMT Legacy/Dev? The ci_doctests.yaml should cover the doctests, and ci_tests.yaml should cover the non-doctest tests already right?

You're right, I almost forgot this workflow. I was looking at the checklist at #2843, which only mentions "GMT Legacy" and "GMT Tests" but not "Doctests".

Yeah, could you trigger the "Doctests" workflow in this PR? I did try it locally and it seems to work fine without contextily if you add --doctest-plus here:

pygmt/Makefile

Lines 52 to 54 in 621d6da

# run doctests only
doctest: PYTEST_ARGS=--ignore=../pygmt/tests ${PYTEST_EXTRA}
doctest: _runtest

I think we should mention the "DocTests" workflow in both checklists (#2843 and #2961).

Sounds good.

@weiji14
Copy link
Member

weiji14 commented Jan 15, 2024

Yeah, could you trigger the "Doctests" workflow in this PR? I did try it locally and it seems to work fine without contextily if you add --doctest-plus here:

Owh, but using --doctest-plus only runs 34 tests, compared to 74 doctests if using only --doctest-modules. Maybe don't add that --doctest-plus line to make doctest then, as we agreed on in #1790 (comment).

>>> # Create a new grid from the input grid, set the projection to
>>> # Mercator, and set inverse to "True" to change from "geographic"
>>> # to "rectangular"
>>> new_grid = pygmt.grdproject(grid=grid, projection="M10c", inverse=True)
>>> region = [10, 30, 15, 25]
>>> grid = pygmt.datasets.load_earth_relief(resolution="30m", region=region)
>>> # Project the geographic gridded data onto a rectangular grid
>>> new_grid = pygmt.grdproject(grid=grid, projection="M10c", region=region)
Copy link
Member

Choose a reason for hiding this comment

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

Oh wow, did we write the wrong description before. Default (when inverse=False) should have been "geographic" to "rectangular" 😅

@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 15, 2024
@seisman seisman merged commit ec75e7b into main Jan 15, 2024
12 of 19 checks passed
@seisman seisman deleted the inline-doctests branch January 15, 2024 14:06
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Jan 15, 2024
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.

None yet

2 participants