@@ -16,7 +16,11 @@ def crossunder(
1616) -> Union [PdDataFrame , PlDataFrame ]:
1717
1818 if number_of_data_points is not None :
19- data = data .tail (number_of_data_points ).copy () if isinstance (data , PdDataFrame ) else data .slice (- number_of_data_points )
19+
20+ if isinstance (data , PdDataFrame ):
21+ data = data .tail (number_of_data_points ).copy ()
22+ else :
23+ data = data .slice (- number_of_data_points )
2024
2125 if isinstance (data , PdDataFrame ):
2226 col1 , col2 = data [first_column ], data [second_column ]
@@ -25,7 +29,8 @@ def crossunder(
2529 if strict :
2630 crossunder_mask = (prev_col1 > prev_col2 ) & (col1 < col2 )
2731 else :
28- crossunder_mask = (col1 > col2 ) & (prev_col1 <= prev_col2 ) | (col1 >= col2 ) & (prev_col1 < prev_col2 )
32+ crossunder_mask = (col1 > col2 ) & (prev_col1 <= prev_col2 ) \
33+ | (col1 >= col2 ) & (prev_col1 < prev_col2 )
2934
3035 data .loc [:, result_column ] = crossunder_mask .astype (int )
3136
@@ -36,9 +41,12 @@ def crossunder(
3641 if strict :
3742 crossunder_mask = (prev_col1 > prev_col2 ) & (col1 < col2 )
3843 else :
39- crossunder_mask = (col1 > col2 ) & (prev_col1 <= prev_col2 ) | (col1 >= col2 ) & (prev_col1 < prev_col2 )
44+ crossunder_mask = (col1 > col2 ) & (prev_col1 <= prev_col2 ) \
45+ | (col1 >= col2 ) & (prev_col1 < prev_col2 )
4046
41- data = data .with_columns (pl .when (crossunder_mask ).then (1 ).otherwise (0 ).alias (result_column ))
47+ data = data .with_columns (
48+ pl .when (crossunder_mask ).then (1 ).otherwise (0 ).alias (result_column )
49+ )
4250
4351 return data
4452
@@ -70,9 +78,11 @@ def is_crossunder(
7078 number_of_data_points = len (data )
7179
7280 if isinstance (data , PdDataFrame ):
73- return data [crossunder_column ].tail (number_of_data_points ).eq (1 ).any ()
81+ return data [crossunder_column ].tail (number_of_data_points )\
82+ .eq (1 ).any ()
7483 elif isinstance (data , pl .DataFrame ):
75- return data [crossunder_column ][- number_of_data_points :].to_list ().count (1 ) > 0
84+ return data [crossunder_column ][- number_of_data_points :]\
85+ .to_list ().count (1 ) > 0
7686
7787 raise PyIndicatorException (
7888 "Data type not supported. Please provide a Pandas or Polars DataFrame."
0 commit comments