2727
2828import warnings
2929from dataclasses import dataclass
30- from typing import List , Optional
30+ from typing import Any , List , Optional
3131
3232import numpy as np
3333import pandas as pd
@@ -55,8 +55,9 @@ class PreTrendEstimate:
5555
5656 Attributes
5757 ----------
58- period : int
59- Calendar period (pseudo-post) used for this estimate.
58+ period : scalar
59+ Calendar period (pseudo-post) used for this estimate, on the
60+ native scale of the ``time`` column (integer, datetime64, ...).
6061 att : float
6162 Estimated average treatment effect on the treated.
6263 se : float
@@ -67,7 +68,7 @@ class PreTrendEstimate:
6768 Two-sided p-value for testing H0: ATT = 0.
6869 """
6970
70- period : int
71+ period : Any
7172 att : float
7273 se : float
7374 t_stat : float
@@ -216,14 +217,16 @@ def _identify_pre_periods(data: pd.DataFrame, time: str, treatment: str, unit: s
216217
217218 Returns
218219 -------
219- tuple of (list, int)
220- (pre_periods sorted, first_treat_time)
220+ tuple of (list, scalar)
221+ (pre_periods sorted, first_treat_time). The first-treatment time
222+ is kept on the native scale of the ``time`` column (integer,
223+ datetime64, ...), matching the LWDiD estimator.
221224 """
222225 treated_times = data .loc [data [treatment ] == 1 , time ].unique ()
223226 if len (treated_times ) == 0 :
224227 raise ValueError ("No treated observations found in the data." )
225228
226- first_treat = int ( min (treated_times ) )
229+ first_treat = min (treated_times )
227230 all_times = sorted (data [time ].unique ())
228231 pre_periods = [t for t in all_times if t < first_treat ]
229232
@@ -372,7 +375,7 @@ def _placebo_pre_trends(
372375 pre_periods , first_treat = _identify_pre_periods (data , time , treatment , unit )
373376
374377 if len (pre_periods ) < 2 :
375- raise ValueError (
378+ raise InsufficientPrePeriodsError (
376379 f"Need at least 2 pre-treatment periods for parallel trends test, "
377380 f"got { len (pre_periods )} ."
378381 )
@@ -416,7 +419,7 @@ def _placebo_pre_trends(
416419 pval = 2 * (1 - stats .norm .cdf (abs (t_stat )))
417420 pre_effects .append (
418421 PreTrendEstimate (
419- period = int ( pseudo_post_start ) ,
422+ period = pseudo_post_start ,
420423 att = float (result .att ),
421424 se = float (result .se ),
422425 t_stat = float (t_stat ),
0 commit comments