[GH-ISSUE #157] Issue: NumPy Import Error in pandas_ta Library #452

Closed
opened 2026-03-13 20:27:36 +03:00 by kerem · 2 comments
Owner

Originally created by @cypheroxide on GitHub (Mar 4, 2025).
Original GitHub issue: https://github.com/AJaySi/ALwrity/issues/157

Originally assigned to: @AJaySi, @cypheroxide, @uniqueumesh on GitHub.

Issue: NumPy Import Error in pandas_ta Library

Summary

After successfully resolving the dependencies installation issues, I encountered an error when trying to run the application due to a NumPy import issue in the pandas_ta library.

Environment

Error Description

When running the application with streamlit run alwrity.py, the following error occurs:

ImportError: cannot import name 'NaN' from 'numpy' (C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\numpy\__init__.py). Did you mean: 'nan'?

Error Traceback

Traceback (most recent call last):
  File "C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\streamlit\runtime\scriptrunner\exec_code.py", line 121, in exec_func_with_error_handling
    result = func()
             ^^^^^^
  File "C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 591, in code_to_exec
    exec(code, module.__dict__)
  File "C:\Users\CypherOxide\Code\AI-Writer\alwrity.py", line 8, in <module>
    from lib.utils.ui_setup import setup_ui
  File "C:\Users\CypherOxide\Code\AI-Writer\lib\utils\ui_setup.py", line 4, in <module>
    from .content_generators import content_planning_tools, ai_writers
  File "C:\Users\CypherOxide\Code\AI-Writer\lib\utils\content_generators.py", line 2, in <module>
    from lib.utils.alwrity_utils import (
  File "C:\Users\CypherOxide\Code\AI-Writer\lib\utils\alwrity_utils.py", line 12, in <module>
    from lib.ai_writers.ai_financial_writer import write_basic_ta_report
  File "C:\Users\CypherOxide\Code\AI-Writer\lib\ai_writers\ai_financial_writer.py", line 14, in <module>
    from ..ai_web_researcher.finance_data_researcher import get_finance_data, get_fin_options_data
  File "C:\Users\CypherOxide\Code\AI-Writer\lib\ai_web_researcher\finance_data_researcher.py", line 4, in <module>
    import pandas_ta as ta
  File "C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\pandas_ta\__init__.py", line 116, in <module>
    from pandas_ta.core import *
  File "C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\pandas_ta\core.py", line 18, in <module>
    from pandas_ta.momentum import *
  File "C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\pandas_ta\momentum\__init__.py", line 34, in <module>
    from .squeeze_pro import squeeze_pro
  File "C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\pandas_ta\momentum\squeeze_pro.py", line 2, in <module>
    from numpy import NaN as npNaN
ImportError: cannot import name 'NaN' from 'numpy' (C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\numpy\__init__.py). Did you mean: 'nan'?

Root Cause

In recent versions of NumPy, the NaN constant is named nan (lowercase) instead of NaN (uppercase). The pandas_ta library is trying to import the uppercase version, which no longer exists.

Reproduction Steps

  1. Install all dependencies according to the instructions in the repository
  2. Run the application with streamlit run alwrity.py
  3. Observe the error related to NumPy import

Solution

Edit the following file in your virtual environment:

venv/Lib/site-packages/pandas_ta/momentum/squeeze_pro.py

Change line 2 from:

from numpy import NaN as npNaN

To:

from numpy import nan as npNaN

After making this change, the application runs successfully without any further errors.

Proposed Long-Term Solutions

  1. Consider pinning the pandas_ta package to a specific version that works with the current NumPy version
  2. Submit a PR to the pandas_ta repository to fix this issue at the source (I plan on doing this shortly, disregard)
  3. Create a patching script that automatically applies this fix during installation (I have one, this will be included in my PR)

I've confirmed this solution works on my system (Windows 11, Python 3.12.9). Let me know if there are any questions or if you need additional information.

Originally created by @cypheroxide on GitHub (Mar 4, 2025). Original GitHub issue: https://github.com/AJaySi/ALwrity/issues/157 Originally assigned to: @AJaySi, @cypheroxide, @uniqueumesh on GitHub. # Issue: NumPy Import Error in pandas_ta Library ## Summary After successfully resolving the dependencies installation issues, I encountered an error when trying to run the application due to a NumPy import issue in the pandas_ta library. ## Environment - **Repository**: https://github.com/AJaySi/AI-Writer - **OS**: Windows 11 - **Python**: 3.12.9 - **Dependencies**: Successfully installed all dependencies from requirements.txt ## Error Description When running the application with `streamlit run alwrity.py`, the following error occurs: ``` ImportError: cannot import name 'NaN' from 'numpy' (C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\numpy\__init__.py). Did you mean: 'nan'? ``` ## Error Traceback ``` Traceback (most recent call last): File "C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\streamlit\runtime\scriptrunner\exec_code.py", line 121, in exec_func_with_error_handling result = func() ^^^^^^ File "C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 591, in code_to_exec exec(code, module.__dict__) File "C:\Users\CypherOxide\Code\AI-Writer\alwrity.py", line 8, in <module> from lib.utils.ui_setup import setup_ui File "C:\Users\CypherOxide\Code\AI-Writer\lib\utils\ui_setup.py", line 4, in <module> from .content_generators import content_planning_tools, ai_writers File "C:\Users\CypherOxide\Code\AI-Writer\lib\utils\content_generators.py", line 2, in <module> from lib.utils.alwrity_utils import ( File "C:\Users\CypherOxide\Code\AI-Writer\lib\utils\alwrity_utils.py", line 12, in <module> from lib.ai_writers.ai_financial_writer import write_basic_ta_report File "C:\Users\CypherOxide\Code\AI-Writer\lib\ai_writers\ai_financial_writer.py", line 14, in <module> from ..ai_web_researcher.finance_data_researcher import get_finance_data, get_fin_options_data File "C:\Users\CypherOxide\Code\AI-Writer\lib\ai_web_researcher\finance_data_researcher.py", line 4, in <module> import pandas_ta as ta File "C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\pandas_ta\__init__.py", line 116, in <module> from pandas_ta.core import * File "C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\pandas_ta\core.py", line 18, in <module> from pandas_ta.momentum import * File "C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\pandas_ta\momentum\__init__.py", line 34, in <module> from .squeeze_pro import squeeze_pro File "C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\pandas_ta\momentum\squeeze_pro.py", line 2, in <module> from numpy import NaN as npNaN ImportError: cannot import name 'NaN' from 'numpy' (C:\Users\CypherOxide\Code\AI-Writer\venv\Lib\site-packages\numpy\__init__.py). Did you mean: 'nan'? ``` ## Root Cause In recent versions of NumPy, the `NaN` constant is named `nan` (lowercase) instead of `NaN` (uppercase). The pandas_ta library is trying to import the uppercase version, which no longer exists. ## Reproduction Steps 1. Install all dependencies according to the instructions in the repository 2. Run the application with `streamlit run alwrity.py` 3. Observe the error related to NumPy import ## Solution Edit the following file in your virtual environment: ``` venv/Lib/site-packages/pandas_ta/momentum/squeeze_pro.py ``` Change line 2 from: ```python from numpy import NaN as npNaN ``` To: ```python from numpy import nan as npNaN ``` After making this change, the application runs successfully without any further errors. ## Proposed Long-Term Solutions 1. Consider pinning the pandas_ta package to a specific version that works with the current NumPy version 2. Submit a PR to the pandas_ta repository to fix this issue at the source (I plan on doing this shortly, disregard) 3. Create a patching script that automatically applies this fix during installation (I have one, this will be included in my PR) I've confirmed this solution works on my system (Windows 11, Python 3.12.9). Let me know if there are any questions or if you need additional information.
kerem closed this issue 2026-03-13 20:27:47 +03:00
Author
Owner

@AJaySi commented on GitHub (Mar 4, 2025):

This is useful. Thank you.

Strange that these errors are not present in my environment(not a vanilla system).
@uniqueumesh too confirmed in a new virtual environment and installation went without problems.

Looking forward to include your changes soon. Thank you.

I have posted few questions for you in our other thread.

Regards.

<!-- gh-comment-id:2696599716 --> @AJaySi commented on GitHub (Mar 4, 2025): This is useful. Thank you. Strange that these errors are not present in my environment(not a vanilla system). @uniqueumesh too confirmed in a new virtual environment and installation went without problems. Looking forward to include your changes soon. Thank you. I have posted few questions for you in our other thread. Regards.
Author
Owner

@AJaySi commented on GitHub (Mar 13, 2025):

@cypheroxide Fixed these in his latest patch. Closing this.

<!-- gh-comment-id:2720036722 --> @AJaySi commented on GitHub (Mar 13, 2025): @cypheroxide Fixed these in his latest patch. Closing this.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#452
No description provided.