|
3 | 3 |
|
4 | 4 | from azcausal.core.error import Error |
5 | 5 | from azcausal.core.estimator import Estimator |
6 | | -from azcausal.core.panel import Panel, CausalPanel |
| 6 | +from azcausal.core.panel import ( |
| 7 | + CausalPanel, |
| 8 | + Panel, |
| 9 | +) |
7 | 10 | from azcausal.core.result import Result as _Result |
| 11 | +from azcausal.util import to_panels |
8 | 12 | from jaxtyping import Float |
9 | 13 | import pandas as pd |
10 | 14 |
|
11 | 15 | from causal_validation.data import Dataset |
12 | 16 | from causal_validation.estimator import Result |
13 | 17 | from causal_validation.types import NPArray |
14 | | -from azcausal.util import to_panels |
| 18 | + |
15 | 19 |
|
16 | 20 | def to_azcausal(dataset: Dataset) -> Panel: |
17 | 21 | if dataset.n_treated_units != 1: |
18 | 22 | raise ValueError("Only one treated unit is supported.") |
19 | 23 | time_index = dataset.full_index |
20 | 24 | unit_cols = dataset._get_columns() |
21 | | - |
| 25 | + |
22 | 26 | data = [] |
23 | 27 | for time_idx in range(dataset.n_timepoints): |
24 | 28 | for unit_idx, unit in enumerate(unit_cols): |
25 | | - data.append({ |
26 | | - 'variable': unit, |
27 | | - 'time': time_index[time_idx], |
28 | | - 'value': dataset.Y[time_idx, unit_idx], |
29 | | - 'treated': int(dataset.D[time_idx, unit_idx]) |
30 | | - }) |
31 | | - |
32 | | - df_data = pd.DataFrame(data) |
| 29 | + data.append( |
| 30 | + { |
| 31 | + "variable": unit, |
| 32 | + "time": time_index[time_idx], |
| 33 | + "value": dataset.Y[time_idx, unit_idx], |
| 34 | + "treated": int(dataset.D[time_idx, unit_idx]), |
| 35 | + } |
| 36 | + ) |
| 37 | + |
| 38 | + df_data = pd.DataFrame(data) |
33 | 39 | panels = to_panels(df_data, "time", "variable", ["value", "treated"]) |
34 | | - ctypes = dict( |
35 | | - outcome="value", time="time", unit="variable", intervention="treated" |
36 | | - ) |
| 40 | + ctypes = dict(outcome="value", time="time", unit="variable", intervention="treated") |
37 | 41 | panel = CausalPanel(panels).setup(**ctypes) |
38 | 42 | return panel |
39 | 43 |
|
|
0 commit comments