Daily Feed Coverage Report

Quick Overview

Write a pandas function that summarizes how completely a daily data feed covers its date range, including the longest run of missing days and a coverage verdict. It tests calendar reconstruction, run-length logic and exact Series output.

Daily Feed Coverage Report

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

Write `date_coverage_report(df)` taking a DataFrame whose `date` column is `datetime64[ns]`, unique, and meant to hold one row per day. Return a `pd.Series` that summarizes how well the dates cover their range. Requirements: - The index is exactly `n_expected`, `n_present`, `n_missing`, `coverage_pct`, `longest_gap_days`, `verdict`, in that order. The Series has dtype `object` and `name` `None`. - `n_expected` (int) is the number of calendar days from the minimum to the maximum `date`, inclusive. `n_present` (int) is the number of rows present. `n_missing` (int) is `n_expected - n_present`. - `coverage_pct` (float) is `n_present / n_expected * 100`, rounded to 2 decimal places. - `longest_gap_days` (int) is the longest run of consecutive absent days, or `0` if there are no gaps. - `verdict` (str) is `'complete'` if `coverage_pct == 100.0`, else `'minor_gaps'` if `coverage_pct >= 95.0`, else `'unreliable'`. Example with the dates 2026-01-01, 2026-01-02 and 2026-01-05 present. The range Jan 1 to Jan 5 has 5 calendar days: ```text n_expected 5 n_present 3 n_missing 2 coverage_pct 60.0 longest_gap_days 2 verdict unreliable dtype: object ``` The longest gap is 2 because Jan 3 and Jan 4 are both missing, and 60.0 is below 95.0, so the verdict is `unreliable`. ```hint The calendar to compare against Build the full list of days the feed should contain, then compare the dates you have against it. ``` ```hint Measuring a run A run of missing days ends whenever a present day appears. Think about how to give each run its own label so you can measure all of them in one pass. ``` ### Constraints & Assumptions - `date` has no missing values and the frame has at least one row. - Every value is a calendar day at midnight, with no time-of-day component. - The input is not necessarily sorted. ### What a Strong Answer Covers - Builds the expected calendar from the minimum to the maximum date, inclusive, and derives the three counts from it. - Finds the longest run of consecutive missing days in one pass and returns 0 when nothing is missing. - Applies the rounding and verdict thresholds as specified and returns an `object` Series in the exact index order with no name. - Names the edge cases: a single-row feed, timestamps that carry a time of day, and rounding near the 100 and 95 thresholds. ### Follow-up Questions - How would you extend this to a business-day feed, with weekends excluded? - How would you also report where every gap is, with its start, end and length? - The expected range ends at the last date in the data. How would you catch a feed that stopped arriving a week ago?

Overview: Write a pandas function that summarizes how completely a daily data feed covers its date range, including the longest run of missing days and a coverage verdict. It tests calendar reconstruction, run-length logic and exact Series output.

Nov 24, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

Write date_coverage_report(df) taking a DataFrame whose date column is datetime64[ns], unique, and meant to hold one row per day. Return a pd.Series that summarizes how well the dates cover their range.

Requirements:

  • The index is exactly n_expected , n_present , n_missing , coverage_pct , longest_gap_days , verdict , in that order. The Series has dtype object and name None .
  • n_expected (int) is the number of calendar days from the minimum to the maximum date , inclusive. n_present (int) is the number of rows present. n_missing (int) is n_expected - n_present .
  • coverage_pct (float) is n_present / n_expected * 100 , rounded to 2 decimal places.
  • longest_gap_days (int) is the longest run of consecutive absent days, or 0 if there are no gaps.
  • verdict (str) is 'complete' if coverage_pct == 100.0 , else 'minor_gaps' if coverage_pct >= 95.0 , else 'unreliable' .

Example with the dates 2026-01-01, 2026-01-02 and 2026-01-05 present. The range Jan 1 to Jan 5 has 5 calendar days:

n_expected                   5
n_present                    3
n_missing                    2
coverage_pct              60.0
longest_gap_days             2
verdict             unreliable
dtype: object

The longest gap is 2 because Jan 3 and Jan 4 are both missing, and 60.0 is below 95.0, so the verdict is unreliable.

Constraints & Assumptions

  • date has no missing values and the frame has at least one row.
  • Every value is a calendar day at midnight, with no time-of-day component.
  • The input is not necessarily sorted.

What a Strong Answer Covers Guidance

  • Builds the expected calendar from the minimum to the maximum date, inclusive, and derives the three counts from it.
  • Finds the longest run of consecutive missing days in one pass and returns 0 when nothing is missing.
  • Applies the rounding and verdict thresholds as specified and returns an object Series in the exact index order with no name.
  • Names the edge cases: a single-row feed, timestamps that carry a time of day, and rounding near the 100 and 95 thresholds.

Follow-up Questions Guidance

  • How would you extend this to a business-day feed, with weekends excluded?
  • How would you also report where every gap is, with its start, end and length?
  • The expected range ends at the last date in the data. How would you catch a feed that stopped arriving a week ago?