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: 2 additions & 2 deletions src/recx/rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def clip_to_last_common_date(
``(a_clipped, b_clipped)`` with only rows whose ``date_col`` value is
less than or equal to the shared maximum date.
"""
a_dates = get_col(a, date_col)
b_dates = get_col(b, date_col)
a_dates = get_col(a, date_col).to_numpy()
b_dates = get_col(b, date_col).to_numpy()

latest_date = min(a_dates.max(), b_dates.max())

Expand Down
23 changes: 23 additions & 0 deletions tests/fixtures/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,26 @@ def equal_nan_frames():
baseline = pd.DataFrame({"A": [1.0, None]})
candidate = pd.DataFrame({"A": [1.0, None]})
return baseline, candidate


@pytest.fixture
def multi_index_frames():
baseline = pd.DataFrame(
{
"vintage_date": ["2024-01-01", "2024-01-02"],
"date": ["2024-01-01", "2024-01-02"],
"series_id": [1, 2],
"A": [1, 2],
"B": [3, 4],
}
).set_index(["vintage_date", "date", "series_id"])
candidate = pd.DataFrame(
{
"vintage_date": ["2024-01-01", "2024-01-02", "2024-01-03"],
"date": ["2024-01-01", "2024-01-02", "2024-01-03"],
"series_id": [1, 2, 3],
"A": [1, 2, 3],
"B": [3, 4, 6],
}
).set_index(["vintage_date", "date", "series_id"])
return baseline, candidate
11 changes: 11 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ def test_clip_to_last_common_date_index(dated_frames):
assert a_clip.equals(baseline)
# Candidate should be clipped to remove trailing 2024-01-03, keeping first two rows
assert list(b_clip.index) == ["2024-01-01", "2024-01-02"]


def test_clip_to_last_common_date_index_on_multi_index(multi_index_frames):
b, c = multi_index_frames
a_clip, b_clip = clip_to_last_common_date(b, c, "vintage_date")
assert a_clip.equals(b)

assert b_clip.index.get_level_values("vintage_date").tolist() == [
"2024-01-01",
"2024-01-02",
]
Loading