From 65e9e2b9d122b42cdc5a94805f521bf72d448b5b Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 2 Jan 2024 18:06:40 +1300 Subject: [PATCH 1/2] Make a duplicate fixture for pandas dtypes including pyarrow types Explicitly copying the numpy dtypes fixture to a new pandas dtypes fixture that includes pyarrow types, so that modifications to the original numpy dtypes fixture won't affect other tests. --- pygmt/tests/test_clib_virtualfiles.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pygmt/tests/test_clib_virtualfiles.py b/pygmt/tests/test_clib_virtualfiles.py index 5c0e39d3467..eb2020ee4a3 100644 --- a/pygmt/tests/test_clib_virtualfiles.py +++ b/pygmt/tests/test_clib_virtualfiles.py @@ -34,6 +34,19 @@ def fixture_dtypes(): return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split() +@pytest.fixture(scope="module", name="dtypes_pandas") +def fixture_dtypes_pandas(dtypes): + """ + List of supported pandas dtypes. + """ + dtypes_pandas = dtypes.copy() + + if find_spec("pyarrow") is not None: + dtypes_pandas.extend([f"{dtype}[pyarrow]" for dtype in dtypes_pandas]) + + return tuple(dtypes_pandas) + + def test_virtual_file(dtypes): """ Test passing in data via a virtual file with a Dataset. @@ -315,16 +328,14 @@ def test_virtualfile_from_matrix_slice(dtypes): assert output == expected -def test_virtualfile_from_vectors_pandas(dtypes): +def test_virtualfile_from_vectors_pandas(dtypes_pandas): """ Pass vectors to a dataset using pandas.Series, checking both numpy and pyarrow dtypes. """ size = 13 - if find_spec("pyarrow") is not None: - dtypes.extend([f"{dtype}[pyarrow]" for dtype in dtypes]) - for dtype in dtypes: + for dtype in dtypes_pandas: data = pd.DataFrame( data={ "x": np.arange(size), From 981a98b43794ee65d2b9565e72d73e0f913f8061 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 2 Jan 2024 18:07:49 +1300 Subject: [PATCH 2/2] Let test_virtualfile_from_vectors_transpose use dtypes fixture No need to recreate a new dtypes list. --- pygmt/tests/test_clib_virtualfiles.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pygmt/tests/test_clib_virtualfiles.py b/pygmt/tests/test_clib_virtualfiles.py index eb2020ee4a3..669484a391d 100644 --- a/pygmt/tests/test_clib_virtualfiles.py +++ b/pygmt/tests/test_clib_virtualfiles.py @@ -261,11 +261,10 @@ def test_virtualfile_from_vectors_two_string_or_object_columns(dtype): assert output == expected -def test_virtualfile_from_vectors_transpose(): +def test_virtualfile_from_vectors_transpose(dtypes): """ Test transforming matrix columns to virtual file dataset. """ - dtypes = "float32 float64 int32 int64 uint32 uint64".split() shape = (7, 5) for dtype in dtypes: data = np.arange(shape[0] * shape[1], dtype=dtype).reshape(shape)