Skip to content

Series.to_json - Overload variants arguments raise error despite match #481

Closed
@DarioHett

Description

@DarioHett

Describe the bug
The following should not raise an error in mypy: pd.Series().to_json(path_or_buf=None, orient="table", date_format="iso", double_precision=6, force_ascii=True, date_unit="s", default_handler=None, lines=False, compression=None, index=False, indent=None)

Probably related to #164

To Reproduce

  1. Provide a minimal runnable pandas example that is not properly checked by the stubs.
    bug-example.py
import pandas as pd


def somemethod1(data: pd.DataFrame) -> str:
    return data.to_json(
        path_or_buf=None,
        orient="table",
        date_format="iso",
        double_precision=6,
        force_ascii=True,
        date_unit="s",
        default_handler=None,
        lines=False,
        compression=None,
        index=False,
        indent=None,
    )


def somemethod2(data: pd.Series) -> str:
    return data.to_json(
        path_or_buf=None,
        orient="table",
        date_format="iso",
        double_precision=6,
        force_ascii=True,
        date_unit="s",
        default_handler=None,
        lines=False,
        compression=None,
        index=False,
        indent=None,
    )


if __name__ == "__main__":
    somemethod1(pd.DataFrame())
    somemethod2(pd.Series())

app@54d4ae46c9dd:/workspace$ mypy bug-example.py 
mypy.ini: No [mypy] section in config file
bug-example.py:21: error: No overload variant of "to_json" of "Series" matches argument types "None", "str", "str", "int", "bool", "str", "None", "bool", "None", "bool", "None"  [call-overload]
bug-example.py:21: note: Possible overload variants:
bug-example.py:21: note:     def to_json(self, path_or_buf: Union[str, PathLike[str], WriteBuffer[str]], orient: Optional[Literal['split', 'records', 'index']] = ..., date_format: Optional[Literal['epoch', 'iso']] = ..., double_precision: int = ..., force_ascii: bool = ..., date_unit: Literal['s', 'ms', 'us', 'ns'] = ..., default_handler: Optional[Callable[[Any], Union[str, float, bool, List[Any], Dict[Any, Any]]]] = ..., lines: bool = ..., compression: Union[Dict[str, Any], None, Literal['infer', 'gzip', 'bz2', 'zip', 'xz', 'zstd']] = ..., index: bool = ..., indent: Optional[int] = ...) -> None
bug-example.py:21: note:     def to_json(self, path_or_buf: None = ..., orient: Optional[Literal['split', 'records', 'index']] = ..., date_format: Optional[Literal['epoch', 'iso']] = ..., double_precision: int = ..., force_ascii: bool = ..., date_unit: Literal['s', 'ms', 'us', 'ns'] = ..., default_handler: Optional[Callable[[Any], Union[str, float, bool, List[Any], Dict[Any, Any]]]] = ..., lines: bool = ..., compression: Union[Dict[str, Any], None, Literal['infer', 'gzip', 'bz2', 'zip', 'xz', 'zstd']] = ..., index: bool = ..., indent: Optional[int] = ...) -> str
Found 1 error in 1 file (checked 1 source file)

mypy.ini

# Self-type support added, next release (after 0.991) https://github.com/python/mypy/pull/14041
[mypy-local.stuff.*]
disable_error_code = valid-type 
  1. Indicate which type checker you are using (mypy or pyright).
    mypy
  2. Show the error message received from that type checker while checking your example.
