Skip to content

Commit 4854107

Browse files
committed
MAINT: Merge main
2 parents 805cf98 + 426e31d commit 4854107

File tree

11 files changed

+120
-47
lines changed

11 files changed

+120
-47
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
python-version: ${{ matrix.python-version }}
2323

2424
- name: Install Poetry
25-
run: pip install poetry==1.1.15
25+
run: pip install poetry
2626

2727
- name: Determine poetry version
2828
run: echo "::set-output name=VERSION::$(poetry --version)"

pandas-stubs/_typing.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ IndexingInt = Union[
170170
# passed in, a DataFrame is always returned.
171171
NDFrameT = TypeVar("NDFrameT", bound=NDFrame)
172172

173+
IndexT = TypeVar("IndexT", bound=Index)
174+
173175
# Interval closed type
174176

175177
IntervalClosedType = Literal["left", "right", "both", "neither"]
@@ -240,5 +242,6 @@ CSVEngine = Literal["c", "python", "pyarrow", "python-fwf"]
240242

241243
HDFCompLib = Literal["zlib", "lzo", "bzip2", "blosc"]
242244
ParquetEngine = Literal["auto", "pyarrow", "fastparquet"]
245+
ColspaceArgType = str | int | Sequence[int | str] | Mapping[Hashable, str | int]
243246

244247
__all__ = ["npt", "type_t"]

pandas-stubs/core/frame.pyi

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ from pandas._typing import (
4949
Axes,
5050
Axis,
5151
AxisType,
52+
ColspaceArgType,
5253
CompressionOptions,
5354
Dtype,
5455
DtypeNp,
@@ -328,23 +329,39 @@ class DataFrame(NDFrame, OpsMixin):
328329
@overload
329330
def to_html(
330331
self,
331-
buf: FilePathOrBuffer | None,
332-
columns: Sequence[_str] | None = ...,
333-
col_space: int | list[int] | dict[_str | int, int] | None = ...,
332+
buf: FilePath | WriteBuffer[str],
333+
columns: list[HashableT] | None = ...,
334+
col_space: ColspaceArgType | None = ...,
334335
header: _bool = ...,
335336
index: _bool = ...,
336337
na_rep: _str = ...,
337-
formatters=...,
338-
float_format=...,
338+
formatters: list[Callable[[object], str]]
339+
| tuple[Callable[[object], str], ...]
340+
| Mapping[Hashable, Callable[[object], str]]
341+
| None = ...,
342+
float_format: Callable[[float], str] | None = ...,
339343
sparsify: _bool | None = ...,
340344
index_names: _bool = ...,
341-
justify: _str | None = ...,
345+
justify: Literal[
346+
"left",
347+
"right",
348+
"center",
349+
"justify",
350+
"justify-all",
351+
"start",
352+
"end",
353+
"inherit",
354+
"match-parent",
355+
"initial",
356+
"unset",
357+
]
358+
| None = ...,
342359
max_rows: int | None = ...,
343360
max_cols: int | None = ...,
344361
show_dimensions: _bool = ...,
345362
decimal: _str = ...,
346363
bold_rows: _bool = ...,
347-
classes: _str | list | tuple | None = ...,
364+
classes: Sequence[str] | None = ...,
348365
escape: _bool = ...,
349366
notebook: _bool = ...,
350367
border: int | None = ...,
@@ -355,22 +372,39 @@ class DataFrame(NDFrame, OpsMixin):
355372
@overload
356373
def to_html(
357374
self,
358-
columns: Sequence[_str] | None = ...,
359-
col_space: int | list[int] | dict[_str | int, int] | None = ...,
375+
buf: None = ...,
376+
columns: Sequence[HashableT] | None = ...,
377+
col_space: ColspaceArgType | None = ...,
360378
header: _bool = ...,
361379
index: _bool = ...,
362380
na_rep: _str = ...,
363-
formatters=...,
364-
float_format=...,
381+
formatters: list[Callable[[object], str]]
382+
| tuple[Callable[[object], str], ...]
383+
| Mapping[Hashable, Callable[[object], str]]
384+
| None = ...,
385+
float_format: Callable[[float], str] | None = ...,
365386
sparsify: _bool | None = ...,
366387
index_names: _bool = ...,
367-
justify: _str | None = ...,
388+
justify: Literal[
389+
"left",
390+
"right",
391+
"center",
392+
"justify",
393+
"justify-all",
394+
"start",
395+
"end",
396+
"inherit",
397+
"match-parent",
398+
"initial",
399+
"unset",
400+
]
401+
| None = ...,
368402
max_rows: int | None = ...,
369403
max_cols: int | None = ...,
370404
show_dimensions: _bool = ...,
371405
decimal: _str = ...,
372406
bold_rows: _bool = ...,
373-
classes: _str | list | tuple | None = ...,
407+
classes: Sequence[str] | None = ...,
374408
escape: _bool = ...,
375409
notebook: _bool = ...,
376410
border: int | None = ...,

pandas-stubs/core/generic.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ from pandas._typing import (
2929
HDFCompLib,
3030
IgnoreRaise,
3131
Level,
32+
NDFrameT,
3233
ReplaceMethod,
3334
Scalar,
3435
SeriesAxisType,
@@ -69,8 +70,8 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
6970
def pop(self, item: _str) -> NDFrame: ...
7071
def squeeze(self, axis=...): ...
7172
def equals(self, other: Series[S1]) -> _bool: ...
72-
def __neg__(self) -> None: ...
73-
def __pos__(self) -> None: ...
73+
def __neg__(self: NDFrameT) -> NDFrameT: ...
74+
def __pos__(self: NDFrameT) -> NDFrameT: ...
7475
def __nonzero__(self) -> None: ...
7576
def bool(self) -> _bool: ...
7677
def __abs__(self) -> NDFrame: ...

pandas-stubs/core/indexes/base.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ from pandas._typing import (
2727
Dtype,
2828
DtypeArg,
2929
DtypeObj,
30+
IndexT,
3031
Label,
3132
Level,
3233
NaPosition,
@@ -142,11 +143,12 @@ class Index(IndexOpsMixin, PandasObject):
142143
def __and__(self, other) -> Index: ...
143144
def __or__(self, other) -> Index: ...
144145
def __xor__(self, other) -> Index: ...
146+
def __neg__(self: IndexT) -> IndexT: ...
145147
def __nonzero__(self) -> None: ...
146148
__bool__ = ...
147149
def union(self, other: list[T1] | Index, sort=...) -> Index: ...
148150
def intersection(self, other: list[T1] | Index, sort: bool = ...) -> Index: ...
149-
def difference(self, other: list[T1 | None] | Index) -> Index: ...
151+
def difference(self, other: list | Index) -> Index: ...
150152
def symmetric_difference(
151153
self, other: list[T1] | Index, result_name=..., sort=...
152154
) -> Index: ...

pandas-stubs/io/html.pyi

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
11
from typing import (
22
Any,
33
Callable,
4-
Iterable,
4+
Hashable,
5+
Literal,
56
Mapping,
7+
Pattern,
68
Sequence,
79
)
810

911
from pandas.core.frame import DataFrame
1012

11-
from pandas._typing import FilePathOrBuffer
12-
13-
class _HtmlFrameParser:
14-
io = ...
15-
match = ...
16-
attrs = ...
17-
encoding = ...
18-
displayed_only = ...
19-
def __init__(self, io, match, attrs, encoding, displayed_only) -> None: ...
20-
def parse_tables(self): ...
21-
22-
class _BeautifulSoupHtml5LibFrameParser(_HtmlFrameParser):
23-
def __init__(self, *args, **kwargs) -> None: ...
24-
25-
class _LxmlFrameParser(_HtmlFrameParser):
26-
def __init__(self, *args, **kwargs) -> None: ...
13+
from pandas._typing import (
14+
FilePath,
15+
HashableT,
16+
ReadBuffer,
17+
)
2718

2819
def read_html(
29-
io: FilePathOrBuffer,
30-
match: str = ...,
20+
io: FilePath | ReadBuffer[str],
21+
match: str | Pattern = ...,
3122
flavor: str | None = ...,
3223
header: int | Sequence[int] | None = ...,
33-
index_col: int | Sequence[Any] | None = ...,
34-
skiprows: int | Sequence[Any] | slice | None = ...,
35-
attrs: Mapping[str, str] | None = ...,
24+
index_col: int | Sequence[int] | list[HashableT] | None = ...,
25+
skiprows: int | Sequence[int] | slice | None = ...,
26+
attrs: dict[str, str] | None = ...,
3627
parse_dates: bool
37-
| Sequence[int | str | Sequence[int | str]]
38-
| dict[str, Sequence[int | str]] = ...,
28+
| Sequence[int]
29+
| list[HashableT] # Cannot be Sequence[Hashable] to prevent str
30+
| Sequence[Sequence[Hashable]]
31+
| dict[str, Sequence[int]]
32+
| dict[str, list[HashableT]] = ...,
3933
thousands: str = ...,
4034
encoding: str | None = ...,
4135
decimal: str = ...,
42-
converters: Mapping[int | str, Callable] | None = ...,
43-
na_values: Iterable[Any] | None = ...,
36+
converters: Mapping[int | HashableT, Callable[[str], Any]] | None = ...,
37+
na_values: str
38+
| list[str]
39+
| dict[HashableT, str]
40+
| dict[HashableT, list[str]]
41+
| None = ...,
4442
keep_default_na: bool = ...,
4543
displayed_only: bool = ...,
44+
extract_links: Literal["header", "footer", "body", "all"] | None = ...,
4645
) -> list[DataFrame]: ...

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mypy = ">=0.971"
3939
pyarrow = ">=9.0.0"
4040
pytest = ">=7.1.2"
4141
pyright = ">=1.1.266"
42-
poethepoet = ">=0.13.1"
42+
poethepoet = "0.16.0"
4343
loguru = ">=0.6.0"
4444
pandas = "1.4.3"
4545
typing-extensions = ">=4.2.0"

tests/test_frame.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,3 +1685,15 @@ def func() -> MyDataFrame[int]:
16851685
return MyDataFrame[int]({"foo": [1, 2, 3]})
16861686

16871687
func()
1688+
1689+
1690+
def test_neg() -> None:
1691+
# GH 253
1692+
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
1693+
check(assert_type(-df, pd.DataFrame), pd.DataFrame)
1694+
1695+
1696+
def test_pos() -> None:
1697+
# GH 253
1698+
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
1699+
check(assert_type(+df, pd.DataFrame), pd.DataFrame)

tests/test_indexes.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010

1111
def test_index_unique() -> None:
12-
1312
df = pd.DataFrame({"x": [1, 2, 3, 4]}, index=pd.Index([1, 2, 3, 2]))
1413
ind = df.index
1514
check(assert_type(ind, pd.Index), pd.Index)
@@ -67,7 +66,9 @@ def test_column_contains() -> None:
6766
def test_difference_none() -> None:
6867
# https://github.com/pandas-dev/pandas-stubs/issues/17
6968
ind = pd.Index([1, 2, 3])
70-
check(assert_type(ind.difference([1, None]), "pd.Index"), pd.Index, int)
69+
check(assert_type(ind.difference([1, None]), pd.Index), pd.Index)
70+
# GH 253
71+
check(assert_type(ind.difference([1]), pd.Index), pd.Index)
7172

7273

7374
def test_str_split() -> None:
@@ -87,3 +88,9 @@ def test_index_dropna():
8788

8889
check(assert_type(midx.dropna(how="all"), pd.MultiIndex), pd.MultiIndex)
8990
check(assert_type(midx.dropna(how="any"), pd.MultiIndex), pd.MultiIndex)
91+
92+
93+
def test_index_neg():
94+
# GH 253
95+
idx = pd.Index([1, 2])
96+
check(assert_type(-idx, pd.Index), pd.Index)

tests/test_io.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import io
2-
import os
32
import os.path
43
import pathlib
54
from pathlib import Path
@@ -18,6 +17,7 @@
1817
read_clipboard,
1918
read_feather,
2019
read_hdf,
20+
read_html,
2121
read_json,
2222
read_orc,
2323
read_parquet,
@@ -348,3 +348,10 @@ def test_to_string():
348348
check(assert_type(DF.to_string(df_string), None), type(None))
349349
sio = io.StringIO()
350350
check(assert_type(DF.to_string(sio), None), type(None))
351+
352+
353+
def test_read_html():
354+
check(assert_type(DF.to_html(), str), str)
355+
with ensure_clean() as path:
356+
check(assert_type(DF.to_html(path), None), type(None))
357+
check(assert_type(read_html(path), List[DataFrame]), list)

tests/test_series.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,3 +1124,11 @@ def test_resample() -> None:
11241124
check(assert_type(df.resample("2T").sem(), pd.Series), pd.Series)
11251125
check(assert_type(df.resample("2T").median(), pd.Series), pd.Series)
11261126
check(assert_type(df.resample("2T").ohlc(), pd.DataFrame), pd.DataFrame)
1127+
1128+
1129+
def test_neg() -> None:
1130+
# GH 253
1131+
sr = pd.Series([1, 2, 3])
1132+
sr_int = pd.Series([1, 2, 3], dtype=int)
1133+
check(assert_type(-sr, pd.Series), pd.Series)
1134+
check(assert_type(-sr_int, "pd.Series[int]"), pd.Series, int)

0 commit comments

Comments
 (0)