(
data: "pa.Table",
enable_categorical: bool,
feature_names: Optional[FeatureNames],
feature_types: Optional[Union[FeatureTypes, Categories]],
)
| 821 | |
| 822 | |
| 823 | def _transform_arrow_table( |
| 824 | data: "pa.Table", |
| 825 | enable_categorical: bool, |
| 826 | feature_names: Optional[FeatureNames], |
| 827 | feature_types: Optional[Union[FeatureTypes, Categories]], |
| 828 | ) -> Tuple[ArrowTransformed, Optional[FeatureNames], Optional[FeatureTypes]]: |
| 829 | if TYPE_CHECKING: |
| 830 | import pyarrow as pa |
| 831 | else: |
| 832 | pa = import_pyarrow() |
| 833 | |
| 834 | t_names, t_types = _arrow_feature_info(data) |
| 835 | feature_types, ref_categories = get_ref_categories(feature_types) |
| 836 | |
| 837 | if feature_names is None: |
| 838 | feature_names = t_names |
| 839 | if feature_types is None: |
| 840 | feature_types = t_types |
| 841 | |
| 842 | columns = [] |
| 843 | for cname in feature_names: |
| 844 | col0 = data.column(cname) |
| 845 | col: Union["pa.NumericArray", "pa.DictionaryArray"] = col0.combine_chunks() |
| 846 | if isinstance(col, pa.BooleanArray): |
| 847 | col = col.cast(pa.int8()) # bit-compressed array, not supported. |
| 848 | if is_arrow_dict(col) and not enable_categorical: |
| 849 | # None because the function doesn't know how to get the type info from arrow |
| 850 | # table. |
| 851 | _invalid_dataframe_dtype(None) |
| 852 | columns.append(col) |
| 853 | |
| 854 | df_t = ArrowTransformed(columns, ref_categories=ref_categories) |
| 855 | return df_t, feature_names, feature_types |
| 856 | |
| 857 | |
| 858 | def _from_arrow_table( # pylint: disable=too-many-positional-arguments |
no test coverage detected