Skip to content

Commit

Permalink
📌 Require pandas~=2.1 and drop support for python 3.8 (#62)
Browse files Browse the repository at this point in the history
* 📌 Require pandas~=2.1

* Drop support for python 3.8

* Update type checks
  • Loading branch information
ddelange committed Jan 10, 2024
1 parent 73fd310 commit d80292c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ description = "Sensible multi-core apply function for Pandas"
readme = "README.md"
urls = {Repository = "https://github.com/ddelange/mapply", Documentation = "https://mapply.readthedocs.io"}
authors = [{name = "ddelange", email = "[email protected]"}]
requires-python = ">=3.8" # sync with classifiers below, and tool.ruff and tool.mypy
requires-python = ">=3.9" # sync with classifiers below, and tool.ruff and tool.mypy
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand All @@ -31,7 +30,7 @@ branch = true
omit = ["site-packages"]

[tool.mypy]
python_version = "3.8"
python_version = "3.9"
ignore_missing_imports = true
warn_no_return = false
disallow_untyped_defs = false
Expand All @@ -58,6 +57,7 @@ ignore = [
"D203", # there is D211
"D213", # there is D212
"FIX002", # there is TD002,TD003
"TCH003", # clutters
]

[tool.ruff.extend-per-file-ignores]
Expand Down
1 change: 0 additions & 1 deletion requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ mypy~=1.6
pre-commit~=3.5
pytest-cov~=4.1
pytest~=7.4
pandas
1 change: 1 addition & 0 deletions requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pathos>=0.3.1 # https://github.com/uqfoundation/pathos/pull/252
multiprocess
psutil
tqdm>=4.27 # from tqdm.auto import tqdm
pandas~=2.1
12 changes: 3 additions & 9 deletions src/mapply/_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# ruff: noqa: ERA001
import logging
from types import MethodType
from typing import Any, Callable, Tuple
from typing import Any, Callable

from mapply.parallel import multiprocessing_imap, tqdm

Expand All @@ -46,11 +46,10 @@ def run_groupwise_apply(
*,
n_workers: int,
progressbar: bool,
args: Tuple[Any, ...] = (), # noqa: FA100
args: tuple[Any, ...] = (),
**kwargs: Any,
):
"""Patch GroupBy.grouper.apply, applying func to each group in parallel."""
from pandas import __version__

def apply(self, f, data, axis=0):
# patching https://github.com/pandas-dev/pandas/blob/v1.5.3/pandas/core/groupby/ops.py#L823
Expand Down Expand Up @@ -118,13 +117,8 @@ def apply(self, f, data, axis=0):

return result_values, mutated

if __version__.split(".") < ["1", "5"]: # pragma: no cover
logger.warning("GroupBy.mapply only works for pandas>=1.5.0. Using single CPU.")
return df_or_series.apply(func, *args, **kwargs)

# 2.1.0 renamed to apply_groupwise ref https://github.com/pandas-dev/pandas/commit/dc947a459b094ccd087557db355cfde5ed97b454
attr = "apply" if hasattr(df_or_series.grouper, "apply") else "apply_groupwise"
# overwrite apply method and restore after execution
attr = "apply_groupwise"
original_apply = getattr(df_or_series.grouper, attr)
setattr(df_or_series.grouper, attr, MethodType(apply, df_or_series.grouper))
try:
Expand Down
3 changes: 2 additions & 1 deletion src/mapply/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def some_heavy_computation(x, power):

import logging
import os
from collections.abc import Iterable, Iterator
from functools import partial
from typing import Any, Callable, Iterable, Iterator
from typing import Any, Callable

import multiprocess
import psutil
Expand Down

0 comments on commit d80292c

Please sign in to comment.