Skip to content
Closed
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
## [Unreleased]

### Added
- Regression test that an invalid `timezone=` on
`EncounterRecencyTransformer` raises `KeyError` naming the zone, not
`TypeError("Already tz-aware")`. Closes #204.
- Tests for `MovesManagementClassifier` now fit a named DataFrame and an
array so `feature_names_in_` is both recorded and absent on the paths
sklearn specifies. Closes #200.
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ contribution. Code, docs, tests, and review all count.

## Contributors

- **Harsh Raj Singhania** ([@HarshRajSinghania](https://github.com/HarshRajSinghania)):
added a regression test so an invalid timezone on
`EncounterRecencyTransformer` raises `KeyError` naming the zone (closes
[#204](https://github.com/PhilanthroPy-Project/PhilanthroPy/issues/204)).
- **Leyn.cx** ([@laichouchi](https://github.com/laichouchi)): fixed Windows
drive-letter paths being rejected as URI schemes (closes #217).

Expand Down
17 changes: 17 additions & 0 deletions tests/test_encounter_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import os

import pytest

import numpy as np
import pandas as pd

Expand Down Expand Up @@ -73,3 +75,18 @@ def test_naive_dates_with_a_tz_aware_reference_date():

assert out.shape == (2, 3)
np.testing.assert_allclose(out[:, 0], [364.0, 213.0])

def test_invalid_timezone_raises_keyerror_naming_the_zone():
"""Invalid timezone names must surface as a lookup error, not TypeError.

pandas 2 (pytz) and pandas 3 (zoneinfo) raise different concrete types,
but both subclass KeyError and include the zone name. The pre-#202
fallback turned this into TypeError('Already tz-aware').
"""
X = pd.DataFrame({"last_encounter_date": ["2023-01-01", "2023-06-01"]})
t = EncounterRecencyTransformer(
reference_date="2023-12-31", timezone="Not/AZone"
)
with pytest.raises(KeyError, match="Not/AZone") as excinfo:
t.fit_transform(X)
assert "Already tz-aware" not in str(excinfo.value)