Skip to content

Commit c2ffc92

Browse files
committed
Add tests for dtype_to_arrow_c_fmt
Signed-off-by: Vasily Litvinov <[email protected]>
1 parent adb49da commit c2ffc92

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

pandas/core/exchange/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
Utility functions and objects for implementing the exchange API.
33
"""
44

5-
import enum
65
import pandas as pd
76
import re
87
import numpy as np
98
from pandas.api.types import is_datetime64_dtype
109

1110

12-
@enum.unique
13-
class ArrowCTypes(enum.Enum):
11+
class ArrowCTypes:
1412
"""
1513
Enum for Apache Arrow C type format strings.
1614

pandas/tests/exchange/test_utils.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import pandas as pd
2+
import numpy as np
3+
import pytest
4+
5+
from pandas.core.exchange.utils import dtype_to_arrow_c_fmt
6+
7+
# TODO: use ArrowSchema to get reference C-string.
8+
# At the time, there is no way to access ArrowSchema holding a type format string from python.
9+
# The only way to 'touch' it is to export the structure to a C-pointer:
10+
# https://github.com/apache/arrow/blob/5680d209fd870f99134e2d7299b47acd90fabb8e/python/pyarrow/types.pxi#L230-L239
11+
@pytest.mark.parametrize(
12+
"pandas_dtype, c_string",
13+
[
14+
(np.dtype("bool"), "b"),
15+
(np.dtype("int8"), "c"),
16+
(np.dtype("uint8"), "C"),
17+
(np.dtype("int16"), "s"),
18+
(np.dtype("uint16"), "S"),
19+
(np.dtype("int32"), "i"),
20+
(np.dtype("uint32"), "I"),
21+
(np.dtype("int64"), "l"),
22+
(np.dtype("uint64"), "L"),
23+
(np.dtype("float16"), "e"),
24+
(np.dtype("float32"), "f"),
25+
(np.dtype("float64"), "g"),
26+
(pd.Series(["a"]).dtype, "u"),
27+
(
28+
pd.Series([0]).astype("datetime64[ns]").dtype,
29+
"tsn:",
30+
),
31+
],
32+
)
33+
def test_dtype_to_arrow_c_fmt(pandas_dtype, c_string): # noqa PR01
34+
"""Test ``dtype_to_arrow_c_fmt`` utility function."""
35+
assert dtype_to_arrow_c_fmt(pandas_dtype) == c_string

0 commit comments

Comments
 (0)