Skip to content

Commit 8e6e3ac

Browse files
committed
Fix flake8 errors
1 parent 746269c commit 8e6e3ac

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
#----------------------------------------------
3535
- run: python -m pip install black flake8 isort
3636
- run: |
37-
flake8 ./investing_algorithm_framework
37+
flake8 ./pyindicators
3838
test:
3939
needs: linting
4040
strategy:

pyindicators/indicators/crossover.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@ def is_crossover(
1111
strict=True,
1212
) -> bool:
1313
"""
14-
Returns a boolean when the first series crosses above the second series at any point or within the last n data points.
14+
Returns a boolean when the first series crosses above the second
15+
series at any point or within the last n data points.
1516

1617
Args:
1718
data (Union[PdDataFrame, PlDataFrame]): The input data.
1819
first_column (str): The name of the first series.
1920
second_column (str): The name of the second series.
20-
data_points (int, optional): The number of data points to consider. Defaults to None.
21-
strict (bool, optional): If True, the first series must be strictly greater than the second series. If False, the first series must be greater than or equal to the second series. Defaults to True.
21+
data_points (int, optional): The number of data points
22+
to consider. Defaults to None.
23+
strict (bool, optional): If True, the first series must
24+
be strictly greater than the second series. If False,
25+
the first series must be greater than or equal
26+
to the second series. Defaults to True.
2227

2328
Returns:
24-
bool: Returns True if the first series crosses above the second series at any point or within the last n data points.
29+
bool: Returns True if the first series crosses above the
30+
second series at any point or within the last n data points.
2531
"""
2632

2733
if len(data) < 2:

pyindicators/indicators/exponential_moving_average.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import polars as pl
55
from pyindicators.exceptions import PyIndicatorException
66

7+
78
def ema(
89
data: Union[PdDataFrame, PlDataFrame],
910
source_column: str,
@@ -21,7 +22,8 @@ def ema(
2122
exponential moving average. Defaults to None.
2223

2324
Returns:
24-
Union[PdDataFrame, PlDataFrame]: Returns a DataFrame with the EMA of the series.
25+
Union[PdDataFrame, PlDataFrame]: Returns a DataFrame with
26+
the EMA of the series.
2527
"""
2628

2729
if len(data) < period:
@@ -35,9 +37,11 @@ def ema(
3537
result_column = f"EMA_{source_column}_{period}"
3638

3739
if isinstance(data, PdDataFrame):
38-
data[result_column] = data[source_column].ewm(span=period, adjust=False).mean()
40+
data[result_column] = data[source_column]\
41+
.ewm(span=period, adjust=False).mean()
3942
else:
40-
# Polars does not have a direct EWM function, so we implement it manually
43+
# Polars does not have a direct EWM function,
44+
# so we implement it manually
4145
alpha = 2 / (period + 1)
4246
ema_values = []
4347
ema_prev = data[source_column][0] # Initialize with the first value

pyindicators/indicators/rsi.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pandas import Series
22

3+
34
def rsi(series: Series, timeperiod=14):
45
"""
56
Calculate the Relative Strength Index (RSI) for a given Pandas series.
@@ -30,8 +31,9 @@ def rsi(series: Series, timeperiod=14):
3031
i]) / timeperiod
3132

3233
# Calculate relative strength (RS)
33-
rs = avg_gain / avg_loss.replace(0,
34-
1) # Replace 0s with 1 to avoid division by zero
34+
rs = avg_gain / avg_loss.replace(
35+
0, 1
36+
) # Replace 0s with 1 to avoid division by zero
3537

3638
# Calculate RSI
3739
rsi_values = 100 - (100 / (1 + rs))
@@ -59,4 +61,4 @@ def rsi(series: Series, timeperiod=14):
5961
#
6062
# # Drop intermediate columns
6163
# df_deep_copy.drop(['Delta'], axis=1, inplace=True)
62-
# return df_deep_copy[[f'Rsi_{period}']]
64+
# return df_deep_copy[[f'Rsi_{period}']]

pyindicators/indicators/simple_moving_average.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def sma(
2121
simple moving average. Defaults to None.
2222

2323
Returns:
24-
Union[PdDataFrame, PlDataFrame]: Returns a DataFrame with the simple moving average of the series.
24+
Union[PdDataFrame, PlDataFrame]: Returns a DataFrame
25+
with the simple moving average of the series.
2526
"""
2627

2728
if len(data) < period:
@@ -38,8 +39,7 @@ def sma(
3839
data[result_column] = data[source_column].rolling(window=period).mean()
3940
else:
4041
data = data.with_column(
41-
data[source_column]
42-
.rolling(window=period).mean(),
42+
data[source_column].rolling(window=period).mean(),
4343
result_column
4444
)
4545

0 commit comments

Comments
 (0)