MCPcopy Create free account
hub / github.com/dmlc/xgboost / _transform_arrow_table

Function _transform_arrow_table

python-package/xgboost/data.py:823–855  ·  view source on GitHub ↗
(
    data: "pa.Table",
    enable_categorical: bool,
    feature_names: Optional[FeatureNames],
    feature_types: Optional[Union[FeatureTypes, Categories]],
)

Source from the content-addressed store, hash-verified

821
822
823def _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
858def _from_arrow_table( # pylint: disable=too-many-positional-arguments

Callers 4

inplace_predictMethod · 0.85
_from_arrow_tableFunction · 0.85
_transform_polars_dfFunction · 0.85
_proxy_transformFunction · 0.85

Calls 6

import_pyarrowFunction · 0.85
_arrow_feature_infoFunction · 0.85
get_ref_categoriesFunction · 0.85
is_arrow_dictFunction · 0.85
_invalid_dataframe_dtypeFunction · 0.85
ArrowTransformedClass · 0.85

Tested by

no test coverage detected