Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pandas-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ from pandas.core.api import (
UInt16Dtype as UInt16Dtype,
UInt32Dtype as UInt32Dtype,
UInt64Dtype as UInt64Dtype,
array as array,
bdate_range as bdate_range,
date_range as date_range,
factorize as factorize,
Expand All @@ -66,6 +65,7 @@ from pandas.core.api import (
)
from pandas.core.arrays.sparse import SparseDtype as SparseDtype
from pandas.core.computation.api import eval as eval
from pandas.core.construction import array as array
from pandas.core.reshape.api import (
concat as concat,
crosstab as crosstab,
Expand Down Expand Up @@ -100,13 +100,11 @@ from pandas.io.api import (
HDFStore as HDFStore,
read_clipboard as read_clipboard,
read_csv as read_csv,
read_excel as read_excel,
read_feather as read_feather,
read_fwf as read_fwf,
read_hdf as read_hdf,
read_html as read_html,
read_json as read_json,
read_orc as read_orc,
read_parquet as read_parquet,
read_pickle as read_pickle,
read_sas as read_sas,
Expand All @@ -118,6 +116,12 @@ from pandas.io.api import (
read_table as read_table,
read_xml as read_xml,
)
from pandas.io.api import (
read_excel as read_excel, # pyright: ignore[reportUnknownVariableType]
)
from pandas.io.api import (
read_orc as read_orc, # pyright: ignore[reportUnknownVariableType]
)
from pandas.io.json._normalize import json_normalize as json_normalize
from pandas.tseries import offsets as offsets
from pandas.tseries.api import infer_freq as infer_freq
Expand Down
8 changes: 4 additions & 4 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@overload
def sort_values(
self,
by: _str | Sequence[_str],
by: _str | SequenceNotStr[_str],
*,
axis: Axis = 0,
ascending: _bool | Sequence[_bool] = ...,
Expand All @@ -1096,7 +1096,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@overload
def sort_values(
self,
by: _str | Sequence[_str],
by: _str | SequenceNotStr[_str],
*,
axis: Axis = 0,
ascending: _bool | Sequence[_bool] = ...,
Expand Down Expand Up @@ -1303,7 +1303,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@overload
def groupby( # type: ignore[overload-overlap] # pyright: ignore reportOverlappingOverload
self,
by: MultiIndex | GroupByObjectNonScalar | None = ...,
by: MultiIndex | GroupByObjectNonScalar[Any] | None = ...,
level: IndexLabel | None = ...,
as_index: Literal[True] = True,
sort: _bool = ...,
Expand All @@ -1314,7 +1314,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@overload
def groupby( # type: ignore[overload-overlap]
self,
by: MultiIndex | GroupByObjectNonScalar | None = ...,
by: MultiIndex | GroupByObjectNonScalar[Any] | None = ...,
level: IndexLabel | None = ...,
as_index: Literal[False] = False,
sort: _bool = ...,
Expand Down
10 changes: 7 additions & 3 deletions pandas-stubs/io/api.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ from pandas.io.clipboards import read_clipboard as read_clipboard
from pandas.io.excel import (
ExcelFile as ExcelFile,
ExcelWriter as ExcelWriter,
read_excel as read_excel,
)
from pandas.io.excel import (
read_excel as read_excel, # pyright: ignore[reportUnknownVariableType]
)
from pandas.io.feather_format import read_feather as read_feather
from pandas.io.html import read_html as read_html
from pandas.io.json import read_json as read_json
from pandas.io.orc import read_orc as read_orc
from pandas.io.orc import (
read_orc as read_orc, # pyright: ignore[reportUnknownVariableType]
)
from pandas.io.parquet import read_parquet as read_parquet
from pandas.io.parsers import (
from pandas.io.parsers.readers import (
read_csv as read_csv,
read_fwf as read_fwf,
read_table as read_table,
Expand Down
6 changes: 3 additions & 3 deletions pandas-stubs/io/clipboards.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def read_clipboard(
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: UsecolsArgType = ...,
usecols: UsecolsArgType[Any] = ...,
dtype: DtypeArg | defaultdict[Any, Any] | None = ...,
engine: CSVEngine | None = ...,
converters: dict[int | str, Callable[[str], Any]] = ...,
Expand Down Expand Up @@ -94,7 +94,7 @@ def read_clipboard(
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: UsecolsArgType = ...,
usecols: UsecolsArgType[Any] = ...,
dtype: DtypeArg | defaultdict[Any, Any] | None = ...,
engine: CSVEngine | None = ...,
converters: dict[int | str, Callable[[str], Any]] = ...,
Expand Down Expand Up @@ -153,7 +153,7 @@ def read_clipboard(
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: UsecolsArgType = ...,
usecols: UsecolsArgType[Any] = ...,
dtype: DtypeArg | defaultdict[Any, Any] | None = ...,
engine: CSVEngine | None = ...,
converters: dict[int | str, Callable[[str], Any]] = ...,
Expand Down
4 changes: 3 additions & 1 deletion pandas-stubs/io/excel/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from pandas.io.excel._base import (
ExcelFile as ExcelFile,
ExcelWriter as ExcelWriter,
read_excel as read_excel,
)
from pandas.io.excel._base import (
read_excel as read_excel, # pyright: ignore[reportUnknownVariableType]
)
17 changes: 10 additions & 7 deletions pandas-stubs/io/excel/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ from typing import (
overload,
)

from odf.opendocument import OpenDocument # pyright: ignore[reportMissingTypeStubs]
from openpyxl.workbook.workbook import Workbook
from pandas.core.frame import DataFrame
import pyxlsb.workbook # pyright: ignore[reportMissingTypeStubs]
Expand Down Expand Up @@ -43,6 +42,10 @@ from pandas._typing import (
UsecolsArgType,
)

from odf.opendocument import ( # pyright: ignore[reportMissingTypeStubs] # isort: skip
OpenDocument, # pyright: ignore[reportUnknownVariableType]
)

@overload
def read_excel(
io: (
Expand All @@ -59,7 +62,7 @@ def read_excel(
header: int | Sequence[int] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | Sequence[int] | str | None = ...,
usecols: str | UsecolsArgType = ...,
usecols: str | UsecolsArgType[Any] = ...,
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
engine: ExcelReadEngine | None = ...,
converters: Mapping[int | str, Callable[[Any], Any]] | None = ...,
Expand Down Expand Up @@ -102,7 +105,7 @@ def read_excel(
header: int | Sequence[int] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | Sequence[int] | str | None = ...,
usecols: str | UsecolsArgType = ...,
usecols: str | UsecolsArgType[Any] = ...,
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
engine: ExcelReadEngine | None = ...,
converters: Mapping[int | str, Callable[[Any], Any]] | None = ...,
Expand Down Expand Up @@ -146,7 +149,7 @@ def read_excel( # type: ignore[overload-cannot-match]
header: int | Sequence[int] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | Sequence[int] | str | None = ...,
usecols: str | UsecolsArgType = ...,
usecols: str | UsecolsArgType[Any] = ...,
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
engine: ExcelReadEngine | None = ...,
converters: Mapping[int | str, Callable[[Any], Any]] | None = ...,
Expand Down Expand Up @@ -189,7 +192,7 @@ def read_excel(
header: int | Sequence[int] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | Sequence[int] | str | None = ...,
usecols: str | UsecolsArgType = ...,
usecols: str | UsecolsArgType[Any] = ...,
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
engine: ExcelReadEngine | None = ...,
converters: Mapping[int | str, Callable[[Any], Any]] | None = ...,
Expand Down Expand Up @@ -312,7 +315,7 @@ class ExcelFile:
header: int | Sequence[int] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | Sequence[int] | None = ...,
usecols: str | UsecolsArgType = ...,
usecols: str | UsecolsArgType[Any] = ...,
converters: dict[int | str, Callable[[Any], Any]] | None = ...,
true_values: Iterable[Hashable] | None = ...,
false_values: Iterable[Hashable] | None = ...,
Expand Down Expand Up @@ -340,7 +343,7 @@ class ExcelFile:
header: int | Sequence[int] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | Sequence[int] | None = ...,
usecols: str | UsecolsArgType = ...,
usecols: str | UsecolsArgType[Any] = ...,
converters: dict[int | str, Callable[[Any], Any]] | None = ...,
true_values: Iterable[Hashable] | None = ...,
false_values: Iterable[Hashable] | None = ...,
Expand Down
5 changes: 4 additions & 1 deletion pandas-stubs/io/orc.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any

from fsspec.spec import AbstractFileSystem # pyright: ignore[reportMissingTypeStubs]
from pandas import DataFrame
from pyarrow.fs import FileSystem

Expand All @@ -12,6 +11,10 @@ from pandas._typing import (
ReadBuffer,
)

from fsspec.spec import ( # pyright: ignore[reportMissingTypeStubs] # isort: skip
AbstractFileSystem, # pyright: ignore[reportUnknownVariableType]
)

def read_orc(
path: FilePath | ReadBuffer[bytes],
columns: list[HashableT] | None = None,
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ reportUnknownArgumentType = false
reportUnknownLambdaType = false
reportUnknownMemberType = false
reportUnknownParameterType = false
reportUnknownVariableType = false
reportPrivateUsage = false
# enable optional checks
reportMissingModuleSource = true
Expand Down
17 changes: 11 additions & 6 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,19 @@ def check(
if dtype is None:
return actual

value: Any
if isinstance(actual, pd.Series):
value = actual.iloc[index_to_check_for_type]
value = actual.iloc[ # pyright: ignore[reportUnknownVariableType]
index_to_check_for_type
]
elif isinstance(actual, pd.Index):
value = actual[index_to_check_for_type]
value = actual[ # pyright: ignore[reportUnknownVariableType]
index_to_check_for_type
]
elif isinstance(actual, BaseGroupBy):
value = actual.obj # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue]
value = actual.obj # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportUnknownVariableType]
elif hasattr(actual, "__iter__"):
value = next(
value = next( # pyright: ignore[reportUnknownVariableType]
iter(actual) # pyright: ignore[reportArgumentType,reportCallIssue]
)
else:
Expand All @@ -151,7 +156,7 @@ def check(

if not isinstance(value, dtype):
raise RuntimeError(f"Expected type '{dtype}' but got '{type(value)}'")
return actual
return actual # pyright: ignore[reportUnknownVariableType]


def pytest_warns_bounded(
Expand All @@ -161,7 +166,7 @@ def pytest_warns_bounded(
upper: str | None = None,
version_str: str | None = None,
upper_exception: type[Exception] | None = None,
) -> AbstractContextManager[Any]:
) -> AbstractContextManager[Any, bool | None]:
"""
Version conditional pytest.warns context manager

Expand Down
1 change: 1 addition & 0 deletions tests/arrays/test_extension_array.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Test common ExtensionArray methods

import numpy as np
import pandas as pd
from pandas.core.arrays import ExtensionArray
Expand Down
22 changes: 13 additions & 9 deletions tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,19 @@ def __array_ufunc__(
return NotImplemented

if "out" in kwargs:
return arraylike.dispatch_ufunc_with_out( # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue]
return arraylike.dispatch_ufunc_with_out( # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportUnknownVariableType]
self, ufunc, method, *inputs, **kwargs
)

inputs = tuple(x._data if isinstance(x, DecimalArray) else x for x in inputs)
result = getattr(ufunc, method)(*inputs, **kwargs)

if method == "reduce":
result = arraylike.dispatch_reduction_ufunc( # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue]
result = arraylike.dispatch_reduction_ufunc( # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportUnknownVariableType]
self, ufunc, method, *inputs, **kwargs
)
if result is not NotImplemented:
return result
return result # pyright: ignore[reportUnknownVariableType]

def reconstruct(
x: (
Expand All @@ -199,16 +199,18 @@ def reconstruct(
return DecimalArray._from_sequence(x)

if ufunc.nout > 1:
return tuple(reconstruct(x) for x in result)
return tuple(
reconstruct(x)
for x in result # pyright: ignore[reportUnknownVariableType]
)
return reconstruct(result)

def __getitem__(self, item: ScalarIndexer | SequenceIndexer) -> Any:
if isinstance(item, numbers.Integral):
return self._data[item]
# array, slice.
item = check_array_indexer(
self,
item, # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue]
item = check_array_indexer( # pyright: ignore[reportCallIssue,reportUnknownVariableType]
self, item # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
)
return type(self)(self._data[item])

Expand Down Expand Up @@ -347,10 +349,12 @@ def convert_values(param: Any) -> ExtensionArray | list[Any]:

def value_counts(self, dropna: bool = True) -> Series:
from pandas.core.algorithms import ( # type: ignore[attr-defined] # isort: skip
value_counts, # pyright: ignore[reportAttributeAccessIssue]
value_counts, # pyright: ignore[reportAttributeAccessIssue,reportAttributeAccessIssue,reportUnknownVariableType]
)

return value_counts(self.to_numpy(), dropna=dropna)
return value_counts(
self.to_numpy(), dropna=dropna
) # pyright: ignore[reportUnknownVariableType]

@classmethod
def _add_arithmetic_ops(cls) -> None: ...
Expand Down
Loading
Loading