[ENH] use logging instead of print for verbose output in HIVE-COTE classifiers (and elsewhere)
Describe the bug
Several estimators report progress with plain print() calls, switched on by a verbose parameter. The output always goes to stdout and bypasses the logging module, so it cannot be filtered, redirected or silenced with standard logging handlers.
For example, in HIVECOTEV2._fit (_hivecote_v2.py):
if self.verbose > 0:
print("STC ", datetime.now().strftime("%H:%M:%S %d/%m/%Y"))HIVECOTEV1 does the same (11 calls), as do ElasticEnsemble, ProximityForest, the shapelet transform and some deep learning / foundation-model wrappers.
This causes three problems:
- users cannot send, filter or silence this output with standard
logginghandlers - output always goes to stdout, which clutters logs in pipelines, notebooks and benchmarking runs
- output control is inconsistent across the codebase, since other modules (e.g.
utils/parallel.py,transformations/compose/_logger.py) already uselogging
To Reproduce
import logging
from sktime.classification.hybrid import HIVECOTEV2
from sktime.datasets import load_unit_test
X_train, y_train = load_unit_test(split="train", return_X_y=True)
logging.basicConfig(level=logging.DEBUG) # attach a root handler at the lowest level
clf = HIVECOTEV2(verbose=1) # [TODO: add small-parameter settings so this runs quickly]
clf.fit(X_train, y_train)Progress messages are written to stdout via print(). The logging handler receives nothing, so it cannot filter or redirect them.
Expected behavior
Progress messages should go through logging, so users can control them with standard handlers and levels.
Proposed first step, limited to the two HIVE-COTE classifiers, which are small and self-contained:
- add a module-level
logger = logging.getLogger(__name__) - replace the
print(...)calls withlogger.info(...)(ordebug) - keep the current behavior of
verbose: withverbose > 0, users should still see the progress messages by default, so nothing breaks - update the
verbosedocstring, which currently says "Level of output printed to the console" - add a test (via
caplog/capsys) checking that output is still produced whenverbose=1
If this works, the same pattern can be applied to the other estimators in follow-up PRs.
Additional context Alternatives considered:
- Replace
printwithlogger.infodirectly. This is the simplest option, but it quietly changes behavior: Python's default logger only shows WARNING and above, soverbose=1would print nothing unless the user configures logging. - Log unconditionally and deprecate
verbose. This is cleaner in the long run, but it changes the public API and needs a deprecation cycle. - Add a shared helper in
sktime.utilsthat respectsverboseand sends output throughlogging. This gives consistent behavior across estimators, but it is a larger design decision.
Which approach would the maintainers prefer? I'm happy to implement the HIVE-COTE part once there's agreement.
Classification modules that use print() for this, outside of tests/doctests:
classification/hybrid/_hivecote_v1.pyclassification/hybrid/_hivecote_v2.pyclassification/distance_based/_elastic_ensemble.pyclassification/distance_based/_proximity_forest.pyclassification/deep_learning/_pytorch.pyclassification/deep_learning/base/_base_torch.pyclassification/foundation_models/momentfm.py
Source: sktime/sktime