Skip to content

Commit 4704d19

Browse files
committed
pylint
1 parent 559802f commit 4704d19

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

causal_testing/estimation/ipcw_estimator.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""This module contains the IPCWEstimator class, for estimating the time to a particular event"""
22

33
import logging
4-
from numpy import ceil
54
from typing import Any
6-
from tqdm import tqdm
75
from uuid import uuid4
86

7+
98
import numpy as np
109
import pandas as pd
1110
import statsmodels.formula.api as smf
@@ -15,8 +14,6 @@
1514

1615
logger = logging.getLogger(__name__)
1716

18-
debug_id = "data-50/batch_run_16/00221634_10.csv"
19-
2017

2118
class IPCWEstimator(Estimator):
2219
"""
@@ -152,7 +149,7 @@ def setup_fault_t_do(self, individual: pd.DataFrame):
152149

153150
if not fault.empty:
154151
time_fault_observed = (
155-
max(0, ceil(fault["time"].min() / self.timesteps_per_observation) - 1)
152+
max(0, np.ceil(fault["time"].min() / self.timesteps_per_observation) - 1)
156153
) * self.timesteps_per_observation
157154
individual.loc[individual["time"] == time_fault_observed, "fault_t_do"] = 1
158155

@@ -195,7 +192,7 @@ def preprocess_data(self):
195192

196193
assert (
197194
self.df.groupby("id", sort=False).apply(lambda x: len(set(x["fault_time"])) == 1).all()
198-
), f"Each individual must have a unique fault time."
195+
), "Each individual must have a unique fault time."
199196

200197
fault_t_do_df = self.df.groupby("id", sort=False)[["id", "time", self.status_column]].apply(
201198
self.setup_fault_t_do
@@ -263,7 +260,8 @@ def preprocess_data(self):
263260
(
264261
(
265262
individuals["time"]
266-
< ceil(individuals["fault_time"] / self.timesteps_per_observation) * self.timesteps_per_observation
263+
< np.ceil(individuals["fault_time"] / self.timesteps_per_observation)
264+
* self.timesteps_per_observation
267265
)
268266
& (~individuals["xo_t_do"].isnull())
269267
)
@@ -275,7 +273,7 @@ def preprocess_data(self):
275273
raise ValueError("No individuals followed either strategy.")
276274
self.df = individuals.loc[
277275
individuals["time"]
278-
< ceil(individuals["fault_time"] / self.timesteps_per_observation) * self.timesteps_per_observation
276+
< np.ceil(individuals["fault_time"] / self.timesteps_per_observation) * self.timesteps_per_observation
279277
].reset_index()
280278
logger.debug(len(individuals.groupby("id")), "individuals")
281279

@@ -341,10 +339,7 @@ def estimate_hazard_ratio(self):
341339
axis=1,
342340
).min(axis=1)
343341

344-
assert (preprocessed_data["tin"] <= preprocessed_data["tout"]).all(), (
345-
f"Left before joining\n"
346-
f"{preprocessed_data.loc[preprocessed_data['tin'] >= preprocessed_data['tout'], ['id', 'time', 'fault_time', 'tin', 'tout']]}"
347-
)
342+
assert (preprocessed_data["tin"] <= preprocessed_data["tout"]).all(), f"Individuals left before joining."
348343

349344
preprocessed_data.to_csv("/home/michael/tmp/preprocessed_data.csv")
350345

0 commit comments

Comments
 (0)