Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
Update to mypy 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
tmke8 committed Aug 11, 2023
1 parent dba342f commit 1d405c6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions ethicml/implementations/fair_dummies_modules/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def fit(self, train: DataTuple, seed: int) -> Self:

for _ in range(self.pretrain_pred_epochs):
random_array = rng.uniform(low=0.0, high=1.0, size=train.s.shape)
z_tilde = (random_array < p_success).astype(float)
z_tilde = (random_array < p_success).astype(np.dtype(float))
zt_train = pd.DataFrame(data=z_tilde)
train_data = PandasDataSet(train.x, train.s, train.y, zt_train)
train_loader = DataLoader(
Expand All @@ -513,7 +513,7 @@ def fit(self, train: DataTuple, seed: int) -> Self:

for _ in range(self.pretrain_dis_epochs):
random_array = rng.uniform(low=0.0, high=1.0, size=train.s.shape)
z_tilde = (random_array < p_success).astype(float)
z_tilde = (random_array < p_success).astype(np.dtype(float))
zt_train = pd.DataFrame(data=z_tilde)
train_data = PandasDataSet(train.x, train.s, train.y, zt_train)
train_loader = DataLoader(
Expand All @@ -536,7 +536,7 @@ def fit(self, train: DataTuple, seed: int) -> Self:

for _ in range(1, self.epochs):
random_array = rng.uniform(low=0.0, high=1.0, size=train.s.shape)
z_tilde = (random_array < p_success).astype(float)
z_tilde = (random_array < p_success).astype(np.dtype(float))
zt_train = pd.DataFrame(data=z_tilde)
train_data = PandasDataSet(train.x, train.s, train.y, zt_train)
train_loader = DataLoader(
Expand Down Expand Up @@ -645,7 +645,7 @@ def fit(self, train: DataTuple, seed: int) -> None:

for _ in range(self.pretrain_pred_epochs):
random_array = rng.uniform(low=0.0, high=1.0, size=train.s.shape)
z_tilde = (random_array < p_success).astype(float)
z_tilde = (random_array < p_success).astype(np.dtype(float))
zt_train = pd.DataFrame(data=z_tilde)
train_data = PandasDataSet(train.x, train.s, train.y, zt_train)
train_loader = DataLoader(
Expand Down Expand Up @@ -675,7 +675,7 @@ def fit(self, train: DataTuple, seed: int) -> None:

for _ in range(self.pretrain_dis_epochs):
random_array = rng.uniform(low=0.0, high=1.0, size=train.s.shape)
z_tilde = (random_array < p_success).astype(float)
z_tilde = (random_array < p_success).astype(np.dtype(float))
zt_train = pd.DataFrame(data=z_tilde)
train_data = PandasDataSet(train.x, train.s, train.y, zt_train)
train_loader = DataLoader(
Expand Down Expand Up @@ -710,7 +710,7 @@ def fit(self, train: DataTuple, seed: int) -> None:

for _ in range(1, self.epochs):
random_array = rng.uniform(low=0.0, high=1.0, size=train.s.shape)
z_tilde = (random_array < p_success).astype(float)
z_tilde = (random_array < p_success).astype(np.dtype(float))
zt_train = pd.DataFrame(data=z_tilde)
train_data = PandasDataSet(train.x, train.s, train.y, zt_train)
train_loader = DataLoader(
Expand Down
7 changes: 4 additions & 3 deletions ethicml/models/inprocess/kamishima.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _predict(self, test: TestTuple, fit_info: _FitInfo, tmp_path: Path) -> Predi
cmd = [script, "-i", test_path, "-m", fit_info.model_path, "-o", output_path, "--quiet"]
self.call_script([str(e) for e in cmd])
output = np.loadtxt(output_path)
predictions = output[:, 1].astype(np.float32)
predictions = output[:, 1].astype(np.dtype(np.float32))
# except RuntimeError:
# predictions = np.ones_like(test.y.to_numpy())

Expand All @@ -102,9 +102,10 @@ def _create_file_in_kamishima_format(data: DataTuple | TestTuple, file_path: Pat
:param data: Data to write to the file.
:param file_path: Path to the file.
"""
dtype = np.dtype(np.float64)
if isinstance(data, DataTuple):
result = pd.concat([data.x, data.s, data.y], axis="columns").to_numpy().astype(np.float64)
result = pd.concat([data.x, data.s, data.y], axis="columns").to_numpy().astype(dtype)
else:
zeros = pd.DataFrame([0 for _ in range(data.x.shape[0])], columns=["y"])
result = pd.concat([data.x, data.s, zeros], axis="columns").to_numpy().astype(np.float64)
result = pd.concat([data.x, data.s, zeros], axis="columns").to_numpy().astype(dtype)
np.savetxt(file_path, result)
2 changes: 1 addition & 1 deletion ethicml/models/postprocess/hardt.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _predict(
p2n_indices = othr_pp_indices[: int(len(othr_pp_indices) * (1 - op2p))]
othr_fair_pred[p2n_indices] = self.unfavorable_label

new_labels = np.zeros_like(test_preds_numpy, dtype=np.float64)
new_labels = np.zeros_like(test_preds_numpy, dtype=np.dtype(np.float64))
new_labels[mask_s1] = self_fair_pred
new_labels[mask_s0] = othr_fair_pred

Expand Down

0 comments on commit 1d405c6

Please sign in to comment.