MCPcopy Create free account
hub / github.com/catboost/catboost / preprocess_data

Function preprocess_data

catboost/python-package/ut/medium/test_with_polars.py:328–361  ·  view source on GitHub ↗

:return: (X, Xpl)

(
    X: List[object],
    Xpl: Union[pl.DataFrame, pl.Series],
    offset: int,
    multiple_chunks: bool
)

Source from the content-addressed store, hash-verified

326
327
328def preprocess_data(
329 X: List[object],
330 Xpl: Union[pl.DataFrame, pl.Series],
331 offset: int,
332 multiple_chunks: bool
333) -> Tuple[List[object], Union[pl.DataFrame, pl.Series]]:
334 """
335 :return: (X, Xpl)
336 """
337
338 if offset:
339 X = X[offset:]
340 Xpl = Xpl.slice(offset=offset)
341 if has_pyarrow:
342 if isinstance(Xpl, pl.DataFrame):
343 for column in Xpl:
344 assert column.to_arrow().offset == offset
345 elif isinstance(Xpl, pl.Series):
346 assert Xpl.to_arrow().offset == offset
347
348 n_samples_after_offset = len(X)
349
350 if multiple_chunks:
351 cut_pos = n_samples_after_offset // 3
352 Xpl1 = Xpl.slice(offset=0, length=cut_pos)
353 Xpl2 = Xpl.slice(offset=cut_pos)
354 Xpl = pl.concat([Xpl1, Xpl2])
355 if isinstance(Xpl, pl.DataFrame):
356 for column in Xpl:
357 assert column.n_chunks() == 2
358 elif isinstance(Xpl, pl.Series):
359 assert Xpl.n_chunks() == 2
360
361 return X, Xpl
362
363
364def generate_group_sizes(n_samples: int, min_group_size: int, max_group_size: int, seed: int = 42) -> List[int]:

Callers 13

test_features_numericFunction · 0.85
test_features_textFunction · 0.85
test_features_embeddingsFunction · 0.85
test_labelFunction · 0.85
test_pairs_and_graphFunction · 0.85
test_weightFunction · 0.85
test_group_idFunction · 0.85
test_group_weightFunction · 0.85
test_subgroup_idFunction · 0.85
test_pairs_weightFunction · 0.85
test_baselineFunction · 0.85

Calls 4

isinstanceFunction · 0.85
lenFunction · 0.85
concatMethod · 0.80
sliceMethod · 0.45

Tested by

no test coverage detected