Skip to content

Request abstract.pyi stub #745

Closed

Description

@AchmadFathoni

Would be nice if we have this stub to help people who works with pandas dataframe and use pyright.

Activity

  1. mrjbq7 commented on Mar 6, 2026

    @mrjbq7
    Member

    Wat?

  2. AchmadFathoni commented on Mar 6, 2026

    @AchmadFathoni
    ContributorAuthor

    Sorry, but which part you don't understand?

  3. mrjbq7 commented on Mar 6, 2026

    @mrjbq7
    Member

    Can you give me an example that would be nicer?

  4. AchmadFathoni commented on Mar 6, 2026

    @AchmadFathoni
    ContributorAuthor

    Let's use something simpler like https://github.com/freqtrade/freqtrade/blob/develop/tests/test_talib.py. We use pandas as input to TA-Lib function.

    when I run pyright test_talib.py I got

    test.py:15:20 - error: "BBANDS" is not a known attribute of module "talib.abstract" (reportAttributeAccessIssue)
    1 error, 0 warnings, 0 informations
    

    Wow why is that? Then I check the content of installed TA-lib

    _abstract.pxi  deprecated.py  py.typed     _ta_lib.cpython-313-x86_64-linux-gnu.so
    abstract.py    _func.pxi      _stream.pxi  _ta_lib.pxd
    common.pxd     __init__.py    stream.py    _ta_lib.pyi
    _common.pxi    __pycache__    _ta_lib.c    _ta_lib.pyx
    

    No abstract.pyi that pyright can read. I understand that pyright only can read static with simpler declaration. So I made crude one as test and put it in .env/lib/python3.13/site-packages/talib/abstract.pyi

    # abstract.pyi
    import numpy as np
    import pandas as pd
    from numpy.typing import NDArray
    from typing import Union
    
    _Array = NDArray[np.float64]
    _Input = Union[pd.DataFrame, _Array]
    
    def BBANDS(
        input: _Input,
        timeperiod: int = 5,
        nbdevup: float = 2,
        nbdevdn: float = 2,
        matype: int = 0,
    ) -> pd.DataFrame: ...
    

    I run test again, got no error and my LSP can give proper function signature. Amazing right?

  5. mrjbq7 commented on Mar 6, 2026

    @mrjbq7
    Member

    Nice! Feel free to contribute that !

  6. AchmadFathoni commented on Mar 6, 2026

    @AchmadFathoni
    ContributorAuthor

    Thanks for the green light . I still considering a script that can automatically generate it from source code. Do you have any newer thought about #212 from 2018?

  7. mrjbq7 commented on Mar 6, 2026

    @mrjbq7
    Member

    You can get pretty far by modifying the _ta_lib.pyi probably.

    Regarding #212, i didn't like a bunch of things about it, but partly i didn't like the instantiation of a new abstract function per function call, but sure if you want to do something there thats nice, sure.

    We have generate scripts in tools/.

  8. AchmadFathoni commented on Mar 6, 2026

    @AchmadFathoni
    ContributorAuthor

    Alright. Anyway what python LSP do you use? Maybe there is better alternative than pyright itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions