Skip to content

Commit

Permalink
Make a duplicate fixture for pandas dtypes including pyarrow types (#…
Browse files Browse the repository at this point in the history
…2941)

* Make a duplicate fixture for pandas dtypes including pyarrow types

Explicitly copying the numpy dtypes fixture in test_clib_virtualfiles.py to a
new dtypes_pandas fixture that includes pyarrow types, so that modifications
to the original numpy dtypes fixture won't affect other tests.

* Let test_virtualfile_from_vectors_transpose use dtypes fixture

No need to recreate a new dtypes list.
  • Loading branch information
weiji14 committed Jan 2, 2024
1 parent 5639f24 commit 6028bf4
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions pygmt/tests/test_clib_virtualfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -248,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)
Expand Down Expand Up @@ -315,16 +327,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),
Expand Down

0 comments on commit 6028bf4

Please sign in to comment.