Skip to content

Commit

Permalink
Quickfix to support pandas 2.0 and 2.1 (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuppmann authored Apr 17, 2024
1 parent 8b0c1dc commit 18fb1da
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: pull_request

jobs:
test:
timeout-minutes: 15
timeout-minutes: 30
strategy:
matrix:
python-version:
Expand All @@ -16,14 +16,28 @@ jobs:
- false
postgres-version:
- "16"
pandas-version:
- false
include:
- python-version: "3.12"
with-pyarrow: true
postgres-version: "16"
pandas-version: false
- python-version: "3.12"
with-pyarrow: false
postgres-version: "15"
name: py${{ matrix.python-version }} | with-pyarrow=${{ matrix.with-pyarrow }} | pgsql${{ matrix.postgres-version }}
pandas-version: false
- python-version: "3.11"
with-pyarrow: true
postgres-version: "16"
pandas-version: "2.1.3"
- python-version: "3.10"
with-pyarrow: true
postgres-version: "16"
pandas-version: "2.0.0"


name: py${{ matrix.python-version }} | with-pyarrow=${{ matrix.with-pyarrow }} | pgsql=${{ matrix.postgres-version }} | pandas=${{ matrix.pandas-version }}
runs-on: ubuntu-latest
services:
postgres:
Expand Down Expand Up @@ -90,6 +104,10 @@ jobs:
if: ${{ matrix.with-pyarrow }}
run: pip install pyarrow

- name: Install legacy pandas
if: ${{ matrix.pandas-version }}
run: poetry add pandas@${{ matrix.pandas-version }} --lock

#------------------------
# install root project
#------------------------
Expand Down
9 changes: 8 additions & 1 deletion ixmp4/data/db/iamc/timeseries/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,16 @@ def map_measurand(df):
df["unit__id"] = unit__id
return df

# ensure compatibility with pandas < 2.2
# TODO remove legacy-handling when dropping support for pandas < 2.2
if pd.__version__[0:3] in ["2.0", "2.1"]:
apply_args = dict()
else:
apply_args = dict(include_groups=False)

return pd.DataFrame(
df.groupby(["variable", "unit__id"], group_keys=False).apply(
map_measurand, include_groups=False
map_measurand, **apply_args
)
)

Expand Down
9 changes: 8 additions & 1 deletion ixmp4/data/db/meta/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,15 @@ def map_value_column(df: pd.DataFrame):
df["type"] = type_str
return df.drop(columns=RunMetaEntry._column_map.values())

# ensure compatibility with pandas y 2.2
# TODO remove legacy-handling when dropping support for pandas < 2.2
if pd.__version__[0:3] in ["2.0", "2.1"]:
apply_args = dict()
else:
apply_args = dict(include_groups=False)

return df.groupby("type", group_keys=False).apply(
map_value_column, include_groups=False
map_value_column, **apply_args
)

@check_types
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ alembic = ">=1.12.0"
fastapi = ">=0.100.0"
httpx = { extras = ["http2"], version = ">=0.25.0" }
openpyxl = ">=3.0.9"
# remove legacy-handling in timeseries- and meta-repositories when dropping pandas < 2.2
pandas = [
{version = ">=2.1.1", python = ">=3.12"},
{version = ">=2.0.0", python = ">=3.10"}
{ version = ">=2.1.1", python = ">=3.12" },
{ version = ">=2.0.0", python = ">=3.10" }
]
pandera = ">=0.17.0"
pydantic = ">=2.3.0"
Expand Down

0 comments on commit 18fb1da

Please sign in to comment.