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
use Column;
use *;
/// Ensure a column in a DataFrame is of Float64 type
///
/// # Arguments
///
/// * `df` - DataFrame to modify
/// * `column_name` - Name of the column to convert
///
/// # Returns
///
/// Returns a PolarsResult indicating success or failure
///
/// # Example
///
/// ```
/// use polars::prelude::*;
/// use ta_lib_in_rust::util::dataframe_utils::ensure_f64_column;
///
/// let mut df = DataFrame::new(vec![
/// Series::new("price", &[1, 2, 3]),
/// ]).unwrap();
/// ensure_f64_column(&mut df, "price").unwrap();
/// assert_eq!(df.column("price").unwrap().dtype(), &DataType::Float64);
/// ```
/// Check if a DataFrame has enough rows for a given window size
///
/// # Arguments
///
/// * `df` - The DataFrame to check
/// * `window` - The window size required
/// * `indicator_name` - Name of the indicator (for error message)
///
/// # Returns
///
/// Returns a PolarsResult<()> or an error if there are not enough rows
///
/// # Example
///
/// ```
/// use polars::prelude::*;
/// use ta_lib_in_rust::util::dataframe_utils::check_window_size;
///
/// let df = DataFrame::new(vec![Series::new("close", &[1.0, 2.0, 3.0, 4.0])]).unwrap();
/// assert!(check_window_size(&df, 3, "test").is_ok());
/// assert!(check_window_size(&df, 5, "test").is_err());
/// ```