Skip to content

Commit 3e9efc1

Browse files
Merge branch 'main' of github.com:loicdiridollou/pandas-stubs into gh613_comment_ci
2 parents 4eaf6f0 + d2798db commit 3e9efc1

File tree

16 files changed

+212
-99
lines changed

16 files changed

+212
-99
lines changed

.github/setup/action.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
name: Install project dependencies
2+
description: Install project dependencies
23

34
inputs:
45
python-version:
6+
description: The python version to use
57
required: true
68
os:
7-
required: true
8-
numpy-version:
9+
description: The OS to run on
910
required: true
1011

1112
runs:
1213
using: composite
1314
steps:
14-
1515
- name: Set up Python
1616
uses: actions/setup-python@v4
1717
with:
@@ -35,7 +35,3 @@ runs:
3535
- name: Install project dependencies
3636
shell: bash
3737
run: poetry install -vvv --no-root
38-
39-
- name: Set numpy version
40-
shell: bash
41-
run: pip install numpy"${{ inputs. numpy-version }}"

.github/workflows/test.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@ jobs:
1919
matrix:
2020
# Don't use macos-latest because it is arm64
2121
os: [ubuntu-latest, windows-latest, macos-13]
22-
python-version: ["3.9", "3.10", "3.11", "3.12"]
23-
include:
24-
- numpy-version: "<2.0"
25-
- numpy-version: ">= 2.0"
26-
os: ubuntu-latest
22+
python-version: ["3.10", "3.11", "3.12"]
2723

28-
name: OS ${{ matrix.os }} - Python ${{ matrix.python-version }} - Numpy ${{ matrix.numpy-version }}
24+
name: OS ${{ matrix.os }} - Python ${{ matrix.python-version }}
2925

3026
steps:
3127
- uses: actions/checkout@v3
@@ -35,7 +31,6 @@ jobs:
3531
with:
3632
os: ${{ matrix.os }}
3733
python-version: ${{ matrix.python-version }}
38-
numpy-version: ${{ matrix.numpy-version }}
3934

4035
- name: Run mypy on 'tests' (using the local stubs) and on the local stubs
4136
run: poetry run poe mypy

conftest.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import gc
2+
3+
import pytest
4+
5+
6+
@pytest.fixture
7+
def mpl_cleanup():
8+
"""
9+
Ensure Matplotlib is cleaned up around a test.
10+
11+
Before a test is run:
12+
13+
1) Set the backend to "template" to avoid requiring a GUI.
14+
15+
After a test is run:
16+
17+
1) Reset units registry
18+
2) Reset rc_context
19+
3) Close all figures
20+
21+
See matplotlib/testing/decorators.py#L24.
22+
"""
23+
mpl = pytest.importorskip("matplotlib")
24+
mpl_units = pytest.importorskip("matplotlib.units")
25+
plt = pytest.importorskip("matplotlib.pyplot")
26+
orig_units_registry = mpl_units.registry.copy()
27+
try:
28+
with mpl.rc_context():
29+
mpl.use("template")
30+
yield
31+
finally:
32+
mpl_units.registry.clear()
33+
mpl_units.registry.update(orig_units_registry)
34+
plt.close("all")
35+
# https://matplotlib.org/stable/users/prev_whats_new/whats_new_3.6.0.html#garbage-collection-is-no-longer-run-on-figure-close
36+
gc.collect(1)

docs/release_procedure.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77

88
```shell
99
rm dist/*
10-
poetry publish --build # you will get prompted for your pypi username/password
10+
poetry build
11+
twine upload dist/* # Requires having the pypi API token allowing uploads
1112
git commit -a -m "Version a.b.c.yymmdd"
1213
git push upstream main
1314
git tag va.b.c.yymmdd
1415
git push upstream --tags
1516
```
1617

1718
The conda bots will recognize that a new version has been uploaded to pypi, and generate a pull request sent to the maintainers to approve it.
18-
19-
Note - Changes will need to be made to use pypi API tokens in the near future.

docs/setup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Set Up Environment
22

3-
- Make sure you have `python >= 3.9` installed.
4-
- Install poetry: `pip install 'poetry>=1.2'`
3+
- Make sure you have `python >= 3.10` installed.
4+
- Install poetry: `pip install 'poetry>=1.8'`
55
- Install the project dependencies: `poetry update`
66
- Enter the virtual environment: `poetry shell`
77
- Run all tests: `poe test_all`

pandas-stubs/_testing/__init__.pyi

Lines changed: 95 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,117 @@
1-
from collections.abc import Generator
1+
from collections.abc import (
2+
Container,
3+
Generator,
4+
Iterable,
5+
)
26
from contextlib import contextmanager
37
from typing import (
48
Any,
59
Literal,
610
overload,
711
)
12+
import warnings
813

