diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index da451553c82..76ff9f9401a 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -61,7 +61,7 @@ jobs: echo $CONDA/bin >> $GITHUB_PATH conda install --solver=libmamba gmt=6.4.0 python=3.12 \ numpy pandas xarray netCDF4 packaging \ - geopandas pytest pytest-mpl + geopandas pyarrow pytest pytest-mpl python -m pip install -U pytest-codspeed setuptools # Download cached remote files (artifacts) from GitHub diff --git a/pygmt/tests/test_accessor.py b/pygmt/tests/test_accessor.py index fbaee96a520..6ba6c58b122 100644 --- a/pygmt/tests/test_accessor.py +++ b/pygmt/tests/test_accessor.py @@ -46,6 +46,7 @@ def test_accessor_set_pixel_registration(): assert grid.gmt.registration == 1 # ensure changed to pixel registration +@pytest.mark.benchmark def test_accessor_set_geographic_cartesian_roundtrip(): """ Check that we can set a grid to switch between the default Cartesian coordinate type diff --git a/pygmt/tests/test_binstats.py b/pygmt/tests/test_binstats.py index 65daa4fe70a..4815b9e6d5c 100644 --- a/pygmt/tests/test_binstats.py +++ b/pygmt/tests/test_binstats.py @@ -4,6 +4,7 @@ from pathlib import Path import numpy.testing as npt +import pytest from pygmt import binstats from pygmt.helpers import GMTTempFile @@ -26,6 +27,7 @@ def test_binstats_outgrid(): assert Path(tmpfile.name).stat().st_size > 0 # check that outgrid exists +@pytest.mark.benchmark def test_binstats_no_outgrid(): """ Test binstats with no set outgrid. diff --git a/pygmt/tests/test_blockm.py b/pygmt/tests/test_blockm.py index 89516bce06a..f8bea4ac1f5 100644 --- a/pygmt/tests/test_blockm.py +++ b/pygmt/tests/test_blockm.py @@ -45,6 +45,7 @@ def test_blockmean_input_table_matrix(array_func, dataframe): npt.assert_allclose(output.iloc[0], [245.888877, 29.978707, -384.0]) +@pytest.mark.benchmark def test_blockmean_input_xyz(dataframe): """ Run blockmean by passing in x/y/z as input. @@ -99,6 +100,7 @@ def test_blockmean_without_outfile_setting(): npt.assert_allclose(output.iloc[0], [245.888877, 29.978707, -384.0]) +@pytest.mark.benchmark def test_blockmode_input_dataframe(dataframe): """ Run blockmode by passing in a pandas.DataFrame as input. diff --git a/pygmt/tests/test_blockmedian.py b/pygmt/tests/test_blockmedian.py index afe53b583a6..c46770db077 100644 --- a/pygmt/tests/test_blockmedian.py +++ b/pygmt/tests/test_blockmedian.py @@ -31,6 +31,7 @@ def test_blockmedian_input_dataframe(dataframe): npt.assert_allclose(output.iloc[0], [245.88819, 29.97895, -385.0]) +@pytest.mark.benchmark def test_blockmedian_input_table_matrix(dataframe): """ Run blockmedian using table input that is not a pandas.DataFrame but still a matrix. diff --git a/pygmt/tests/test_clib.py b/pygmt/tests/test_clib.py index da127554790..ffb7a6bde41 100644 --- a/pygmt/tests/test_clib.py +++ b/pygmt/tests/test_clib.py @@ -130,6 +130,7 @@ def test_destroy_session_fails(): ses.destroy() +@pytest.mark.benchmark def test_call_module(): """ Run a command to see if call_module works. @@ -388,6 +389,7 @@ def test_write_data_fails(): ) +@pytest.mark.benchmark def test_dataarray_to_matrix_works(): """ Check that dataarray_to_matrix returns correct output. diff --git a/pygmt/tests/test_clib_loading.py b/pygmt/tests/test_clib_loading.py index 513523917b3..a6bd9541c06 100644 --- a/pygmt/tests/test_clib_loading.py +++ b/pygmt/tests/test_clib_loading.py @@ -62,6 +62,7 @@ def test_clib_names(): ############################################################################### # Test load_libgmt +@pytest.mark.benchmark def test_load_libgmt(): """ Test that loading libgmt works and doesn't crash. diff --git a/pygmt/tests/test_clib_put_matrix.py b/pygmt/tests/test_clib_put_matrix.py index dd288aacd13..dd50050edb9 100644 --- a/pygmt/tests/test_clib_put_matrix.py +++ b/pygmt/tests/test_clib_put_matrix.py @@ -19,6 +19,7 @@ def fixture_dtypes(): return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split() +@pytest.mark.benchmark def test_put_matrix(dtypes): """ Check that assigning a numpy 2-D array to a dataset works. @@ -64,6 +65,7 @@ def test_put_matrix_fails(): lib.put_matrix(dataset=None, matrix=np.empty((10, 2)), pad=0) +@pytest.mark.benchmark def test_put_matrix_grid(dtypes): """ Check that assigning a numpy 2-D array to an ASCII and netCDF grid works. diff --git a/pygmt/tests/test_clib_put_strings.py b/pygmt/tests/test_clib_put_strings.py index a37ca3affe6..8aad6abbffd 100644 --- a/pygmt/tests/test_clib_put_strings.py +++ b/pygmt/tests/test_clib_put_strings.py @@ -9,6 +9,7 @@ from pygmt.helpers import GMTTempFile +@pytest.mark.benchmark def test_put_strings(): """ Check that assigning a numpy array of dtype str to a dataset works. diff --git a/pygmt/tests/test_clib_put_vector.py b/pygmt/tests/test_clib_put_vector.py index 09a4235298b..bbaf0aced65 100644 --- a/pygmt/tests/test_clib_put_vector.py +++ b/pygmt/tests/test_clib_put_vector.py @@ -20,6 +20,7 @@ def fixture_dtypes(): return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split() +@pytest.mark.benchmark def test_put_vector(dtypes): """ Check that assigning a numpy array to a dataset works. @@ -97,6 +98,7 @@ def test_put_vector_mixed_dtypes(dtypes): npt.assert_allclose(newy, y) +@pytest.mark.benchmark def test_put_vector_string_dtype(): """ Passing string type vectors to a dataset. diff --git a/pygmt/tests/test_clib_virtualfiles.py b/pygmt/tests/test_clib_virtualfiles.py index 669484a391d..6378f403459 100644 --- a/pygmt/tests/test_clib_virtualfiles.py +++ b/pygmt/tests/test_clib_virtualfiles.py @@ -47,6 +47,7 @@ def fixture_dtypes_pandas(dtypes): return tuple(dtypes_pandas) +@pytest.mark.benchmark def test_virtual_file(dtypes): """ Test passing in data via a virtual file with a Dataset. @@ -122,6 +123,7 @@ def test_virtual_file_bad_direction(): pass +@pytest.mark.benchmark @pytest.mark.parametrize( ("array_func", "kind"), [(np.array, "matrix"), (pd.DataFrame, "vector"), (xr.Dataset, "vector")], @@ -202,6 +204,7 @@ def test_virtualfile_from_data_fail_non_valid_data(data): ) +@pytest.mark.benchmark def test_virtualfile_from_vectors(dtypes): """ Test the automation for transforming vectors to virtual file dataset. @@ -221,6 +224,7 @@ def test_virtualfile_from_vectors(dtypes): assert output == expected +@pytest.mark.benchmark @pytest.mark.parametrize("dtype", [str, object]) def test_virtualfile_from_vectors_one_string_or_object_column(dtype): """ @@ -290,6 +294,7 @@ def test_virtualfile_from_vectors_diff_size(): pass +@pytest.mark.benchmark def test_virtualfile_from_matrix(dtypes): """ Test transforming a matrix to virtual file dataset. diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index 990761079a6..cc7fb092b13 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -6,6 +6,7 @@ from pygmt.exceptions import GMTInvalidInput +@pytest.mark.benchmark @pytest.mark.mpl_image_compare def test_coast_region(): """ diff --git a/pygmt/tests/test_colorbar.py b/pygmt/tests/test_colorbar.py index 57aa10c5311..bae59a1e050 100644 --- a/pygmt/tests/test_colorbar.py +++ b/pygmt/tests/test_colorbar.py @@ -5,6 +5,7 @@ from pygmt import Figure +@pytest.mark.benchmark @pytest.mark.mpl_image_compare def test_colorbar_box(): """ diff --git a/pygmt/tests/test_config.py b/pygmt/tests/test_config.py index e14f543d0f6..b9341f5b0bf 100644 --- a/pygmt/tests/test_config.py +++ b/pygmt/tests/test_config.py @@ -64,6 +64,7 @@ def test_config_font_annot(): return fig +@pytest.mark.benchmark @pytest.mark.mpl_image_compare def test_config_format_date_map(): """ diff --git a/pygmt/tests/test_contour.py b/pygmt/tests/test_contour.py index 95d7705e48b..58aa0d56a31 100644 --- a/pygmt/tests/test_contour.py +++ b/pygmt/tests/test_contour.py @@ -46,6 +46,7 @@ def test_contour_vec(region): return fig +@pytest.mark.benchmark @pytest.mark.mpl_image_compare(filename="test_contour_matrix.png") @pytest.mark.parametrize( "array_func", diff --git a/pygmt/tests/test_datasets_load_remote_datasets.py b/pygmt/tests/test_datasets_load_remote_datasets.py index bb5a9087e0d..ee5e126a0de 100644 --- a/pygmt/tests/test_datasets_load_remote_datasets.py +++ b/pygmt/tests/test_datasets_load_remote_datasets.py @@ -19,6 +19,21 @@ def load_remote_dataset_wrapper(resolution="01d", region=None, registration=None ) +@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) + + def test_load_remote_dataset_invalid_resolutions(): """ Make sure _load_remote_dataset fails for invalid resolutions. diff --git a/pygmt/tests/test_datasets_samples.py b/pygmt/tests/test_datasets_samples.py index 28a86711f74..3c05cbec790 100644 --- a/pygmt/tests/test_datasets_samples.py +++ b/pygmt/tests/test_datasets_samples.py @@ -180,6 +180,7 @@ def test_load_notre_dame_topography(): assert data["z"].max() == 960 +@pytest.mark.benchmark def test_earth_relief_holes(): """ Check that the @earth_relief_20m_holes.grd dataset loads without errors. diff --git a/pygmt/tests/test_dimfilter.py b/pygmt/tests/test_dimfilter.py index 4b4f01ec2f6..4bc53d34e7b 100644 --- a/pygmt/tests/test_dimfilter.py +++ b/pygmt/tests/test_dimfilter.py @@ -59,6 +59,7 @@ def test_dimfilter_outgrid(grid, expected_grid): xr.testing.assert_allclose(a=temp_grid, b=expected_grid) +@pytest.mark.benchmark def test_dimfilter_no_outgrid(grid, expected_grid): """ Test the required parameters for dimfilter with no set outgrid. diff --git a/pygmt/tests/test_figure.py b/pygmt/tests/test_figure.py index 2d13ab14459..8cd3514f954 100644 --- a/pygmt/tests/test_figure.py +++ b/pygmt/tests/test_figure.py @@ -56,6 +56,7 @@ def test_figure_region_country_codes(): npt.assert_allclose(fig.region, np.array([0.0, 360.0, -90.0, 90.0])) +@pytest.mark.benchmark def test_figure_repr(): """ Make sure that figure output's PNG and HTML printable representations look ok. diff --git a/pygmt/tests/test_filter1d.py b/pygmt/tests/test_filter1d.py index e591bd419bb..f9f7f37bf9f 100644 --- a/pygmt/tests/test_filter1d.py +++ b/pygmt/tests/test_filter1d.py @@ -22,7 +22,7 @@ def fixture_data(): def test_filter1d_no_outfile(data): """ - Test filter1d with no set outgrid. + Test filter1d with no set outfile. """ result = filter1d(data=data, filter_type="g5") assert result.shape == (671, 2) @@ -79,13 +79,17 @@ def test_filter1d_outfile_incorrect_output_type(data): assert Path(tmpfile.name).stat().st_size > 0 # check that outfile exists +@pytest.mark.benchmark def test_filter1d_format(data): """ Test that correct formats are returned. """ time_series_default = filter1d(data=data, filter_type="g5") assert isinstance(time_series_default, pd.DataFrame) + assert time_series_default.shape == (671, 2) time_series_array = filter1d(data=data, filter_type="g5", output_type="numpy") assert isinstance(time_series_array, np.ndarray) + assert time_series_array.shape == (671, 2) time_series_df = filter1d(data=data, filter_type="g5", output_type="pandas") assert isinstance(time_series_df, pd.DataFrame) + assert time_series_df.shape == (671, 2)