peacock-data-public-datasets-idc-cronscript
/
venv
/lib
/python3.10
/site-packages
/pandas
/tests
/interchange
/test_utils.py
import numpy as np | |
import pytest | |
import pandas as pd | |
from pandas.core.interchange.utils import dtype_to_arrow_c_fmt | |
# TODO: use ArrowSchema to get reference C-string. | |
# At the time, there is no way to access ArrowSchema holding a type format string | |
# from python. The only way to access it is to export the structure to a C-pointer, | |
# see DataType._export_to_c() method defined in | |
# https://github.com/apache/arrow/blob/master/python/pyarrow/types.pxi | |
def test_dtype_to_arrow_c_fmt(pandas_dtype, c_string): # PR01 | |
"""Test ``dtype_to_arrow_c_fmt`` utility function.""" | |
assert dtype_to_arrow_c_fmt(pandas_dtype) == c_string | |
def test_dtype_to_arrow_c_fmt_arrowdtype(pa_dtype, args_kwargs, c_string): | |
# GH 52323 | |
pa = pytest.importorskip("pyarrow") | |
if not args_kwargs: | |
pa_type = getattr(pa, pa_dtype)() | |
elif isinstance(args_kwargs, tuple): | |
pa_type = getattr(pa, pa_dtype)(*args_kwargs) | |
else: | |
pa_type = getattr(pa, pa_dtype)(**args_kwargs) | |
arrow_type = pd.ArrowDtype(pa_type) | |
assert dtype_to_arrow_c_fmt(arrow_type) == c_string | |