1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Core traits and error types for the featrs library.
//!
//! The library is built around three traits that mirror the scikit-learn API:
//!
//! - [`Fit`] — learn parameters from data (`fit`)
//! - [`Transform`] — apply a learned transformation (`transform`)
//! - [`FitTransform`] — convenience blanket trait for types that implement both
//!
//! # Errors
//!
//! All fallible operations return [`Result<T>`], which wraps [`enum@Error`].
//! [`enum@Error`] has three variants:
//! - [`Error::InvalidInput`] — wrong dimensions, types, or empty data
//! - [`Error::NotFitted`] — `transform` called before `fit`
//! - [`Error::Computation`] — numerical issues (zero variance, singular matrices, etc.)
use Error;
/// Errors that can occur during feature engineering operations.
/// Convenience alias for `std::result::Result<T, Error>`.
pub type Result<T> = Result;
/// Learn parameters from data.
///
/// `X` is the feature data (e.g. `DataFrame`).
/// `Y` is the target data (defaults to `X` for unsupervised transformers).
///
/// # Example
///
/// ```rust
/// use featrs::traits::Fit;
/// # use featrs::traits::Result;
/// # use polars::prelude::*;
///
/// // Every transformer implements Fit. The fitted parameters are stored
/// // on the transformer itself.
/// ```
/// Apply a learned transformation to data.
///
/// `X` is the input data (e.g. `DataFrame`). The output type [`Output`](Transform::Output)
/// is typically also `DataFrame`.
///
/// # Example
///
/// ```rust
/// use featrs::traits::Transform;
/// # use polars::prelude::*;
///
/// // After fitting, call transform to apply the transformation.
/// ```
/// Convenience trait for types that implement both [`Fit`] and [`Transform`].
///
/// This trait is automatically implemented for any type that satisfies
/// both bounds. It is used to enable type erasure with
/// [`Box<dyn DataFrameTransformer>`](crate::pipeline::DataFrameTransformer).