Best Python code snippet using hypothesis
preprocessor_dispatcher.py
Source:preprocessor_dispatcher.py
1from sklearn import compose, impute, pipeline, preprocessing2from src import config3NUMERIC_DTYPES = ["int64", "float64"]4def get_numeric_cols():5 if config.CONTINUOUS_FEATURES:6 return config.CONTINUOUS_FEATURES7 return compose.make_column_selector(dtype_include=NUMERIC_DTYPES)8def get_categorical_cols():9 if config.DISCRETE_FEATURES:10 return config.DISCRETE_FEATURES11 return compose.make_column_selector(dtype_exclude=NUMERIC_DTYPES)12imputers = {13 "constant": impute.SimpleImputer(strategy="constant", fill_value="unknown"),14 "knn": impute.KNNImputer(),15 "mean": impute.SimpleImputer(),16 "median": impute.SimpleImputer(strategy="median"),17 "mode": impute.SimpleImputer(strategy="most_frequent"),18}19encoders = {20 "one_hot": preprocessing.OneHotEncoder(handle_unknown="ignore"),21 "ordinal": preprocessing.OrdinalEncoder(22 handle_unknown="use_encoded_value", unknown_value=-1023 ),24}25scalers = {26 "max_abs": preprocessing.MaxAbsScaler(),27 "min_max": preprocessing.MinMaxScaler(),28 "standard": preprocessing.StandardScaler(),29}30numeric_pipelines = {31 "linear": pipeline.Pipeline(32 [("standard_scaler", scalers["standard"]), ("mean_imputer", imputers["mean"])],33 verbose=config.VERBOSITY,34 ),35 "tree": pipeline.Pipeline(36 [("mean_imputer", imputers["mean"])], verbose=config.VERBOSITY37 ),38}39categorical_pipelines = {40 "linear": pipeline.Pipeline(41 [("one_hot_encoder", encoders["one_hot"])], verbose=config.VERBOSITY42 ),43 "tree": pipeline.Pipeline(44 [("mode_imputer", imputers["mode"]), ("ordinal_encoder", encoders["ordinal"])],45 verbose=config.VERBOSITY,46 ),47}48preprocessors = {49 "linear_numeric": compose.make_column_transformer(50 (numeric_pipelines["linear"], get_numeric_cols()),51 n_jobs=-1,52 verbose=config.VERBOSE,53 ),54 "tree_numeric": compose.make_column_transformer(55 (numeric_pipelines["tree"], get_numeric_cols()),56 n_jobs=-1,57 verbose=config.VERBOSE,58 ),59 "linear_categorical": compose.make_column_transformer(60 (categorical_pipelines["linear"], get_categorical_cols()),61 n_jobs=-1,62 verbose=config.VERBOSE,63 ),64 "tree_categorical": compose.make_column_transformer(65 (categorical_pipelines["tree"], get_categorical_cols()),66 n_jobs=-1,67 verbose=config.VERBOSE,68 ),69 "linear_all": compose.make_column_transformer(70 (numeric_pipelines["linear"], get_numeric_cols()),71 (categorical_pipelines["linear"], get_categorical_cols()),72 n_jobs=-1,73 verbose=config.VERBOSE,74 ),75 "tree_all": compose.make_column_transformer(76 (numeric_pipelines["tree"], get_numeric_cols()),77 (categorical_pipelines["tree"], get_categorical_cols()),78 n_jobs=-1,79 verbose=config.VERBOSE,80 ),...
test_pretty.py
Source:test_pretty.py
...31 ("from_dtype", from_dtype(xp, xp.int8)),32 ("arrays", arrays(xp, xp.int8, 5)),33 ("scalar_dtypes", scalar_dtypes(xp)),34 ("boolean_dtypes", boolean_dtypes(xp)),35 ("numeric_dtypes", numeric_dtypes(xp)),36 ("integer_dtypes", integer_dtypes(xp)),37 ("unsigned_integer_dtypes", unsigned_integer_dtypes(xp)),38 ("floating_dtypes", floating_dtypes(xp)),39 # Namespaced strategies40 ("from_dtype", xps.from_dtype(xp.int8)),41 ("arrays", xps.arrays(xp.int8, 5)),42 ("scalar_dtypes", xps.scalar_dtypes()),43 ("boolean_dtypes", xps.boolean_dtypes()),44 ("numeric_dtypes", xps.numeric_dtypes()),45 ("integer_dtypes", xps.integer_dtypes()),46 ("unsigned_integer_dtypes", xps.unsigned_integer_dtypes()),47 ("floating_dtypes", xps.floating_dtypes()),48 ]49)50def test_xp_strategies_pretty_repr(name, strat):51 """Strategies that take xp use its __name__ for their own repr."""52 assert repr(strat).startswith(name), f"{name} not in strat repr"53 assert len(repr(strat)) < 100, "strat repr looks too long"...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!