Skip to content

fix(serialization): report effective values in reproducibility_report - #188

Open
ChrisW09 wants to merge 1 commit into
mainfrom
fix/187-reproducibility-report-values
Open

ChrisW09 wants to merge 1 commit into
mainfrom
fix/187-reproducibility-report-values

Conversation

@ChrisW09

Copy link
Copy Markdown
Collaborator

Fixes #187.

Preprocessor.reproducibility_report() echoed raw constructor values:

  • dtype as a class repr that changed after a spec round trip, while the fingerprint stayed the same;
  • output_format as the unresolved 'auto';
  • a NumPy random_state as is, which made json.dumps(report) fail.

Root cause

reproducibility_report (pretab/preprocessor.py) reported str(self.dtype), self.output_format and self.random_state unchanged.

Fix

  • dtype: str(np.dtype(self.dtype)), the NumPy dtype name ('float32', 'float64'), or None when unset.
  • output_format: getattr(self, "output_format_", self.output_format), the format resolved at fit. Specs written before output_format_ existed keep the requested value, as transform already does.
  • random_state: .item() of a NumPy scalar seed, so the report holds a Python int.

Everything else in the report, and fingerprint_, is unchanged.

Behaviour changes

  • report["dtype"] changes from e.g. "<class 'numpy.float32'>" to 'float32'.
  • report["output_format"] is 'dense' or 'sparse' for output_format="auto". Explicit "dense" / "sparse" requests report the same value as before.
  • report["random_state"] is a Python int for a NumPy seed.
  • A to_spec() / from_spec() round trip now leaves the report unchanged.

Documentation

  • reproducibility_report docstring (Returns): JSON-serializable values, the dtype name and the resolved format.
  • docs/core_concepts/reproducibility.md: the same, and that a spec round trip leaves the report unchanged.

Tests

In tests/integration/test_fingerprint.py:

  • test_reproducibility_report_names_the_output_dtype (None, np.float32, float, "float32"): the dtype name, and the same report after a JSON spec round trip. The np.float32 and float cases fail on main; None and the string are guards that pass on both.
  • test_reproducibility_report_gives_the_resolved_output_format: fails on main, passes here.
  • test_reproducibility_report_is_json_serializable_with_a_numpy_seed: fails on main, passes here.
  • The existing test_reproducibility_report_contents and the grouped replay tests that compare reports still pass.

Reproduction

The script from #187 on this branch:

dtype=<class 'numpy.float32'>: report 'float32', after spec replay 'float32', same fingerprint True
dtype=<class 'float'>: report 'float64', after spec replay 'float64', same fingerprint True
output_format: report 'sparse' | fitted output_format_ 'sparse' | transform returns csr_matrix
json.dumps(report): OK

Checks

  • just test: 4682 passed, 59 skipped, 7 xfailed; coverage 95.71% (gate 90%).
  • Minimum dependencies (CI job: Python 3.11, numpy 1.24.4, pandas 2.0.3, scipy 1.10.1, scikit-learn 1.6.0): 4499 passed, 173 skipped, 7 xfailed; scripts/quickstart.py passes.
  • just docs: strict build succeeds.
  • just check: all pre-commit and pre-push hooks pass (file hygiene, ruff format, ruff lint, prettier, pyright with 0 errors).
  • The change stays inside the facade's report method; no import direction changes.

Merge notes

The report copied constructor attributes: dtype as str(dtype) (a class
repr that changed after a spec round trip with an unchanged
fingerprint), output_format as the request ("auto" rather than the
fitted format), and random_state as given, so a NumPy seed made
json.dumps(report) fail.

It now reports the NumPy dtype name, the output format resolved at fit
(falling back to the request for older specs) and a NumPy seed as a
Python int.

Fixes #187

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reproducibility_report() echoes raw constructor values: dtype as a class repr, unresolved output_format, non-JSON NumPy seed

1 participant