14+
from matplotlib.artist import Artist
15+
import numpy as np
916
from pandas import (
17+
Categorical,
1018
DataFrame,
1119
Index,
1220
Series,
1321
)
22+
from pandas.arrays import (
23+
DatetimeArray,
24+
IntervalArray,
25+
PeriodArray,
26+
SparseArray,
27+
TimedeltaArray,
28+
)
29+
from pandas.core.arrays.base import ExtensionArray
30+
31+
from pandas._typing import (
32+
AnyArrayLike,
33+
T,
34+
)
1435

1536
def assert_almost_equal(
16-
left,
17-
right,
18-
check_dtype: bool | str = ...,
19-
check_less_precise: bool | int = ...,
37+
left: T,
38+
right: T,
39+
check_dtype: bool | Literal["equiv"] = ...,
40+
rtol: float = ...,
41+
atol: float = ...,
2042
**kwargs,
21-
): ...
22-
def assert_dict_equal(left, right, compare_keys: bool = ...): ...
23-
def assert_index_equal(left: Index, right: Index) -> None: ...
24-
def assert_class_equal(left, right, exact: bool | str = ..., obj=...): ...
25-
def assert_attr_equal(attr, left, right, obj: str = ...): ...
26-
def assert_is_valid_plot_return_object(objs) -> None: ...
27-
def assert_is_sorted(seq) -> None: ...
43+
) -> None: ...
44+
def assert_dict_equal(left: dict, right: dict, compare_keys: bool = ...) -> None: ...
45+
def assert_index_equal(
46+
left: Index,
47+
right: Index,
48+
exact: bool | Literal["equiv"] = ...,
49+
check_names: bool = ...,
50+
check_exact: bool = ...,
51+
check_categorical: bool = ...,
52+
check_order: bool = ...,
53+
rtol: float = ...,
54+
atol: float = ...,
55+
obj: str = ...,
56+
) -> None: ...
57+
def assert_class_equal(
58+
left: T, right: T, exact: bool | Literal["equiv"] = ..., obj: str = ...
59+
) -> None: ...
60+
def assert_attr_equal(
61+
attr: str, left: object, right: object, obj: str = ...
62+
) -> None: ...
63+
def assert_is_valid_plot_return_object(
64+
objs: Series | np.ndarray | Artist | tuple | dict,
65+
) -> None: ...
66+
def assert_is_sorted(seq: AnyArrayLike) -> None: ...
2867
def assert_categorical_equal(
29-
left,
30-
right,
68+
left: Categorical,
69+
right: Categorical,
3170
check_dtype: bool = ...,
3271
check_category_order: bool = ...,
3372
obj: str = ...,
3473
) -> None: ...
3574
def assert_interval_array_equal(
36-
left, right, exact: str = ..., obj: str = ...
75+
left: IntervalArray,
76+
right: IntervalArray,
77+
exact: bool | Literal["equiv"] = ...,
78+
obj: str = ...,
79+
) -> None: ...
80+
def assert_period_array_equal(
81+
left: PeriodArray, right: PeriodArray, obj: str = ...
82+
) -> None: ...
83+
def assert_datetime_array_equal(
84+
left: DatetimeArray, right: DatetimeArray, check_freq: bool = ...
85+
) -> None: ...
86+
def assert_timedelta_array_equal(
87+
left: TimedeltaArray, right: TimedeltaArray, check_freq: bool = ...
3788
) -> None: ...
38-
def assert_period_array_equal(left, right, obj: str = ...) -> None: ...
39-
def assert_datetime_array_equal(left, right, obj: str = ...) -> None: ...
40-
def assert_timedelta_array_equal(left, right, obj: str = ...) -> None: ...
4189
def assert_numpy_array_equal(
4290
left,
4391
right,
4492
strict_nan: bool = ...,
45-
check_dtype: bool = ...,
46-
err_msg=...,
47-
check_same=...,
93+
check_dtype: bool | Literal["equiv"] = ...,
94+
err_msg: str | None = ...,
95+
check_same: Literal["copy", "same"] | None = ...,
4896
obj: str = ...,
49-
): ...
97+
index_values: Index | np.ndarray | None = ...,
98+
) -> None: ...
5099
def assert_extension_array_equal(
51-
left,
52-
right,
53-
check_dtype: bool = ...,
54-
check_less_precise: bool = ...,
100+
left: ExtensionArray,
101+
right: ExtensionArray,
102+
check_dtype: bool | Literal["equiv"] = ...,
103+
index_values: Index | np.ndarray | None = ...,
55104
check_exact: bool = ...,
105+
rtol: float = ...,
106+
atol: float = ...,
107+
obj: str = ...,
56108
) -> None: ...
57109
@overload
58110
def assert_series_equal(
59111
left: Series,
60112
right: Series,
61-
check_dtype: bool = ...,
62-
check_index_type: bool | str = ...,
113+
check_dtype: bool | Literal["equiv"] = ...,
114+
check_index_type: bool | Literal["equiv"] = ...,
63115
check_series_type: bool = ...,
64116
check_names: bool = ...,
65117
check_exact: bool = ...,
@@ -79,8 +131,8 @@ def assert_series_equal(
79131
def assert_series_equal(
80132
left: Series,
81133
right: Series,
82-
check_dtype: bool = ...,
83-
check_index_type: bool | str = ...,
134+
check_dtype: bool | Literal["equiv"] = ...,
135+
check_index_type: bool | Literal["equiv"] = ...,
84136
check_series_type: bool = ...,
85137
check_names: bool = ...,
86138
check_exact: bool = ...,
@@ -103,37 +155,34 @@ def assert_frame_equal(
103155
check_index_type: bool | Literal["equiv"] = ...,
104156
check_column_type: bool | Literal["equiv"] = ...,
105157
check_frame_type: bool = ...,
106-
check_less_precise: int | bool = ...,
107158
check_names: bool = ...,
108159
by_blocks: bool = ...,
109160
check_exact: bool = ...,
110161
check_datetimelike_compat: bool = ...,
111162
check_categorical: bool = ...,
112163
check_like: bool = ...,
113164
check_freq: bool = ...,
114-
check_flag: bool = ...,
165+
check_flags: bool = ...,
115166
rtol: float = ...,
116167
atol: float = ...,
117168
obj: str = ...,
118169
) -> None: ...
119170
def assert_equal(left, right, **kwargs) -> None: ...
120-
def assert_sp_array_equal(
121-
left,
122-
right,
123-
check_dtype: bool = ...,
124-
check_kind: bool = ...,
125-
check_fill_value: bool = ...,
126-
consolidate_block_indices: bool = ...,
127-
) -> None: ...
128-
def assert_contains_all(iterable, dic) -> None: ...
129-
def assert_copy(iter1, iter2, **eql_kwargs) -> None: ...
171+
def assert_sp_array_equal(left: SparseArray, right: SparseArray) -> None: ...
172+
def assert_contains_all(iterable: Iterable[T], dic: Container[T]) -> None: ...
173+
def assert_copy(iter1: Iterable[T], iter2: Iterable[T], **eql_kwargs) -> None: ...
174+
@contextmanager
130175
def assert_produces_warning(
131-
expected_warning=...,
132-
filter_level: str = ...,
133-
clear=...,
176+
expected_warning: (
177+
type[Warning] | Literal[False] | tuple[type[Warning], ...] | None
178+
) = ...,
179+
filter_level: Literal[
180+
"error", "ignore", "always", "default", "module", "once"
181+
] = ...,
134182
check_stacklevel: bool = ...,
135183
raise_on_extra_warnings: bool = ...,
136-
) -> None: ...
184+
match: str | None = None,
185+
) -> Generator[list[warnings.WarningMessage], None, None]: ...
137186
@contextmanager
138187
def ensure_clean(
139188
filename: str | None = ..., return_filelike: bool = ..., **kwargs: Any

pandas-stubs/core/dtypes/base.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ExtensionDtype:
1616
@property
1717
def kind(
1818
self,
19-
) -> Literal["b", "i", "u", "f", "c", "m", "M", "O", "S", "U", "V"]: ...
19+
) -> Literal["b", "i", "u", "f", "c", "m", "M", "O", "S", "U", "V", "T"]: ...
2020
@property
2121
def names(self) -> list[str] | None: ...
2222
def empty(self, size: int | tuple[int, ...]) -> type_t[ExtensionArray]: ...

pandas-stubs/core/frame.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class DataFrame(NDFrame, OpsMixin):
259259
def __dataframe__(
260260
self, nan_as_null: bool = ..., allow_copy: bool = ...
261261
) -> DataFrameXchg: ...
262+
def __arrow_c_stream__(self, requested_schema: object | None = None) -> object: ...
262263
@property
263264
def axes(self) -> list[Index]: ...
264265
@property
@@ -1632,8 +1633,8 @@ class DataFrame(NDFrame, OpsMixin):
16321633
) -> DataFrame: ...
16331634
def clip(
16341635
self,
1635-
lower: float | None = ...,
1636-
upper: float | None = ...,
1636+
lower: float | AnyArrayLike | None = ...,
1637+
upper: float | AnyArrayLike | None = ...,
16371638
*,
16381639
axis: Axis | None = ...,
16391640
inplace: _bool = ...,

pandas-stubs/core/indexes/datetimelike.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DatetimeIndexOpsMixin(ExtensionIndex[S1]):
1919
def argmin(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
2020
def max(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
2121
def argmax(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
22-
def __rsub__( # type: ignore[override]
22+
def __rsub__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
2323
self, other: DatetimeIndexOpsMixin
2424
) -> TimedeltaIndex: ...
2525

0 commit comments

Comments
 (0)