Problem
best_fit has a fit_results parameter so users can pass pre-computed fit_all results to avoid re-fitting. This is an internal optimization concern leaking into the public API. It forces the user to manually wire data between the two methods:
results = dist.fit_all()
best_name, best_info = dist.best_fit(fit_results=results) # manual plumbing
The parameter also creates two calling modes (with/without fit_results), making the method signature harder to understand: method and distributions are silently ignored when fit_results is provided, which is not obvious to the caller.
Proposed Solution
fit_all stores its results on self._fit_results after computation.
best_fit reads from self._fit_results automatically. If no cached results exist, it calls fit_all internally.
- Remove the
fit_results parameter from best_fit entirely.
Before
dist = Distributions(data=data)
results = dist.fit_all()
best_name, best_info = dist.best_fit(fit_results=results)
After
dist = Distributions(data=data)
dist.fit_all() # cached on self
best_name, best_info = dist.best_fit() # uses cache automatically
# or skip fit_all entirely:
best_name, best_info = dist.best_fit() # calls fit_all internally, caches
Considerations
- Calling
fit_all again with different parameters (e.g., different method or distributions) should overwrite the cache. This is the expected behavior.
best_fit should still accept method, distributions, and criterion parameters. If best_fit is called and no cache exists, it calls fit_all(method=method, distributions=distributions) to populate the cache.
- Initialize
self._fit_results = None in __init__.
Scope
Depends On
Problem
best_fithas afit_resultsparameter so users can pass pre-computedfit_allresults to avoid re-fitting. This is an internal optimization concern leaking into the public API. It forces the user to manually wire data between the two methods:The parameter also creates two calling modes (with/without
fit_results), making the method signature harder to understand:methodanddistributionsare silently ignored whenfit_resultsis provided, which is not obvious to the caller.Proposed Solution
fit_allstores its results onself._fit_resultsafter computation.best_fitreads fromself._fit_resultsautomatically. If no cached results exist, it callsfit_allinternally.fit_resultsparameter frombest_fitentirely.Before
After
Considerations
fit_allagain with different parameters (e.g., differentmethodordistributions) should overwrite the cache. This is the expected behavior.best_fitshould still acceptmethod,distributions, andcriterionparameters. Ifbest_fitis called and no cache exists, it callsfit_all(method=method, distributions=distributions)to populate the cache.self._fit_results = Nonein__init__.Scope
self._fit_results = Noneto__init__fit_all: store results inself._fit_resultsbefore returningbest_fit: removefit_resultsparameter, read fromself._fit_resultsfit_results=usage, test caching behavior)Depends On