app@54d4ae46c9dd:/workspace$ mypy profilerapi/models/JsonDTO.py
mypy.ini: No [mypy] section in config file
profilerapi/models/JsonDTO.py:54: error: No overload variant of "to_json" of "Series" matches argument types "None", "str", "str", "int", "bool", "str", "None", "bool", "None", "bool", "None"  [call-overload]
profilerapi/models/JsonDTO.py:54: note: Possible overload variants:
profilerapi/models/JsonDTO.py:54: note:     def to_json(self, path_or_buf: Union[str, PathLike[str], WriteBuffer[str]], orient: Optional[Literal['split', 'records', 'index']] = ..., date_format: Optional[Literal['epoch', 'iso']] = ..., double_precision: int = ..., force_ascii: bool = ..., date_unit: Literal['s', 'ms', 'us', 'ns'] = ..., default_handler: Optional[Callable[[Any], Union[str, float, bool, List[Any], Dict[Any, Any]]]] = ..., lines: bool = ..., compression: Union[Dict[str, Any], None, Literal['infer', 'gzip', 'bz2', 'zip', 'xz', 'zstd']] = ..., index: bool = ..., indent: Optional[int] = ...) -> None
profilerapi/models/JsonDTO.py:54: note:     def to_json(self, path_or_buf: None = ..., orient: Optional[Literal['split', 'records', 'index']] = ..., date_format: Optional[Literal['epoch', 'iso']] = ..., double_precision: int = ..., force_ascii: bool = ..., date_unit: Literal['s', 'ms', 'us', 'ns'] = ..., default_handler: Optional[Callable[[Any], Union[str, float, bool, List[Any], Dict[Any, Any]]]] = ..., lines: bool = ..., compression: Union[Dict[str, Any], None, Literal['infer', 'gzip', 'bz2', 'zip', 'xz', 'zstd']] = ..., index: bool = ..., indent: Optional[int] = ...) -> str
Found 1 error in 1 file (checked 1 source file)

Please complete the following information:

  • OS: [e.g. Windows, Linux, MacOS]
  • OS Version [e.g. 22]
app@54d4ae46c9dd:/workspace$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
  • python version
app@54d4ae46c9dd:/workspace$ python --version
Python 3.11.1'
  • version of type checker
app@54d4ae46c9dd:/workspace$ mypy --version
mypy 0.991 (compiled: yes)
  • version of installed pandas-stubs
app@54d4ae46c9dd:/workspace$ pip freeze
anyio==3.6.2
attrs==22.1.0
black @ file:///wheels-test/black-22.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
certifi==2022.12.7
charset-normalizer==2.1.1
click==8.1.3
codecov @ file:///wheels-test/codecov-2.1.12-py2.py3-none-any.whl
coverage @ file:///wheels-test/coverage-7.0.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
fastapi @ file:///wheels/fastapi-0.88.0-py3-none-any.whl
flake8 @ file:///wheels-test/flake8-6.0.0-py2.py3-none-any.whl
h11==0.14.0
httpcore==0.16.2
httpx @ file:///wheels/httpx-0.23.1-py3-none-any.whl
idna==3.4
iniconfig==1.1.1
isort @ file:///wheels-test/isort-5.11.3-py3-none-any.whl
mccabe==0.7.0
mypy @ file:///wheels-test/mypy-0.991-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
mypy-extensions==0.4.3
numpy @ file:///wheels/numpy-1.24.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
packaging==22.0
pandas @ file:///wheels/pandas-1.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pandas-stubs==1.5.2.221213
pathspec==0.10.3
platformdirs==2.6.0
pluggy==1.0.0
pycodestyle==2.10.0
pydantic==1.10.2
pyflakes==3.0.1
pytest @ file:///wheels-test/pytest-7.2.0-py3-none-any.whl
pytest-cov @ file:///wheels-test/pytest_cov-4.0.0-py3-none-any.whl
python-dateutil==2.8.2
pytz==2022.7
requests==2.28.1
rfc3986==1.5.0
six==1.16.0
sniffio==1.3.0
starlette @ file:///wheels/starlette-0.22.0-py3-none-any.whl
types-pytz==2022.7.0.0
typing_extensions==4.4.0
urllib3==1.26.13
uvicorn @ file:///wheels/uvicorn-0.20.0-py3-none-any.whl

Additional context
Add any other context about the problem here.

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