Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
to their first column before computation, matching validation behavior and
returning scalar/Series outputs consistently.

## Tests

- **Expanded warning coverage for `Sample.from_frame()` ID inference**
- Added assertions that validate all three expected warnings are emitted when inferring an `id` column and default weights, including ID guessing, ID string casting, and automatic weight creation.

# 0.16.0 (2026-02-09)

## New Features
Expand Down
21 changes: 11 additions & 10 deletions tests/test_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,18 @@ def test_Sample_from_frame_id_column_detection(self) -> None:
"""
# Test automatic id column detection
df = pd.DataFrame({"id": (1, 2), "a": (1, 2)})
self.assertWarnsRegexp(
"Guessed id column name id for the data", Sample.from_frame, df
)
# TODO: add tests for the two other warnings:
# - self.assertWarnsRegexp("Casting id column to string", Sample.from_frame, df)
# - self.assertWarnsRegexp("No weights passed, setting all weights to 1", Sample.from_frame, df)
# Using the above would fail since the warnings are sent sequentially and using self.assertWarnsRegexp
# only catches the first warning.
self.assertEqual(
Sample.from_frame(df).id_column, pd.Series((1, 2), name="id").astype(str)
with self.assertLogs(level="WARNING") as captured_logs:
sample = Sample.from_frame(df)

warning_messages = "\n".join(captured_logs.output)

self.assertIn("Guessed id column name id for the data", warning_messages)
self.assertIn("Casting id column to string", warning_messages)
self.assertIn(
"No weights passed. Adding a 'weight' column and setting all values to 1",
warning_messages,
)
self.assertEqual(sample.id_column, pd.Series((1, 2), name="id").astype(str))

# Test explicit id column specification
df = pd.DataFrame({"b": (1, 2), "a": (1, 2)})
Expand Down
Loading