ballet.transformer module¶
-
class
ballet.transformer.
ConversionApproach
(name, convert, caught, isokay)[source]¶ Bases:
tuple
-
caught
: Collection[Type[Exception]]¶ Alias for field number 2
-
convert
: Callable¶ Alias for field number 1
-
isokay
: Optional[Callable[[Exception], bool]]¶ Opportunity to catch other exceptions that match a condition
-
name
: str¶ Alias for field number 0
-
-
class
ballet.transformer.
DelegatingRobustTransformer
(transformer)[source]¶ Bases:
ballet.util.DeepcopyMixin
,ballet.eng.base.BaseTransformer
Robust transformer that delegates to underlying transformer
This transformer is robust against different typed and shaped input data. It tries a variety of input data conversion approaches and passes the result to the underlying transformer, using the first approach that works.
- Parameters
transformer (
BaseTransformer
) – a transformer object with fit and transform methods- Raises
UnsuccessfulInputConversionError – If none of the conversion approaches work.
-
CONVERSION_APPROACHES
= [ConversionApproach(name='identity', convert=<function identity>, caught=(<class 'ValueError'>, <class 'TypeError'>), isokay=<function ConversionApproach.<lambda>>), ConversionApproach(name='series', convert=<class 'pandas.core.series.Series'>, caught=(<class 'ValueError'>, <class 'TypeError'>), isokay=<function catch_bare_exception_sanitize_array>), ConversionApproach(name='dataframe', convert=<class 'pandas.core.frame.DataFrame'>, caught=(<class 'ValueError'>, <class 'TypeError'>), isokay=<function ConversionApproach.<lambda>>), ConversionApproach(name='array', convert=<function asarray>, caught=(<class 'ValueError'>, <class 'TypeError'>), isokay=<function ConversionApproach.<lambda>>), ConversionApproach(name='asarray2d', convert=<function asarray2d>, caught=(), isokay=<function ConversionApproach.<lambda>>)]¶
-
DEFAULT_CAUGHT
= (<class 'ValueError'>, <class 'TypeError'>)¶
-
ballet.transformer.
desugar_transformer
(transformer)[source]¶ Replace transformer syntactic sugar with actual transformer
The following syntactic sugar is supported: - None is replaced with an IdentityTransformer - a callable (function or lambda) is replaced with a FunctionTransformer
that wraps that callable
a tuple (input, transformer) is replaced with a SubsetTransformer
- Return type
-
ballet.transformer.
get_transformer_primitives
(transformer)[source]¶ Get the primitives used in this transformer or pipeline
The primitives are just the class names underlying the transformer or pipeline.
- Return type
List
[str
]
-
ballet.transformer.
make_robust_transformer
(transformer)[source]¶ Convert to robust transformer or pipeline
Convert to either a single DelegatingRobustTransformer or a TransformerPipeline where each transformer in the pipeline is a DelegatingRobustTransformer.
- Return type
Union
[TransformerPipeline
,DelegatingRobustTransformer
]