From 1c5d7b6a29c773234b960f965d0d9bafbbf29b0e Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 27 Aug 2026 18:18:08 +0800 Subject: [PATCH 1/3] pygmt.project: Fix the bug that passing x/y/z is not allowed --- pygmt/src/project.py | 8 +++++--- pygmt/tests/test_project.py | 22 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pygmt/src/project.py b/pygmt/src/project.py index 33f4da1ceca..991facaced5 100644 --- a/pygmt/src/project.py +++ b/pygmt/src/project.py @@ -126,6 +126,8 @@ def project( Pass in (x, y, z) or (longitude, latitude, elevation) values by providing a file name to an ASCII data table, a 2-D $table_classes. + x/y/z : 1-D arrays + Arrays of x and y coordinates and values z of the data points. $output_type $outfile center @@ -223,9 +225,9 @@ def project( """ if kwargs.get("C", center) is None: raise GMTParameterError(required="center") - if kwargs.get("G") is None and data is None: + if kwargs.get("G") is None and data is None and x is None and y is None: raise GMTParameterError( - required="data", reason="Required unless 'generate' is set." + at_least_one=["data", "x/y/z"], reason="Required unless 'generate' is set." ) if kwargs.get("G") is not None and kwargs.get("F") is not None: raise GMTParameterError(at_most_one=["convention", "generate"]) @@ -267,7 +269,7 @@ def project( y=y, z=z, mincols=2, - required=False, + required=aliasdict.get("G") is None, ) as vintbl, lib.virtualfile_out(kind="dataset", fname=outfile) as vouttbl, ): diff --git a/pygmt/tests/test_project.py b/pygmt/tests/test_project.py index 4d00709c039..8d414e17e8d 100644 --- a/pygmt/tests/test_project.py +++ b/pygmt/tests/test_project.py @@ -52,6 +52,22 @@ def test_project_input_matrix(array_func, dataframe): ) +def test_project_input_xy(dataframe): + """ + Run project by passing in x/y as input. + """ + output = project( + x=dataframe.x, y=dataframe.y, center=[0, -1], azimuth=45, flat_earth=True + ) + assert isinstance(output, pd.DataFrame) + assert output.shape == (1, 6) + npt.assert_allclose( + output.iloc[0], + [0.000000, 0.000000, 0.707107, 0.707107, 0.500000, -0.500000], + rtol=1e-5, + ) + + def test_project_output_filename(dataframe): """ Run project by passing in a pandas.DataFrame, and output to an ASCII txt file. @@ -78,14 +94,14 @@ def test_project_output_filename(dataframe): def test_project_incorrect_parameters(): """ - Run project by providing incorrect parameters such as 1) no `center`; 2) no `data` - or `generate`; and 3) `generate` with `convention`. + Run project by providing incorrect parameters such as 1) no `center`; 2) no `data`, + `x`/`y` or `generate`; and 3) `generate` with `convention`. """ with pytest.raises(GMTParameterError): # No `center` project(azimuth=45) with pytest.raises(GMTParameterError): - # No `data` or `generate` + # No `data`, `x`/`y` or `generate` project(center=[0, -1], azimuth=45, flat_earth=True) with pytest.raises(GMTParameterError): # Using `generate` with `convention` From 6b6d17544391a6b79529757c260024fea1f0e55e Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 27 Aug 2026 19:15:19 +0800 Subject: [PATCH 2/3] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com> --- pygmt/src/project.py | 2 +- pygmt/tests/test_project.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/src/project.py b/pygmt/src/project.py index 991facaced5..5b1988d0349 100644 --- a/pygmt/src/project.py +++ b/pygmt/src/project.py @@ -127,7 +127,7 @@ def project( providing a file name to an ASCII data table, a 2-D $table_classes. x/y/z : 1-D arrays - Arrays of x and y coordinates and values z of the data points. + Arrays of x- and y-coordinates and z-values of the data points. $output_type $outfile center diff --git a/pygmt/tests/test_project.py b/pygmt/tests/test_project.py index 8d414e17e8d..87f8c867374 100644 --- a/pygmt/tests/test_project.py +++ b/pygmt/tests/test_project.py @@ -98,13 +98,13 @@ def test_project_incorrect_parameters(): `x`/`y` or `generate`; and 3) `generate` with `convention`. """ with pytest.raises(GMTParameterError): - # No `center` + # 'center' is not set project(azimuth=45) with pytest.raises(GMTParameterError): - # No `data`, `x`/`y` or `generate` + # None of 'data', 'x'/'y' or 'generate' is set project(center=[0, -1], azimuth=45, flat_earth=True) with pytest.raises(GMTParameterError): - # Using `generate` with `convention` + # Using 'generate' with 'convention' project(center=[0, -1], generate=0.5, convention="xypqrsz") From 3f9be0c39cf2f98a48375f651c18902f0a2510d1 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 27 Aug 2026 19:16:42 +0800 Subject: [PATCH 3/3] Fix backtick to single quotes in docstrings --- pygmt/tests/test_project.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_project.py b/pygmt/tests/test_project.py index 87f8c867374..35b8841541e 100644 --- a/pygmt/tests/test_project.py +++ b/pygmt/tests/test_project.py @@ -94,8 +94,8 @@ def test_project_output_filename(dataframe): def test_project_incorrect_parameters(): """ - Run project by providing incorrect parameters such as 1) no `center`; 2) no `data`, - `x`/`y` or `generate`; and 3) `generate` with `convention`. + Run project by providing incorrect parameters such as 1) no 'center'; 2) no 'data', + 'x'/'y' or 'generate'; and 3) 'generate' with 'convention'. """ with pytest.raises(GMTParameterError): # 'center' is not set