Skip to content

Commit f8b06e1

Browse files
authored
Support Numpy 2.1 (#981)
* Revert "remove pyright overrides not needed with pyright 1.1.374 (#967)" This reverts commit 458ecb4. * fix matplotlib tests for Windows 11 * lock numpy up to 2.0.1 * Support numpy 2.1. Remove python 3.9 support. Update docs
1 parent 9c20865 commit f8b06e1

File tree

8 files changed

+41
-33
lines changed

8 files changed

+41
-33
lines changed

.github/setup/action.yaml

+3-7
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

+2-7
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

docs/release_procedure.md

+2-3
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

+2-2
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/core/dtypes/base.pyi

+1-1
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]: ...

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ packages = [{ "include" = "pandas-stubs" }]
2828
"Documentation" = "https://pandas.pydata.org/pandas-docs/stable"
2929

3030
[tool.poetry.dependencies]
31-
python = ">=3.9"
31+
python = ">=3.10"
3232
types-pytz = ">= 2022.1.1"
33-
numpy = ">= 1.23.5, <= 2.0.1"
33+
numpy = ">= 1.23.5"
3434

3535
[tool.poetry.group.dev.dependencies]
3636
mypy = "1.10.1"

tests/test_scalars.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,8 @@ def test_timedelta_cmp() -> None:
879879
le = check(assert_type(c_dt_timedelta <= td, bool), bool)
880880
assert gt != le
881881

882-
gt_b = check(assert_type(c_timedelta64 > td, Any), bool)
883-
le_b = check(assert_type(c_timedelta64 <= td, Any), bool)
882+
gt_b = check(assert_type(c_timedelta64 > td, np.bool), bool)
883+
le_b = check(assert_type(c_timedelta64 <= td, np.bool), bool)
884884
assert gt_b != le_b
885885

886886
gt_a = check(
@@ -947,8 +947,8 @@ def test_timedelta_cmp() -> None:
947947
ge = check(assert_type(c_dt_timedelta >= td, bool), bool)
948948
assert lt != ge
949949

950-
lt_b = check(assert_type(c_timedelta64 < td, Any), bool)
951-
ge_b = check(assert_type(c_timedelta64 >= td, Any), bool)
950+
lt_b = check(assert_type(c_timedelta64 < td, np.bool), bool)
951+
ge_b = check(assert_type(c_timedelta64 >= td, np.bool), bool)
952952
assert lt_b != ge_b
953953

954954
lt_a = check(
@@ -1271,8 +1271,8 @@ def test_timestamp_cmp() -> None:
12711271
check(assert_type(ts > c_series_dt64, "pd.Series[bool]"), pd.Series, np.bool_)
12721272
check(assert_type(ts <= c_series_dt64, "pd.Series[bool]"), pd.Series, np.bool_)
12731273

1274-
check(assert_type(c_np_dt64 > ts, Any), bool)
1275-
check(assert_type(c_np_dt64 <= ts, Any), bool)
1274+
check(assert_type(c_np_dt64 > ts, np.bool), bool)
1275+
check(assert_type(c_np_dt64 <= ts, np.bool), bool)
12761276

12771277
gt = check(assert_type(c_dt_datetime > ts, bool), bool)
12781278
lte = check(assert_type(c_dt_datetime <= ts, bool), bool)
@@ -1315,8 +1315,8 @@ def test_timestamp_cmp() -> None:
13151315
lt = check(assert_type(c_dt_datetime < ts, bool), bool)
13161316
assert gte != lt
13171317

1318-
check(assert_type(c_np_dt64 >= ts, Any), bool)
1319-
check(assert_type(c_np_dt64 < ts, Any), bool)
1318+
check(assert_type(c_np_dt64 >= ts, np.bool), bool)
1319+
check(assert_type(c_np_dt64 < ts, np.bool), bool)
13201320

13211321
check(assert_type(c_datetimeindex >= ts, np_ndarray_bool), np.ndarray, np.bool_)
13221322
check(assert_type(c_datetimeindex < ts, np_ndarray_bool), np.ndarray, np.bool_)

tests/test_series.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
TYPE_CHECKING,
1616
Any,
1717
Generic,
18+
Literal,
1819
TypeVar,
1920
Union,
2021
cast,
@@ -81,6 +82,23 @@
8182
)
8283
from pandas._typing import np_ndarray_int # noqa: F401
8384

85+
# Tests will use numpy 2.1 in python 3.10 or later
86+
# From Numpy 2.1 __init__.pyi
87+
_DTypeKind: TypeAlias = Literal[
88+
"b", # boolean
89+
"i", # signed integer
90+
"u", # unsigned integer
91+
"f", # floating-point
92+
"c", # complex floating-point
93+
"m", # timedelta64
94+
"M", # datetime64
95+
"O", # python object
96+
"S", # byte-string (fixed-width)
97+
"U", # unicode-string (fixed-width)
98+
"V", # void
99+
"T", # unicode-string (variable-width)
100+
]
101+
84102

85103
def test_types_init() -> None:
86104
pd.Series(1)
@@ -1675,15 +1693,15 @@ def test_dtype_type() -> None:
16751693
# GH 216
16761694
s1 = pd.Series(["foo"], dtype="string")
16771695
check(assert_type(s1.dtype, DtypeObj), ExtensionDtype)
1678-
check(assert_type(s1.dtype.kind, str), str)
1696+
check(assert_type(s1.dtype.kind, _DTypeKind), str)
16791697

16801698
s2 = pd.Series([1], dtype="Int64")
16811699
check(assert_type(s2.dtype, DtypeObj), ExtensionDtype)
1682-
check(assert_type(s2.dtype.kind, str), str)
1700+
check(assert_type(s2.dtype.kind, _DTypeKind), str)
16831701

16841702
s3 = pd.Series([1, 2, 3])
16851703
check(assert_type(s3.dtype, DtypeObj), np.dtype)
1686-
check(assert_type(s3.dtype.kind, str), str)
1704+
check(assert_type(s3.dtype.kind, _DTypeKind), str)
16871705

16881706

16891707
def test_types_to_numpy() -> None:

0 commit comments

Comments
 (0)