Dispatch data for DMatrix.
(
*,
data: DataType,
missing: FloatCompatible, # Or Optional[Float]
threads: int,
feature_names: Optional[FeatureNames],
feature_types: Optional[Union[FeatureTypes, Categories]],
enable_categorical: bool = False,
data_split_mode: DataSplitMode = DataSplitMode.ROW,
)
| 1330 | |
| 1331 | |
| 1332 | def dispatch_data_backend( |
| 1333 | *, |
| 1334 | data: DataType, |
| 1335 | missing: FloatCompatible, # Or Optional[Float] |
| 1336 | threads: int, |
| 1337 | feature_names: Optional[FeatureNames], |
| 1338 | feature_types: Optional[Union[FeatureTypes, Categories]], |
| 1339 | enable_categorical: bool = False, |
| 1340 | data_split_mode: DataSplitMode = DataSplitMode.ROW, |
| 1341 | ) -> DispatchedDataBackendReturnType: |
| 1342 | """Dispatch data for DMatrix.""" |
| 1343 | |
| 1344 | def check_cats( |
| 1345 | feature_types: Optional[Union[FeatureTypes, Categories]], |
| 1346 | ) -> TypeGuard[Optional[FeatureTypes]]: |
| 1347 | if isinstance(feature_types, Categories): |
| 1348 | raise ValueError( |
| 1349 | "Reference category is only supported by DataFrame inputs." |
| 1350 | ) |
| 1351 | return True |
| 1352 | |
| 1353 | if ( |
| 1354 | not _is_cudf_ser(data) |
| 1355 | and not _is_pandas_series(data) |
| 1356 | and not _is_polars_series(data) |
| 1357 | ): |
| 1358 | _check_data_shape(data) |
| 1359 | if is_scipy_csr(data): |
| 1360 | assert check_cats(feature_types) |
| 1361 | return _from_scipy_csr( |
| 1362 | data=data, |
| 1363 | missing=missing, |
| 1364 | nthread=threads, |
| 1365 | feature_names=feature_names, |
| 1366 | feature_types=feature_types, |
| 1367 | data_split_mode=data_split_mode, |
| 1368 | ) |
| 1369 | if is_scipy_csc(data): |
| 1370 | assert check_cats(feature_types) |
| 1371 | return _from_scipy_csc( |
| 1372 | data=data, |
| 1373 | missing=missing, |
| 1374 | nthread=threads, |
| 1375 | feature_names=feature_names, |
| 1376 | feature_types=feature_types, |
| 1377 | data_split_mode=data_split_mode, |
| 1378 | ) |
| 1379 | if is_scipy_coo(data): |
| 1380 | assert check_cats(feature_types) |
| 1381 | return _from_scipy_csr( |
| 1382 | data=data.tocsr(), |
| 1383 | missing=missing, |
| 1384 | nthread=threads, |
| 1385 | feature_names=feature_names, |
| 1386 | feature_types=feature_types, |
| 1387 | data_split_mode=data_split_mode, |
| 1388 | ) |
| 1389 | if _is_np_array_like(data): |
no test coverage detected