From 826979d7c953751d44e584fe1b7a8088cf5259db Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 3 Nov 2025 15:31:01 +1300 Subject: [PATCH 1/3] Fix deprecated string[pyarrow_numpy] in test_to_numpy_pandas_string Xref https://github.com/pandas-dev/pandas/pull/60152 --- pygmt/tests/test_clib_to_numpy.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pygmt/tests/test_clib_to_numpy.py b/pygmt/tests/test_clib_to_numpy.py index e04f732bb3d..5bb65ae9b01 100644 --- a/pygmt/tests/test_clib_to_numpy.py +++ b/pygmt/tests/test_clib_to_numpy.py @@ -371,7 +371,10 @@ def test_to_numpy_pandas_numeric_with_na(dtype, expected_dtype): "U10", "string[python]", pytest.param("string[pyarrow]", marks=skip_if_no(package="pyarrow")), - pytest.param("string[pyarrow_numpy]", marks=skip_if_no(package="pyarrow")), + pytest.param( + pd.StringDtype(storage="pyarrow", na_value=np.nan), + marks=skip_if_no(package="pyarrow"), + ), ], ) def test_to_numpy_pandas_string(dtype): From 8c6f3a2eec6035df5bece2896b27e9a8185c75f6 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 3 Nov 2025 15:57:44 +1300 Subject: [PATCH 2/3] Add conditional to support string[pyarrow_numpy] for pandas<=2.2 Handle pd.StringDtype not having the na_value parameter in pandas 2.2 and below. --- pygmt/tests/test_clib_to_numpy.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pygmt/tests/test_clib_to_numpy.py b/pygmt/tests/test_clib_to_numpy.py index 5bb65ae9b01..971f4178f91 100644 --- a/pygmt/tests/test_clib_to_numpy.py +++ b/pygmt/tests/test_clib_to_numpy.py @@ -372,7 +372,12 @@ def test_to_numpy_pandas_numeric_with_na(dtype, expected_dtype): "string[python]", pytest.param("string[pyarrow]", marks=skip_if_no(package="pyarrow")), pytest.param( - pd.StringDtype(storage="pyarrow", na_value=np.nan), + # TODO(pandas>=2.3): Remove the string[pyarrow_numpy] else statement + ( + pd.StringDtype(storage="pyarrow", na_value=np.nan) + if Version(pd.__version__) >= Version("2.3.0") + else "string[pyarrow_numpy]" + ), marks=skip_if_no(package="pyarrow"), ), ], From 29593c64748b4d6a379186dc98c9aca51f8281d9 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 3 Nov 2025 16:13:05 +1300 Subject: [PATCH 3/3] Just use "str" for pyarrow backed arrays in pandas>=3.0 Otherwise will get an error on Python 3.12 tests when pd.StringDtype(storage="pyarrow", ...) is called without pyarrow installed. --- pygmt/tests/test_clib_to_numpy.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/tests/test_clib_to_numpy.py b/pygmt/tests/test_clib_to_numpy.py index 971f4178f91..ca4417437f3 100644 --- a/pygmt/tests/test_clib_to_numpy.py +++ b/pygmt/tests/test_clib_to_numpy.py @@ -372,10 +372,10 @@ def test_to_numpy_pandas_numeric_with_na(dtype, expected_dtype): "string[python]", pytest.param("string[pyarrow]", marks=skip_if_no(package="pyarrow")), pytest.param( - # TODO(pandas>=2.3): Remove the string[pyarrow_numpy] else statement + # TODO(pandas>=3.0): Remove the string[pyarrow_numpy] else statement ( - pd.StringDtype(storage="pyarrow", na_value=np.nan) - if Version(pd.__version__) >= Version("2.3.0") + "str" # pyarrow string dtype in pandas>=3.0 + if Version(pd.__version__) >= Version("3.0.0.dev0") else "string[pyarrow_numpy]" ), marks=skip_if_no(package="pyarrow"),