Skip to content

Commit 031de87

Browse files
MaxGhenisclaude
andauthored
Bump policyengine-core to 3.23.5 for pandas 3.0 compatibility (#1492)
* Bump policyengine-core to 3.23.5 for pandas 3.0 compatibility Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Add test for pandas 3.0 enum encoding compatibility Adds tests to verify that policyengine-core 3.23.5 correctly handles pandas Series with StringDtype index when encoding enums. This ensures the fix using .iloc[0] for positional access works as expected. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * [TDD DEMO] Pin core to 3.23.4 to demonstrate test failure This commit intentionally pins policyengine-core to 3.23.4 (before the pandas 3.0 fix) to demonstrate that the test_pandas3_enum_encoding test fails without the fix. The next commit will revert to >=3.23.5. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * [TDD DEMO] Bump core to >=3.23.5 to fix pandas 3.0 compatibility This commit restores policyengine-core>=3.23.5, which includes the fix for pandas 3.0 enum encoding (using .iloc[0] instead of array[0]). The previous commit demonstrated the test failure. This commit shows the test passing with the fix in place. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Bump microdf-python to >=1.2.1 for pandas 3.0 compatibility microdf 1.2.1 includes the fix for pandas 3.0 Copy-on-Write compatibility in MicroDataFrame column access. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix black formatting in test file Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Bump policyengine-core to >=3.23.6 for pandas 3.0 StringArray fix Core 3.23.6 fixes TypeError: unhashable type: 'StringArray' when using pandas StringArray for parameter lookups (issue #429 in policyengine-core). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 54330ae commit 031de87

4 files changed

Lines changed: 50 additions & 2 deletions

File tree

changelog_entry.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- bump: patch
2+
changes:
3+
changed:
4+
- Bumped policyengine-core minimum version to 3.23.5 for pandas 3.0 compatibility

policyengine_uk/tests/core/__init__.py

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Test pandas 3.0 compatibility with enum encoding.
2+
3+
This test verifies that policyengine-core 3.23.5+ correctly handles
4+
pandas Series with StringDtype index when encoding enums.
5+
"""
6+
7+
import numpy as np
8+
import pandas as pd
9+
import pytest
10+
11+
from policyengine_core.enums import Enum
12+
13+
14+
class SampleEnum(Enum):
15+
VALUE_A = "value_a"
16+
VALUE_B = "value_b"
17+
18+
19+
def test_enum_encode_with_pandas_series():
20+
"""Test that Enum.encode works with pandas Series containing enum items.
21+
22+
In pandas 3.0, Series with StringDtype use label-based indexing by default.
23+
This test verifies the fix in policyengine-core 3.23.5 that uses .iloc[0]
24+
for positional access instead of array[0].
25+
"""
26+
enum_items = [SampleEnum.VALUE_A, SampleEnum.VALUE_B, SampleEnum.VALUE_A]
27+
series = pd.Series(enum_items)
28+
29+
# This would fail with KeyError: 0 before the fix
30+
encoded = SampleEnum.encode(series)
31+
32+
assert len(encoded) == 3
33+
assert list(encoded) == [0, 1, 0]
34+
35+
36+
def test_enum_encode_with_string_index():
37+
"""Test enum encoding with explicitly string-indexed Series."""
38+
enum_items = [SampleEnum.VALUE_A, SampleEnum.VALUE_B]
39+
series = pd.Series(enum_items, index=["a", "b"])
40+
41+
encoded = SampleEnum.encode(series)
42+
43+
assert len(encoded) == 2
44+
assert list(encoded) == [0, 1]

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ classifiers = [
2424
]
2525
requires-python = ">=3.13,<3.14"
2626
dependencies = [
27-
"policyengine-core>=3.23.0",
28-
"microdf-python>=1.0.2",
27+
"policyengine-core>=3.23.6",
28+
"microdf-python>=1.2.1",
2929
"pydantic>=2.11.7",
3030
"tables>=3.10.2",
3131
]

0 commit comments

Comments
 (0)