Skip to content

Commit ce9be02

Browse files
committed
refactor(ta): remove unnecessary cast() calls and fix noinspection
1 parent 22f279a commit ce9be02

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/pynecore/lib/ta.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def ema(source: float, length: int, _alpha: float | None = None) -> float | NA[f
527527
# Use SMA at warming stage
528528
if isinstance(last_val, NA):
529529
last_val = sma(source, length)
530-
return cast(float | NA[float], last_val)
530+
return last_val
531531

532532
# Warmed result
533533
last_val = alpha * source + (1 - alpha) * last_val
@@ -607,7 +607,7 @@ def highest(source: Series[float], length: int, _bars: bool = False, _tuple: boo
607607
return -max_index
608608
if _tuple:
609609
return cast(float | tuple[float | NA[float], float | NA[float]], (last_max, -max_index))
610-
return cast(float | NA[float], last_max)
610+
return last_max
611611

612612

613613
@overload
@@ -805,7 +805,7 @@ def lowest(source: Series[float], length: int,
805805
return -min_index
806806
if _tuple:
807807
return cast(float | tuple[float | NA[float], float | NA[float]], (last_min, -min_index))
808-
return cast(float | NA[float], last_min)
808+
return last_min
809809

810810

811811
@overload
@@ -871,7 +871,7 @@ def max(source: Series[float]) -> float | NA[float]:
871871
max_val: Persistent[float | NA] = NA(float)
872872
if max_val < source or isinstance(max_val, NA):
873873
max_val = source
874-
return cast(float | NA[float], max_val)
874+
return max_val
875875

876876

877877
def median(source: Series[TFI], length: int) -> TFI | NA[TFI] | Series[TFI]:
@@ -897,8 +897,8 @@ def median(source: Series[TFI], length: int) -> TFI | NA[TFI] | Series[TFI]:
897897

898898
# Add new value and balance heaps
899899
value = source
900-
window.append(cast(TFI, value))
901-
heapq.heappush(heap_low, -cast(TFI, value))
900+
window.append(value)
901+
heapq.heappush(heap_low, -value)
902902
heapq.heappush(heap_high, -heapq.heappop(heap_low))
903903

904904
if len(heap_low) < len(heap_high):
@@ -964,7 +964,7 @@ def min(source: Series[float]) -> float | NA:
964964
min_val: Persistent[float | NA] = NA(float)
965965
if min_val > source or isinstance(min_val, NA):
966966
min_val = source
967-
return cast(float | NA[float], min_val)
967+
return min_val
968968

969969

970970
def mode(source: Series[TFI], length: int) -> TFI | NA:
@@ -1121,7 +1121,7 @@ def percentrank(source: Series[float], length: int) -> float | NA[float] | Serie
11211121
return array.percentrank(source[:length + 1], 0) # type: ignore
11221122

11231123

1124-
# noinspection PyUnusedLocal
1124+
# noinspection PyUnusedLocal,PyShadowingBuiltins
11251125
def pivot_point_levels(type: str, anchor: bool, developing: bool = False) -> list[float | NA[float]]:
11261126
"""
11271127
Calculate pivot point levels based on the specified calculation type.
@@ -1645,7 +1645,7 @@ def sar(start: float = 0.02, inc: float = 0.02, max: float = 0.2) -> float | NA[
16451645
af = builtins.min(af + inc, max)
16461646

16471647
sar_val = next_sar
1648-
return cast(float | NA[float], sar_val)
1648+
return sar_val
16491649

16501650

16511651
def sma(source: Series[float], length: int) -> float | NA[float]:

0 commit comments

Comments
 (0)