Skip to content

Commit fa90522

Browse files
committed
Fix flake8 warnings
1 parent d66bef2 commit fa90522

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

pyindicators/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .indicators import sma, rsi, crossunder, ema, wilders_rsi, \
1+
from .indicators import sma, rsi, ema, wilders_rsi, \
22
crossover, is_crossover, wma, macd, willr, is_crossunder, crossunder
33

44
__all__ = [

pyindicators/indicators/crossunder.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)