Skip to content

Conversation

@TaXxER
Copy link
Contributor

@TaXxER TaXxER commented Dec 19, 2025

Summary:
Code quality improvements for metrics.py following Google Python style guide:

Type annotations:

  • Removed unused imports (Dict, Tuple from typing)
  • Fixed **kwargs type hint from Dict[str, Any] to Any (the correct type for kwargs values)
  • Updated Tuple to lowercase tuple for Python 3.9+ style

Replaced assert statements with proper exceptions:

  • Production code should not use assert for validation since asserts can be disabled with -O flag
  • Converted 5 assert statements to raise ValueError() or raise AssertionError() in:
    • multi_cg_score: metric validation
    • kuiper_distribution: input validation for positive x
    • rank_multicalibration_error: segment weight validation
    • calibration_free_normalized_entropy: labels shape validation
    • wrap_multicalibration_error_metric: segment columns and metric version validation

Fixed variable shadowing:

  • calibration_ratio variable shadowed the function → renamed to ratio
  • fpr variables in fpr_with_mask and fpr_at_precision shadowed the function → renamed to false_positive_rate
  • normalized_entropy variable shadowed the function → renamed to ne

Extracted magic numbers to module-level constants:

  • Added KUIPER_STATISTIC_MAX and KUIPER_STATISTIC_MIN as documented constants
  • Removed duplicated local definitions inside kuiper_test()

Test cleanup:

  • Removed debug print() statement from test

Differential Revision: D89555477

@meta-codesync
Copy link

meta-codesync bot commented Dec 19, 2025

@TaXxER has exported this pull request. If you are a Meta employee, you can view the originating Diff in D89555477.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 19, 2025
Summary:

Code quality improvements for metrics.py following Google Python style guide:

**Type annotations:**
- Removed unused imports (`Dict`, `Tuple` from typing)
- Fixed `**kwargs` type hint from `Dict[str, Any]` to `Any` (the correct type for kwargs values)
- Updated `Tuple` to lowercase `tuple` for Python 3.9+ style

**Replaced assert statements with proper exceptions:**
- Production code should not use `assert` for validation since asserts can be disabled with `-O` flag
- Converted 5 `assert` statements to `raise ValueError()` or `raise AssertionError()` in:
  - `multi_cg_score`: metric validation
  - `kuiper_distribution`: input validation for positive x
  - `rank_multicalibration_error`: segment weight validation
  - `calibration_free_normalized_entropy`: labels shape validation
  - `wrap_multicalibration_error_metric`: segment columns and metric version validation

**Fixed variable shadowing:**
- `calibration_ratio` variable shadowed the function → renamed to `ratio`
- `fpr` variables in `fpr_with_mask` and `fpr_at_precision` shadowed the function → renamed to `false_positive_rate`
- `normalized_entropy` variable shadowed the function → renamed to `ne`

**Extracted magic numbers to module-level constants:**
- Added `KUIPER_STATISTIC_MAX` and `KUIPER_STATISTIC_MIN` as documented constants
- Removed duplicated local definitions inside `kuiper_test()`

**Test cleanup:**
- Removed debug `print()` statement from test

Reviewed By: Lorenzo-Perini

Differential Revision: D89555477
@meta-codesync
Copy link

meta-codesync bot commented Jan 5, 2026

This pull request has been merged in 516d884.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. fb-exported Merged meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants