Skip to content

Mark unit tests with @pytest.mark.benchmark part 2 - #2924

Merged
weiji14 merged 24 commits into
mainfrom
pytest/mark-benchmark-part2
Jan 6, 2024
Merged

Mark unit tests with @pytest.mark.benchmark part 2#2924
weiji14 merged 24 commits into
mainfrom
pytest/mark-benchmark-part2

Conversation

@weiji14

@weiji14weiji14 commented Dec 27, 2023

Copy link
Copy Markdown
Member

Description of proposed changes

Follow-up to #2908, this is where we mark the unit tests for any PyGMT functions we want to benchmark with the @pytest.mark.benchmark decorator.

Benchmark report at https://codspeed.io/GenericMappingTools/pygmt/branches/pytest/mark-benchmark-part2

See #2924 (comment) below on which new tests have been marked for benchmarking. Will prioritize PyGMT functions that use temporary files, and low-level clib functions that should be benchmarked. General discussion on which tests to mark can go in #2910.

Part 2 of addressing #2910. Covers test functions from test_binstats to test_filter1d according to the list in #2910 (comment).

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@weiji14weiji14 added maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog labels Dec 27, 2023
@weiji14weiji14 added this to the 0.11.0 milestone Dec 27, 2023
@weiji14weiji14 self-assigned this Dec 27, 2023
@weiji14weiji14 linked an issue Dec 27, 2023 that may be closed by this pull request
@codspeed-hq

codspeed-hqBot commented Dec 27, 2023

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #2924 will not alter performance

⚠️ No base runs were found

Falling back to comparing pytest/mark-benchmark-part2 (4c1f1e9) with main (8be628e)

Summary

✅ 64 untouched benchmarks

🆕 34 new benchmarks

Benchmarks breakdown

Benchmarkmainpytest/mark-benchmark-part2Change
🆕test_put_matrixN/A125.9 msN/A
🆕test_dataarray_to_matrix_worksN/A10.5 msN/A
🆕test_load_libgmtN/A951.1 µsN/A
🆕test_blockmean_input_xyzN/A412.3 msN/A
🆕test_blockmedian_input_table_matrixN/A603.7 msN/A
🆕test_accessor_set_geographic_cartesian_roundtripN/A928.5 µsN/A
🆕test_virtualfile_from_data_required_z_matrix[Dataset-vector]N/A64.8 msN/A
🆕test_blockmode_input_dataframeN/A621.6 msN/A
🆕test_virtual_fileN/A444.2 msN/A
🆕test_put_matrix_gridN/A331.1 msN/A
🆕test_binstats_no_outgridN/A154 msN/A
🆕test_put_vector_string_dtypeN/A143.4 msN/A
🆕test_call_moduleN/A46.7 msN/A
🆕test_virtualfile_from_vectors_one_string_or_object_column[object]N/A47.2 msN/A
🆕test_virtualfile_from_vectors_one_string_or_object_column[str]N/A47.2 msN/A
🆕test_virtualfile_from_vectorsN/A451.2 msN/A
🆕test_put_stringsN/A14.7 msN/A
🆕test_virtualfile_from_data_required_z_matrix[array-matrix]N/A49.4 msN/A
🆕test_config_format_date_mapN/A233.4 msN/A
🆕test_virtualfile_from_data_required_z_matrix[DataFrame-vector]N/A51.3 msN/A
...............

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Comment on lines +22 to +34
@pytest.mark.benchmark
def test_load_remote_dataset_benchmark_with_region():
"""
Benchmark loading a remote dataset with 'region'.
"""
data = load_remote_dataset_wrapper(resolution="01d", region=[-10, 10, -5, 5])
assert data.name == "seafloor_age"
assert data.attrs["long_name"] == "age of seafloor crust"
assert data.attrs["cpt"] == "@earth_age.cpt"
assert data.attrs["units"] == "Myr"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.gmt.registration == 0
assert data.shape == (11, 21)

@weiji14weiji14Dec 27, 2023

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Instead of benchmarking all the various load_earth_* functions, I just made created a new one that tests the _load_remote_dataset function, and it should cover the refactoring happening at #2917. Note that this test is somewhat duplicating test_earth_age_01d_with_region, but should be ok I hope.

Comment threadpygmt/tests/test_figure.py Outdated
Comment on lines 59 to 62
@pytest.mark.benchmark
def test_figure_repr():
"""
Make sure that figure output's PNG and HTML printable representations look

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Was a little unsure which test to benchmark for figure.py, so I picked this one that tests __repr_png__, since it goes through the savefig and _preview calls.

Comment on lines +183 to 186
@pytest.mark.benchmark
def test_earth_relief_holes():
"""
Check that the @earth_relief_20m_holes.grd dataset loads without errors.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Only benchmarking test_earth_relief_holes since it calls both pygmt.which and pygmt.io.load_dataarray. The other sample datasets call pygmt.which and pd.read_csv only.

@weiji14weiji14 added the needs review This PR has higher priority and needs review. label Jan 6, 2024
@weiji14
weiji14 marked this pull request as ready for review January 6, 2024 09:38
@weiji14
weiji14 enabled auto-merge (squash) January 6, 2024 09:41
@weiji14weiji14 removed the needs review This PR has higher priority and needs review. label Jan 6, 2024
@weiji14
weiji14 disabled auto-merge January 6, 2024 10:47
@weiji14
weiji14 merged commit 1a103ce into mainJan 6, 2024
@weiji14
weiji14 deleted the pytest/mark-benchmark-part2 branch January 6, 2024 10:48
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenanceBoring but important stuff for the core devsskip-changelogSkip adding Pull Request to changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@weiji14@seisman