Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .claude/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ def estimate(self, y_true: NDArray, y_proxy: NDArray, power_tuning: bool = True)
def estimate(self, y_true: NDArray, y_proxy: NDArray, *, power_tuning: bool = True) -> ...: ...
```

### Zip Strictness

Every `zip()` call must pass an explicit `strict=` argument (ruff `B905`). Use `strict=True` whenever the iterables are expected to have the same length, so a mismatch raises instead of silently truncating; use `strict=False` only when truncation is intended. This applies to library code, tests and notebook code cells alike.

```python
# BAD
for estimate, label in zip(estimates, labels): ...


# GOOD
for estimate, label in zip(estimates, labels, strict=True): ...
```

### Type Conversions

Do not use needless type conversions like `float()` or `int()` unless required by the caller or for debugging purposes.
Expand Down
4 changes: 2 additions & 2 deletions docs/deep_dive/case_studies/memerag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
"fig, ax = plt.subplots(figsize=(11, 5.5))\n",
"y_pos = [2, 1, 0]\n",
"\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates):\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates, strict=True):\n",
" ax.plot([lo, hi], [y, y], color=color, linewidth=4, solid_capstyle=\"round\", zorder=3)\n",
" for xc in [lo, hi]:\n",
" ax.plot([xc, xc], [y - 0.2, y + 0.2], color=color, linewidth=2.5, zorder=3)\n",
Expand Down Expand Up @@ -571,7 +571,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "glide-py (3.12.12.final.0)",
"display_name": "glide-py (3.12.12)",
"language": "python",
"name": "python3"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/deep_dive/case_studies/spider.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
"fig, ax = plt.subplots(figsize=(11, 5.5))\n",
"y_pos = [2, 1, 0]\n",
"\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates):\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates, strict=True):\n",
" ax.plot([lo, hi], [y, y], color=color, linewidth=4, solid_capstyle=\"round\", zorder=3)\n",
" for xc in [lo, hi]:\n",
" ax.plot([xc, xc], [y - 0.2, y + 0.2], color=color, linewidth=2.5, zorder=3)\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/deep_dive/scientific_validation/estimators/asi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
"fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharey=True)\n",
"colors = {\"True only\": \"steelblue\", \"ASI\": \"darkorange\", \"Proxy only\": \"red\"}\n",
"\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels):\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels, strict=True):\n",
" ax.plot(confidence_levels, confidence_levels, color=\"black\", lw=1.5, linestyle=\"--\", label=\"Ideal\")\n",
" for method in METHODS:\n",
" mean_ci = np.array([coverages_confidence_intervals[correlation][cl][method] for cl in confidence_levels])\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
"fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharey=True)\n",
"colors = {\"True only\": \"steelblue\", \"Clustered PPI++\": \"darkorange\", \"Proxy only\": \"red\"}\n",
"\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels):\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels, strict=True):\n",
" ax.plot(confidence_levels, confidence_levels, color=\"black\", lw=1.5, linestyle=\"--\", label=\"Ideal\")\n",
" for method in METHODS:\n",
" mean_ci = np.array([coverages_confidence_intervals[correlation][cl][method] for cl in confidence_levels])\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
"fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharey=True)\n",
"colors = {\"True only\": \"steelblue\", \"Clustered PTD\": \"darkorange\", \"Proxy only\": \"red\"}\n",
"\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels):\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels, strict=True):\n",
" ax.plot(confidence_levels, confidence_levels, color=\"black\", lw=1.5, linestyle=\"--\", label=\"Ideal\")\n",
" for method in METHODS:\n",
" mean_ci = np.array([coverages_confidence_intervals[correlation][cl][method] for cl in confidence_levels])\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
"fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharey=True)\n",
"colors = {\"True only\": \"steelblue\", \"IPW PTD\": \"darkorange\", \"Proxy only\": \"red\"}\n",
"\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels):\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels, strict=True):\n",
" ax.plot(confidence_levels, confidence_levels, color=\"black\", lw=1.5, linestyle=\"--\", label=\"Ideal\")\n",
" for method in METHODS:\n",
" mean_ci = np.array([coverages_confidence_intervals[correlation][cl][method] for cl in confidence_levels])\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
"fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharey=True)\n",
"colors = {\"True only\": \"steelblue\", \"Multi-PPI++\": \"darkorange\", \"Proxy 1 only\": \"red\", \"Proxy 2 only\": \"firebrick\"}\n",
"\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels):\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels, strict=True):\n",
" ax.plot(confidence_levels, confidence_levels, color=\"black\", lw=1.5, linestyle=\"--\", label=\"Ideal\")\n",
" for method in METHODS:\n",
" mean_ci = np.array([coverages_confidence_intervals[correlation][cl][method] for cl in confidence_levels])\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
"fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharey=True)\n",
"colors = {\"True only\": \"steelblue\", \"Multi-PTD\": \"darkorange\", \"Proxy 1 only\": \"red\", \"Proxy 2 only\": \"firebrick\"}\n",
"\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels):\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels, strict=True):\n",
" ax.plot(confidence_levels, confidence_levels, color=\"black\", lw=1.5, linestyle=\"--\", label=\"Ideal\")\n",
" for method in METHODS:\n",
" mean_ci = np.array([coverages_confidence_intervals[correlation][cl][method] for cl in confidence_levels])\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/deep_dive/scientific_validation/estimators/ppi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
"fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharey=True)\n",
"colors = {\"True only\": \"steelblue\", \"PPI++\": \"darkorange\", \"Proxy only\": \"red\"}\n",
"\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels):\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels, strict=True):\n",
" ax.plot(confidence_levels, confidence_levels, color=\"black\", lw=1.5, linestyle=\"--\", label=\"Ideal\")\n",
" for method in METHODS:\n",
" mean_ci = np.array([coverages_confidence_intervals[correlation][cl][method] for cl in confidence_levels])\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/deep_dive/scientific_validation/estimators/ptd.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
"fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharey=True)\n",
"colors = {\"True only\": \"steelblue\", \"PTD\": \"darkorange\", \"Proxy only\": \"red\"}\n",
"\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels):\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels, strict=True):\n",
" ax.plot(confidence_levels, confidence_levels, color=\"black\", lw=1.5, linestyle=\"--\", label=\"Ideal\")\n",
" for method in METHODS:\n",
" mean_ci = np.array([coverages_confidence_intervals[correlation][cl][method] for cl in confidence_levels])\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
"fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharey=True)\n",
"colors = {\"True only\": \"steelblue\", \"Stratified PPI++\": \"darkorange\", \"Proxy only\": \"red\"}\n",
"\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels):\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels, strict=True):\n",
" ax.plot(confidence_levels, confidence_levels, color=\"black\", lw=1.5, linestyle=\"--\", label=\"Ideal\")\n",
" for method in METHODS:\n",
" mean_ci = np.array([coverages_confidence_intervals[correlation][cl][method] for cl in confidence_levels])\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharey=True)\n",
"colors = {\"True only\": \"steelblue\", \"Stratified PTD\": \"darkorange\", \"Proxy only\": \"red\"}\n",
"\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels):\n",
"for ax, correlation, label in zip(axes, correlations_lmh, corr_labels, strict=True):\n",
" ax.plot(confidence_levels, confidence_levels, color=\"black\", lw=1.5, linestyle=\"--\", label=\"Ideal\")\n",
" for method in METHODS:\n",
" mean_ci = np.array([coverages_confidence_intervals[correlation][cl][method] for cl in confidence_levels])\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/estimators/asi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
"fig, ax = plt.subplots(figsize=(11, 5.5))\n",
"y_pos = [2, 1, 0]\n",
"\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates):\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates, strict=True):\n",
" ax.plot([lo, hi], [y, y], color=color, linewidth=4, solid_capstyle=\"round\", zorder=3)\n",
" for xc in [lo, hi]:\n",
" ax.plot([xc, xc], [y - 0.2, y + 0.2], color=color, linewidth=2.5, zorder=3)\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/estimators/clustered_ppi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
"\n",
"ax.bar(x_pos, bar_vals, color=bar_colors, width=0.45, edgecolor=\"white\", linewidth=2, zorder=3)\n",
"\n",
"for xi, val, c in zip(x_pos, bar_vals, bar_colors):\n",
"for xi, val, c in zip(x_pos, bar_vals, bar_colors, strict=True):\n",
" ax.text(xi, val + 0.005, f\"{val:.1%}\", ha=\"center\", fontsize=14, fontweight=\"bold\", color=c)\n",
"\n",
"ax.annotate(\n",
Expand Down Expand Up @@ -390,7 +390,7 @@
"fig, ax = plt.subplots(figsize=(11, 5.5))\n",
"y_pos = [2, 1, 0]\n",
"\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates):\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates, strict=True):\n",
" # Confidence interval line\n",
" ax.plot([lo, hi], [y, y], color=color, linewidth=4, solid_capstyle=\"round\", zorder=3)\n",
" # Cap marks\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/estimators/cost_optimal.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
"fig, ax = plt.subplots(figsize=(11, 5.5))\n",
"y_pos = [2, 1, 0]\n",
"\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, baseline_estimates):\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, baseline_estimates, strict=True):\n",
" ax.plot([lo, hi], [y, y], color=color, linewidth=4, solid_capstyle=\"round\", zorder=3)\n",
" for xc in [lo, hi]:\n",
" ax.plot([xc, xc], [y - 0.2, y + 0.2], color=color, linewidth=2.5, zorder=3)\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/estimators/cost_optimal_random.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@
"fig, ax = plt.subplots(figsize=(11, 5.5))\n",
"y_pos = [2, 1, 0]\n",
"\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, baseline_estimates):\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, baseline_estimates, strict=True):\n",
" ax.plot([lo, hi], [y, y], color=color, linewidth=4, solid_capstyle=\"round\", zorder=3)\n",
" for xc in [lo, hi]:\n",
" ax.plot([xc, xc], [y - 0.2, y + 0.2], color=color, linewidth=2.5, zorder=3)\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/estimators/multi_ppi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@
"\n",
"ax.bar(x_pos, bar_vals, color=bar_colors, width=0.45, edgecolor=\"white\", linewidth=2, zorder=3)\n",
"\n",
"for xi_pos, val, c in zip(x_pos, bar_vals, bar_colors):\n",
"for xi_pos, val, c in zip(x_pos, bar_vals, bar_colors, strict=True):\n",
" ax.text(xi_pos, val + 0.004, f\"{val:.1%}\", ha=\"center\", fontsize=14, fontweight=\"bold\", color=c)\n",
"\n",
"for xi_pos, bias in zip([0, 1], [gemini_bias, claude_bias]):\n",
"for xi_pos, bias in zip([0, 1], [gemini_bias, claude_bias], strict=True):\n",
" ax.text(\n",
" xi_pos,\n",
" t_mean + 0.055,\n",
Expand Down Expand Up @@ -410,7 +410,7 @@
"fig, ax = plt.subplots(figsize=(11, 7))\n",
"y_pos = [3, 2, 1, 0]\n",
"\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates):\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates, strict=True):\n",
" ax.plot([lo, hi], [y, y], color=color, linewidth=4, solid_capstyle=\"round\", zorder=3)\n",
" for xc in [lo, hi]:\n",
" ax.plot([xc, xc], [y - 0.2, y + 0.2], color=color, linewidth=2.5, zorder=3)\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/estimators/ppi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
"\n",
"ax.bar(x_pos, bar_vals, color=bar_colors, width=0.45, edgecolor=\"white\", linewidth=2, zorder=3)\n",
"\n",
"for xi, val, c in zip(x_pos, bar_vals, bar_colors):\n",
"for xi, val, c in zip(x_pos, bar_vals, bar_colors, strict=True):\n",
" ax.text(xi, val + 0.005, f\"{val:.1%}\", ha=\"center\", fontsize=14, fontweight=\"bold\", color=c)\n",
"\n",
"ax.annotate(\n",
Expand Down Expand Up @@ -381,7 +381,7 @@
"fig, ax = plt.subplots(figsize=(11, 5.5))\n",
"y_pos = [2, 1, 0]\n",
"\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates):\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates, strict=True):\n",
" # Confidence interval line\n",
" ax.plot([lo, hi], [y, y], color=color, linewidth=4, solid_capstyle=\"round\", zorder=3)\n",
" # Cap marks\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/estimators/stratified_ppi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@
")\n",
"\n",
"# Annotate biases\n",
"for i, (j_mean, h_mean, bias) in enumerate(zip(judge_means, human_means, biases)):\n",
"for i, (j_mean, h_mean, bias) in enumerate(zip(judge_means, human_means, biases, strict=True)):\n",
" max_y = max(j_mean, h_mean)\n",
" ax.annotate(\n",
" \"\",\n",
Expand Down Expand Up @@ -473,7 +473,7 @@
"fig, ax = plt.subplots(figsize=(12, 6))\n",
"y_pos = [2, 1, 0]\n",
"\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates):\n",
"for y, (label, mean, lo, hi, color) in zip(y_pos, estimates, strict=True):\n",
" # Confidence interval line\n",
" ax.plot([lo, hi], [y, y], color=color, linewidth=5, solid_capstyle=\"round\", zorder=3)\n",
" # Cap marks\n",
Expand Down
3 changes: 2 additions & 1 deletion glide/simulators/multi_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def generate_multi_binary_dataset(
min_correlations = np.maximum(-p_t * p_p, p_p + p_t - 1 - p_t * p_p) / D
max_correlations = np.minimum(p_t * (1 - p_p), p_p * (1 - p_t)) / D

for m, (rho, lo, hi, proxy_mean) in enumerate(zip(correlations_arr, min_correlations, max_correlations, p_p)):
bounds = zip(correlations_arr, min_correlations, max_correlations, p_p, strict=True)
for m, (rho, lo, hi, proxy_mean) in enumerate(bounds):
if rho < lo or rho > hi:
raise ValueError(
f"Proxy {m}: impossible combination of 'true_mean'={true_mean!r}, "
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ default-groups = ["dev"]
[tool.ruff]
line-length = 120
fix = true
lint.select = ["E", "F", "FBT001", "FBT002", "I", "RUF001", "RUF002", "RUF003", "D102", "D105", "B028"]
lint.select = ["E", "F", "FBT001", "FBT002", "I", "RUF001", "RUF002", "RUF003", "D102", "D105", "B028", "B905"]

[tool.ty.analysis]
respect-type-ignore-comments = true
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/engines/test_clustered_ppi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_fit_tuning_parameter_delegates_to_ppi_engine(engine, dataset):
tuning_parameter = engine._fit_tuning_parameter(dataset, power_tuning=False)

mock_fit_tuning_parameter.assert_called_once()
for received, expected in zip(mock_fit_tuning_parameter.call_args[0][0], dataset):
for received, expected in zip(mock_fit_tuning_parameter.call_args[0][0], dataset, strict=True):
np.testing.assert_array_equal(received, expected)
assert mock_fit_tuning_parameter.call_args.kwargs == {"power_tuning": False}
assert tuning_parameter == 0.5
Expand All @@ -80,7 +80,7 @@ def test_compute_mean_and_std_delegates_to_ppi_engine(engine, dataset):
mean, std = engine._compute_mean_and_std(dataset, tuning_parameter=0.5)

mock_compute_mean_and_std.assert_called_once()
for received, expected in zip(mock_compute_mean_and_std.call_args[0][0], dataset):
for received, expected in zip(mock_compute_mean_and_std.call_args[0][0], dataset, strict=True):
np.testing.assert_array_equal(received, expected)
assert mock_compute_mean_and_std.call_args[0][1] == 0.5
assert (mean, std) == (1.5, 0.25)
2 changes: 1 addition & 1 deletion tests/unit/simulators/test_batched_clustered_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_generate_batched_clustered_binary_dataset_delegates_to_validation(datas
def test_generate_batched_clustered_binary_dataset_reproducibility(dataset_params):
output1 = generate_batched_clustered_binary_dataset(**dataset_params, random_seed=42)
output2 = generate_batched_clustered_binary_dataset(**dataset_params, random_seed=42)
for array1, array2 in zip(output1, output2):
for array1, array2 in zip(output1, output2, strict=True):
np.testing.assert_array_equal(array1, array2)


Expand Down
Loading