Skip to content

Commit 28074c1

Browse files
authored
♻️ Move to Pandas v3 (#103)
1 parent 2777d53 commit 28074c1

13 files changed

Lines changed: 53 additions & 140 deletions

File tree

.github/workflows/CI.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616
id-token: write # codecov/codecov-action
1717
strategy:
1818
matrix:
19-
python-version: ['3.9', '3.14'] # sync with make targets below
19+
python-version: ['3.11', '3.14'] # sync with make targets below
2020

2121
steps:
2222
- uses: actions/checkout@v6
2323
with:
24-
fetch-depth: 0
24+
fetch-depth: 0 # for setuptools_scm
2525

2626
- name: Set up Python
2727
uses: actions/setup-python@v6

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 73 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
repos:
33
- repo: https://github.com/astral-sh/ruff-pre-commit
4-
rev: v0.14.7
4+
rev: v0.15.2
55
hooks:
66
- id: ruff-check
77
args: [--fix, --exit-non-zero-on-fix]
@@ -66,7 +66,7 @@ repos:
6666
- id: debug-statements
6767

6868
- repo: https://github.com/python-jsonschema/check-jsonschema
69-
rev: 0.35.0
69+
rev: 0.36.2
7070
hooks:
7171
- id: check-dependabot
7272
- id: check-github-workflows

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ version: 2
1010
build:
1111
os: ubuntu-24.04
1212
tools:
13-
python: '3.12'
13+
python: '3.14'
1414

1515
# Build documentation in the docs/ directory with Sphinx
1616
sphinx:

docs/source/conf.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
8484
# ones.
8585
extensions = [
86-
"recommonmark",
86+
"myst_parser",
8787
"sphinx_rtd_theme",
8888
"sphinx.ext.autodoc",
8989
"sphinx.ext.napoleon",
@@ -92,8 +92,7 @@
9292
]
9393
autodoc_typehints = "description"
9494

95-
# recommonmark extension allows mixed filetypes
96-
source_suffix = [".rst", ".md"]
95+
suppress_warnings = ["myst.header"]
9796

9897
# Add any paths that contain templates here, relative to this directory.
9998
# templates_path = ["_templates"]
@@ -169,7 +168,7 @@ def linkcode_resolve( # noqa: C901
169168
for part in fullname.split("."):
170169
try:
171170
obj = getattr(obj, part)
172-
except Exception: # noqa: PERF203
171+
except Exception:
173172
return None
174173

175174
# strip decorators, which would resolve to the source of the decorator

pyproject.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ description = "Sensible multi-core apply function for Pandas"
88
readme = "README.md"
99
urls = {Repository = "https://github.com/ddelange/mapply", Documentation = "https://mapply.readthedocs.io"}
1010
authors = [{name = "ddelange", email = "ddelange@delange.dev"}]
11-
requires-python = ">=3.9" # sync with classifiers below, and tool.ruff and tool.mypy
11+
requires-python = ">=3.11" # sync with classifiers below, and tool.ruff and tool.mypy
1212
license = "BSD-3-Clause"
1313
classifiers = [
1414
"Development Status :: 5 - Production/Stable",
1515
"Intended Audience :: Developers",
1616
"Operating System :: OS Independent",
1717
"Programming Language :: Python",
1818
"Programming Language :: Python :: 3",
19-
"Programming Language :: Python :: 3.9",
20-
"Programming Language :: Python :: 3.10",
2119
"Programming Language :: Python :: 3.11",
2220
"Programming Language :: Python :: 3.12",
2321
"Programming Language :: Python :: 3.13",
@@ -32,7 +30,7 @@ branch = true
3230
omit = ["site-packages"]
3331

3432
[tool.mypy]
35-
python_version = "3.9"
33+
python_version = "3.11"
3634
ignore_missing_imports = true
3735
warn_no_return = false
3836
disallow_untyped_defs = false
@@ -45,8 +43,7 @@ check-return-types = false
4543
check-yield-types = false
4644

4745
[tool.pytest.ini_options]
48-
addopts = "-s --strict-markers -vv --cache-clear --doctest-modules --cov=mapply --cov-report=term --cov-report=html --cov-branch --no-cov-on-fail --ignore=docs"
49-
filterwarnings = ["ignore::DeprecationWarning"]
46+
addopts = "-s --strict-markers -vv --cache-clear --doctest-modules --cov=mapply --cov-report=term --cov-report=html --cov-report=xml --cov-branch --no-cov-on-fail --ignore=docs"
5047

5148
[tool.ruff]
5249
output-format = "concise"

requirements/ci.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
detect-secrets~=1.4
22
mypy~=1.6
3-
pre-commit~=3.5
4-
pytest-cov~=4.1
5-
pytest~=7.4
3+
pre-commit~=4.5
4+
pytest-cov~=7.0
5+
pytest~=9.0

requirements/docs.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
recommonmark~=0.7
2-
sphinx-rtd-theme~=1.3
3-
sphinx~=7.0
1+
myst-parser~=5.0
2+
sphinx-rtd-theme~=3.0
3+
sphinx~=8.0

requirements/prod.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ pathos>=0.3.1 # https://github.com/uqfoundation/pathos/pull/252
22
multiprocess
33
psutil
44
tqdm>=4.27 # from tqdm.auto import tqdm
5-
pandas~=2.1
5+
pandas~=3.0

src/mapply/_groupby.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
# SPDX-License-Identifier: BSD-3-Clause
3333
# ruff: noqa: ERA001
3434
import logging
35+
from collections.abc import Callable
3536
from types import MethodType
36-
from typing import Any, Callable
37+
from typing import Any
3738

3839
from pandas.core.groupby.ops import _is_indexed_like
3940

@@ -51,18 +52,18 @@ def run_groupwise_apply(
5152
args: tuple[Any, ...] = (),
5253
**kwargs: Any,
5354
):
54-
"""Patch GroupBy.grouper.apply, applying func to each group in parallel."""
55+
"""Patch GroupBy._grouper.apply_groupwise, applying func to each group in parallel."""
5556

56-
def apply(self, f, data, axis=0):
57-
# patching https://github.com/pandas-dev/pandas/blob/v2.1.4/pandas/core/groupby/ops.py#L890
57+
def apply(self, f, data):
58+
# patching https://github.com/pandas-dev/pandas/blob/v3.0.1/pandas/core/groupby/ops.py#L1014
5859
# with a multiprocessing_imap
5960
mutated = False
60-
splitter = self._get_splitter(data, axis=axis)
61-
group_keys = self.group_keys_seq
61+
splitter = self._get_splitter(data)
62+
group_keys = self.result_index
6263
result_values = []
6364

6465
# This calls DataSplitter.__iter__
65-
zipped = zip(group_keys, splitter)
66+
zipped = zip(group_keys, splitter, strict=True)
6667

6768
# rewrite the original for-loop into an imap
6869
def _run_apply(args):
@@ -91,12 +92,13 @@ def _run_apply(args):
9192
# original for-loop leftover
9293
for res, group_axes in zipped:
9394
# no changes made below this line
94-
if not mutated and not _is_indexed_like(res, group_axes, axis):
95+
if not mutated and not _is_indexed_like(res, group_axes):
9596
mutated = True
9697
result_values.append(res)
9798
# getattr pattern for __name__ is needed for functools.partial objects
9899
if len(group_keys) == 0 and getattr(f, "__name__", None) in [
99100
"skew",
101+
"kurt",
100102
"sum",
101103
"prod",
102104
]:
@@ -109,9 +111,10 @@ def _run_apply(args):
109111

110112
# overwrite apply method and restore after execution
111113
attr = "apply_groupwise"
112-
original_apply = getattr(df_or_series.grouper, attr)
113-
setattr(df_or_series.grouper, attr, MethodType(apply, df_or_series.grouper))
114+
grouper = df_or_series._grouper # noqa: SLF001
115+
original_apply = getattr(grouper, attr)
116+
setattr(grouper, attr, MethodType(apply, grouper))
114117
try:
115118
return df_or_series.apply(func, *args, **kwargs)
116119
finally:
117-
setattr(df_or_series.grouper, attr, original_apply)
120+
setattr(grouper, attr, original_apply)

0 commit comments

Comments
 (0)