Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report - Incorrect Series Indexing in trend.py (Line 1030) #354

Open
Donotavio opened this issue Feb 28, 2025 · 0 comments
Open

Bug Report - Incorrect Series Indexing in trend.py (Line 1030) #354

Donotavio opened this issue Feb 28, 2025 · 0 comments

Comments

@Donotavio
Copy link

Description

There is an issue in the _run method of the trend.py file of the ta package where the self._psar Series is accessed incorrectly.

Most of the indexing operations use .iloc[i], but at line 1030, the code uses self._psar[i] instead of self._psar.iloc[i], which can lead to unintended behavior.

Code Reference

The problematic line in trend.py:

if high2 > self._psar.iloc[i]:
    self._psar[i] = high2  # Incorrect indexing
elif high1 > self._psar.iloc[i]:
    self._psar.iloc[i] = high1

The first assignment should use .iloc[i] instead of direct indexing (self._psar[i]).

Steps to Reproduce

  1. Run a script that calculates the Parabolic SAR (PSAR) indicator using the library.
  2. If self._psar is a Pandas Series, attempting to access it via self._psar[i] instead of self._psar.iloc[i] can cause index mismatches or errors.
  3. This can lead to unexpected results or performance issues.

Expected Behavior

The indexing should be done consistently throughout the _run method using .iloc[i].

Proposed Fix

Modify line 1030 of trend.py from:

self._psar[i] = high2  # Incorrect

to:

self._psar.iloc[i] = high2  # Correct

Environment

  • ta version: (Specify the version you are using)
  • Python version: (e.g., 3.9)
  • Pandas version: (e.g., 1.5.3)
  • OS: (Windows/Linux/macOS)

Additional Context

This change aligns with how indexing is handled in other parts of the _run method and ensures consistency when accessing Pandas Series.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant