Skip to content
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
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: patch
changes:
changed:
- Bumped policyengine-core minimum version to 3.23.5 for pandas 3.0 compatibility
Empty file.
44 changes: 44 additions & 0 deletions policyengine_uk/tests/core/test_pandas3_enum_encoding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Test pandas 3.0 compatibility with enum encoding.

This test verifies that policyengine-core 3.23.5+ correctly handles
pandas Series with StringDtype index when encoding enums.
"""

import numpy as np
import pandas as pd
import pytest

from policyengine_core.enums import Enum


class SampleEnum(Enum):
VALUE_A = "value_a"
VALUE_B = "value_b"


def test_enum_encode_with_pandas_series():
"""Test that Enum.encode works with pandas Series containing enum items.

In pandas 3.0, Series with StringDtype use label-based indexing by default.
This test verifies the fix in policyengine-core 3.23.5 that uses .iloc[0]
for positional access instead of array[0].
"""
enum_items = [SampleEnum.VALUE_A, SampleEnum.VALUE_B, SampleEnum.VALUE_A]
series = pd.Series(enum_items)

# This would fail with KeyError: 0 before the fix
encoded = SampleEnum.encode(series)

assert len(encoded) == 3
assert list(encoded) == [0, 1, 0]


def test_enum_encode_with_string_index():
"""Test enum encoding with explicitly string-indexed Series."""
enum_items = [SampleEnum.VALUE_A, SampleEnum.VALUE_B]
series = pd.Series(enum_items, index=["a", "b"])

encoded = SampleEnum.encode(series)

assert len(encoded) == 2
assert list(encoded) == [0, 1]
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ classifiers = [
]
requires-python = ">=3.13,<3.14"
dependencies = [
"policyengine-core>=3.23.0",
"microdf-python>=1.0.2",
"policyengine-core>=3.23.6",
"microdf-python>=1.2.1",
"pydantic>=2.11.7",
"tables>=3.10.2",
]
Expand Down