Find users assigned to an A/B test but missing from the exposure log with a pandas anti-join
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: easy
Interview Round: Other
In an A/B test, the assignment table records the variant each user was bucketed into, and the exposure log records the users who actually reached the experiment. Assigned users with no exposure point to a triggering or logging gap, so they are worth listing before any analysis.
Implement `unexposed_assigned_users(assignment, exposure)`. Both DataFrames have columns `'user'` (int) and `'variant'` (str). Return the user ids present in `assignment` but absent from `exposure` (an anti-join on `'user'`).
The function must:
- Match by `'user'` only and ignore `'variant'`.
- Return a list of native Python `int` values, sorted ascending.
- Return an empty list if every assigned user was exposed.
Example:
```text
assignment users: [1, 2, 3, 4, 5]
exposure users: [1, 2, 4]
Output: [3, 5]
```
Users 3 and 5 were assigned but never appear in the exposure log. Users 1, 2 and 4 appear in both frames, so they are left out.
```hint Lookups and return types
Collect the exposed ids once so each assigned user is checked without rescanning `exposure`. Then look at what type a value pulled out of a pandas column actually has.
```
### Constraints & Assumptions
- `assignment` and `exposure` each have columns `user` (int) and `variant` (str).
- A user id can appear in more than one row of either frame, for example when exposure is logged per event. Each id appears at most once in the output.
### What a Strong Answer Covers
- Matching on `user` alone, with `variant` left out of the comparison.
- A membership check that avoids a nested scan (a set, `isin`, or a merge with an indicator) and its cost in terms of the two frame sizes.
- Deduplication, so repeated assignment rows do not repeat an id in the output.
- Conversion from NumPy integers to native Python `int`, and the ascending sort.
- The edge cases: every user exposed, repeated rows, and users present in only one frame.
### Follow-up Questions
- How would you extend this to flag `exposure` rows whose variant disagrees with `assignment`?
- How would this scale to hundreds of millions of users?
- What does a high unexposed rate tell you about the experiment, and how would it change the analysis?
Overview: Write a pandas function that lists the users assigned to an A/B test but missing from the exposure log, matching on user id only. It tests anti-join logic, fast membership checks, deduplication, native Python return types and how exposure gaps can bias an experiment readout.