From 6ad6eb96d7d0a0bcbe8e01386d80059a6d70a104 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:58:44 +1300 Subject: [PATCH] Move pa.array parametrizations to another file The test_virtualfile_from_vectors_one_string_or_object_column unit test was moved to test_clib_virtualfile_from_vectors.py. Xref https://github.com/GenericMappingTools/pygmt/pull/3512 --- .../test_clib_virtualfile_from_vectors.py | 25 ++++++++++---- pygmt/tests/test_clib_virtualfiles.py | 34 ------------------- 2 files changed, 19 insertions(+), 40 deletions(-) diff --git a/pygmt/tests/test_clib_virtualfile_from_vectors.py b/pygmt/tests/test_clib_virtualfile_from_vectors.py index 041bc7a803c..453f222b6bc 100644 --- a/pygmt/tests/test_clib_virtualfile_from_vectors.py +++ b/pygmt/tests/test_clib_virtualfile_from_vectors.py @@ -53,17 +53,30 @@ def test_virtualfile_from_vectors(dtypes): @pytest.mark.benchmark -@pytest.mark.parametrize("dtype", [str, object]) -def test_virtualfile_from_vectors_one_string_or_object_column(dtype): - """ - Test passing in one column with string or object dtype into virtual file dataset. +@pytest.mark.parametrize( + ("array_func", "dtype"), + [ + pytest.param(np.array, {"dtype": np.str_}, id="str"), + pytest.param(np.array, {"dtype": np.object_}, id="object"), + pytest.param( + getattr(pa, "array", None), + {}, # pa.string() + marks=skip_if_no(package="pyarrow"), + id="pyarrow", + ), + ], +) +def test_virtualfile_from_vectors_one_string_or_object_column(array_func, dtype): + """ + Test passing in one column with string (numpy/pyarrow) or object (numpy) + dtype into virtual file dataset. """ size = 5 x = np.arange(size, dtype=np.int32) y = np.arange(size, size * 2, 1, dtype=np.int32) - strings = np.array(["a", "bc", "defg", "hijklmn", "opqrst"], dtype=dtype) + strings = array_func(["a", "bc", "defg", "hijklmn", "opqrst"], **dtype) with clib.Session() as lib: - with lib.virtualfile_from_vectors((x, y, strings)) as vfile: + with lib.virtualfile_from_vectors(x, y, strings) as vfile: with GMTTempFile() as outfile: lib.call_module("convert", [vfile, f"->{outfile.name}"]) output = outfile.read(keep_tabs=True) diff --git a/pygmt/tests/test_clib_virtualfiles.py b/pygmt/tests/test_clib_virtualfiles.py index 6277f80e153..c747f763024 100644 --- a/pygmt/tests/test_clib_virtualfiles.py +++ b/pygmt/tests/test_clib_virtualfiles.py @@ -143,37 +143,3 @@ def test_open_virtual_file(): bounds = "\t".join([f"<{col.min():.0f}/{col.max():.0f}>" for col in data.T]) expected = f": N = {shape[0]}\t{bounds}\n" assert output == expected - - -@pytest.mark.benchmark -@pytest.mark.parametrize( - ("array_func", "dtype"), - [ - pytest.param(np.array, {"dtype": np.str_}, id="str"), - pytest.param(np.array, {"dtype": np.object_}, id="object"), - pytest.param( - getattr(pa, "array", None), - {}, # pa.string() - marks=skip_if_no(package="pyarrow"), - id="pyarrow", - ), - ], -) -def test_virtualfile_from_vectors_one_string_or_object_column(array_func, dtype): - """ - Test passing in one column with string (numpy/pyarrow) or object (numpy) - dtype into virtual file dataset. - """ - size = 5 - x = np.arange(size, dtype=np.int32) - y = np.arange(size, size * 2, 1, dtype=np.int32) - strings = array_func(["a", "bc", "defg", "hijklmn", "opqrst"], **dtype) - with clib.Session() as lib: - with lib.virtualfile_from_vectors(x, y, strings) as vfile: - with GMTTempFile() as outfile: - lib.call_module("convert", [vfile, f"->{outfile.name}"]) - output = outfile.read(keep_tabs=True) - expected = "".join( - f"{i}\t{j}\t{k}\n" for i, j, k in zip(x, y, strings, strict=True) - ) - assert output == expected