Skip to content

Commit 6ce988b

Browse files
authored
Fix missing type stubs error from pyright (#1404)
* fix reportMissingTypeStubs error * fix isort issues * fix python 3.10 issue * add pyarrow-stubs. add comment about check_array_indexer
1 parent 76fed11 commit 6ce988b

File tree

10 files changed

+52
-10
lines changed

10 files changed

+52
-10
lines changed

pandas-stubs/__init__.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ from pandas._config import (
9494
)
9595

9696
from pandas.util._print_versions import show_versions as show_versions
97-
from pandas.util._tester import test as test
9897

9998
from pandas.io.api import (
10099
ExcelFile as ExcelFile,

pandas-stubs/core/arrays/arrow/__init__.pyi

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from pandas.core.indexers.objects import BaseIndexer as BaseIndexer
2+
from pandas.core.indexers.utils import check_array_indexer as check_array_indexer
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import Any
2+
3+
import numpy as np
4+
from pandas import DatetimeIndex
5+
6+
from pandas._libs.tslibs import BaseOffset
7+
8+
class BaseIndexer:
9+
def __init__(
10+
self, index_array: np.ndarray | None = None, window_size: int = 0, **kwargs: Any
11+
) -> None: ...
12+
def get_window_bounds(
13+
self,
14+
num_values: int,
15+
min_periods: int | None,
16+
center: bool | None,
17+
closed: str | None = None,
18+
step: int | None = None,
19+
) -> tuple[np.ndarray, np.ndarray]: ...
20+
21+
class FixedForwardWindowIndexer(BaseIndexer): ...
22+
23+
class VariableOffsetWindowIndexer(BaseIndexer):
24+
def __init__(
25+
self,
26+
index_array: np.ndarray | None = None,
27+
window_size: int = 0,
28+
index: DatetimeIndex | None = None,
29+
offset: BaseOffset | None = None,
30+
**kwargs: Any,
31+
) -> None: ...
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import overload
2+
3+
from pandas._typing import (
4+
AnyArrayLike,
5+
ListLike,
6+
np_ndarray_int,
7+
)
8+
9+
# Docs may not be right. See pandas-dev/pandas#62562
10+
@overload
11+
def check_array_indexer(array: AnyArrayLike, indexer: int) -> int: ...
12+
@overload
13+
def check_array_indexer(array: AnyArrayLike, indexer: slice) -> slice: ...
14+
@overload
15+
def check_array_indexer(array: AnyArrayLike, indexer: ListLike) -> np_ndarray_int: ...

pandas-stubs/io/api.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ from pandas.io.excel import (
55
read_excel as read_excel,
66
)
77
from pandas.io.feather_format import read_feather as read_feather
8-
from pandas.io.gbq import read_gbq as read_gbq
98
from pandas.io.html import read_html as read_html
109
from pandas.io.json import read_json as read_json
1110
from pandas.io.orc import read_orc as read_orc

pandas-stubs/io/excel/_base.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ from typing import (
1212
overload,
1313
)
1414

15-
from odf.opendocument import OpenDocument
15+
from odf.opendocument import OpenDocument # pyright: ignore[reportMissingTypeStubs]
1616
from openpyxl.workbook.workbook import Workbook
1717
from pandas.core.frame import DataFrame
18-
import pyxlsb.workbook
18+
import pyxlsb.workbook # pyright: ignore[reportMissingTypeStubs]
1919
from typing_extensions import Self
2020
from xlrd.book import Book
2121

pandas-stubs/io/parsers/readers.pyi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ from pandas._typing import (
3434
UsecolsArgType,
3535
)
3636

37-
from pandas.io.common import IOHandles
38-
3937
@overload
4038
def read_csv(
4139
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
@@ -472,7 +470,6 @@ class TextFileReader(abc.Iterator):
472470
chunksize: int | None
473471
nrows: int | None
474472
squeeze: bool
475-
handles: IOHandles | None
476473
def __init__(
477474
self,
478475
f: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str] | list,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ types-python-dateutil = ">=2.8.19"
6868
beautifulsoup4 = ">=4.14.2"
6969
html5lib = ">=1.1"
7070
python-calamine = ">=0.2.0"
71+
pyarrow-stubs = { version = ">=20.0.0.20250928", python = "<4" }
7172

7273
[build-system]
7374
requires = ["poetry-core>=1.0.0"]
@@ -240,7 +241,6 @@ enableTypeIgnoreComments = false # use pyright-specific ignores
240241
# disable subset of strict
241242
reportMissingParameterType = false
242243
reportMissingTypeArgument = false
243-
reportMissingTypeStubs = false
244244
reportUnnecessaryTypeIgnoreComment = true
245245
reportUnknownArgumentType = false
246246
reportUnknownLambdaType = false

tests/extension/decimal/array.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import sys
77

88
import numpy as np
9-
import pandas as pd
109
from pandas.api.extensions import (
1110
no_default,
1211
register_extension_dtype,
@@ -165,7 +164,7 @@ def __getitem__(self, item):
165164
return self._data[item]
166165
else:
167166
# array, slice.
168-
item = pd.api.indexers.check_array_indexer(self, item)
167+
item = check_array_indexer(self, item)
169168
return type(self)(self._data[item])
170169

171170
def take(

0 commit comments

Comments
 (0)