Skip to content

Support Numpy 2.1 #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 20, 2024
Merged
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: 3 additions & 7 deletions .github/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: Install project dependencies
description: Install project dependencies

inputs:
python-version:
description: The python version to use
required: true
os:
required: true
numpy-version:
description: The OS to run on
required: true

runs:
using: composite
steps:

- name: Set up Python
uses: actions/setup-python@v4
with:
Expand All @@ -35,7 +35,3 @@ runs:
- name: Install project dependencies
shell: bash
run: poetry install -vvv --no-root

- name: Set numpy version
shell: bash
run: pip install numpy"${{ inputs. numpy-version }}"
9 changes: 2 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ jobs:
matrix:
# Don't use macos-latest because it is arm64
os: [ubuntu-latest, windows-latest, macos-13]
python-version: ["3.9", "3.10", "3.11", "3.12"]
include:
- numpy-version: "<2.0"
- numpy-version: ">= 2.0"
os: ubuntu-latest
python-version: ["3.10", "3.11", "3.12"]

name: OS ${{ matrix.os }} - Python ${{ matrix.python-version }} - Numpy ${{ matrix.numpy-version }}
name: OS ${{ matrix.os }} - Python ${{ matrix.python-version }}

steps:
- uses: actions/checkout@v3
Expand All @@ -35,7 +31,6 @@ jobs:
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
numpy-version: ${{ matrix.numpy-version }}

- name: Run mypy on 'tests' (using the local stubs) and on the local stubs
run: poetry run poe mypy
Expand Down
5 changes: 2 additions & 3 deletions docs/release_procedure.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

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

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.

Note - Changes will need to be made to use pypi API tokens in the near future.
4 changes: 2 additions & 2 deletions docs/setup.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Set Up Environment

- Make sure you have `python >= 3.9` installed.
- Install poetry: `pip install 'poetry>=1.2'`
- Make sure you have `python >= 3.10` installed.
- Install poetry: `pip install 'poetry>=1.8'`
- Install the project dependencies: `poetry update`
- Enter the virtual environment: `poetry shell`
- Run all tests: `poe test_all`
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/dtypes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ExtensionDtype:
@property
def kind(
self,
) -> Literal["b", "i", "u", "f", "c", "m", "M", "O", "S", "U", "V"]: ...
) -> Literal["b", "i", "u", "f", "c", "m", "M", "O", "S", "U", "V", "T"]: ...
@property
def names(self) -> list[str] | None: ...
def empty(self, size: int | tuple[int, ...]) -> type_t[ExtensionArray]: ...
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ packages = [{ "include" = "pandas-stubs" }]
"Documentation" = "https://pandas.pydata.org/pandas-docs/stable"

[tool.poetry.dependencies]
python = ">=3.9"
python = ">=3.10"
types-pytz = ">= 2022.1.1"
numpy = ">= 1.23.5, <= 2.0.1"
numpy = ">= 1.23.5"

[tool.poetry.group.dev.dependencies]
mypy = "1.10.1"
Expand Down
16 changes: 8 additions & 8 deletions tests/test_scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,8 @@ def test_timedelta_cmp() -> None:
le = check(assert_type(c_dt_timedelta <= td, bool), bool)
assert gt != le

gt_b = check(assert_type(c_timedelta64 > td, Any), bool)
le_b = check(assert_type(c_timedelta64 <= td, Any), bool)
gt_b = check(assert_type(c_timedelta64 > td, np.bool), bool)
le_b = check(assert_type(c_timedelta64 <= td, np.bool), bool)
assert gt_b != le_b

gt_a = check(
Expand Down Expand Up @@ -947,8 +947,8 @@ def test_timedelta_cmp() -> None:
ge = check(assert_type(c_dt_timedelta >= td, bool), bool)
assert lt != ge

lt_b = check(assert_type(c_timedelta64 < td, Any), bool)
ge_b = check(assert_type(c_timedelta64 >= td, Any), bool)
lt_b = check(assert_type(c_timedelta64 < td, np.bool), bool)
ge_b = check(assert_type(c_timedelta64 >= td, np.bool), bool)
assert lt_b != ge_b

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

check(assert_type(c_np_dt64 > ts, Any), bool)
check(assert_type(c_np_dt64 <= ts, Any), bool)
check(assert_type(c_np_dt64 > ts, np.bool), bool)
check(assert_type(c_np_dt64 <= ts, np.bool), bool)

gt = check(assert_type(c_dt_datetime > ts, bool), bool)
lte = check(assert_type(c_dt_datetime <= ts, bool), bool)
Expand Down Expand Up @@ -1315,8 +1315,8 @@ def test_timestamp_cmp() -> None:
lt = check(assert_type(c_dt_datetime < ts, bool), bool)
assert gte != lt

check(assert_type(c_np_dt64 >= ts, Any), bool)
check(assert_type(c_np_dt64 < ts, Any), bool)
check(assert_type(c_np_dt64 >= ts, np.bool), bool)
check(assert_type(c_np_dt64 < ts, np.bool), bool)

check(assert_type(c_datetimeindex >= ts, np_ndarray_bool), np.ndarray, np.bool_)
check(assert_type(c_datetimeindex < ts, np_ndarray_bool), np.ndarray, np.bool_)
Expand Down
24 changes: 21 additions & 3 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
TYPE_CHECKING,
Any,
Generic,
Literal,
TypeVar,
Union,
cast,
Expand Down Expand Up @@ -81,6 +82,23 @@
)
from pandas._typing import np_ndarray_int # noqa: F401

# Tests will use numpy 2.1 in python 3.10 or later
# From Numpy 2.1 __init__.pyi
_DTypeKind: TypeAlias = Literal[
"b", # boolean
"i", # signed integer
"u", # unsigned integer
"f", # floating-point
"c", # complex floating-point
"m", # timedelta64
"M", # datetime64
"O", # python object
"S", # byte-string (fixed-width)
"U", # unicode-string (fixed-width)
"V", # void
"T", # unicode-string (variable-width)
]


def test_types_init() -> None:
pd.Series(1)
Expand Down Expand Up @@ -1675,15 +1693,15 @@ def test_dtype_type() -> None:
# GH 216
s1 = pd.Series(["foo"], dtype="string")
check(assert_type(s1.dtype, DtypeObj), ExtensionDtype)
check(assert_type(s1.dtype.kind, str), str)
check(assert_type(s1.dtype.kind, _DTypeKind), str)

s2 = pd.Series([1], dtype="Int64")
check(assert_type(s2.dtype, DtypeObj), ExtensionDtype)
check(assert_type(s2.dtype.kind, str), str)
check(assert_type(s2.dtype.kind, _DTypeKind), str)

s3 = pd.Series([1, 2, 3])
check(assert_type(s3.dtype, DtypeObj), np.dtype)
check(assert_type(s3.dtype.kind, str), str)
check(assert_type(s3.dtype.kind, _DTypeKind), str)


def test_types_to_numpy() -> None:
Expand Down
Loading