#11327·sktime

[BUG] CosineTransformer declares a domain of invertibility that does not hold

Author: aminmiralCreated Sep 28, 2026Updated Sep 28, 2026

Describe the bug

CosineTransformer sets capability:inverse_transform:range to [-pi, pi]. The tag is documented in registry/_tags.py as the domain of invertibility, with lower and upper bounds, and capability:inverse_transform:exact defaults to True and is not overridden — so the estimator promises an exact inverse on [-pi, pi].

No inverse exists on that interval: cos is not injective there, cos(-1) == cos(1) exactly. The inverse is np.arccos, whose range is [0, pi], so arccos(cos(x)) == x holds on [0, pi] and nowhere else. On [-pi, 0) it returns -x.

To Reproduce

python
import numpy as np
import pandas as pd
from sktime.transformations.cos import CosineTransformer

t = CosineTransformer()
declared = t.get_tag("capability:inverse_transform:range")   # [-pi, pi]

X = pd.DataFrame({"a": np.linspace(declared[0], declared[1], 13)})
Xit = t.fit(X).inverse_transform(t.transform(X))

print((X - Xit).abs().max().iloc[0])   # 6.283  -- inside the declared domain

Sampling [0, pi] instead gives 1.1e-16. Individually, -1.0 comes back as 1.0 and -2.0 as 2.0.

Expected behavior

The tag names an interval on which the round trip holds, i.e. [0, pi].

Additional context

Introduced in #3671, which added the tag mechanism; the value has not changed since. CosineTransformer is the only estimator in sktime that sets this tag to a non-None value.

It currently fails nothing. test_transform_inverse_transform_equivalent masks to the declared interval and asserts the round trip there, and is collected for CosineTransformer across 7 scenarios, but passes with either value because no scenario has data in [-pi, 0). test_capability_inverse_tag_is_correct only checks that _inverse_transform is implemented. The one runtime consumer, PluginParamsTransformer, clones the tag onto its wrapper, so the incorrect value propagates rather than being acted on.

Versions

sktime 1.2.0 | python 3.13.3 | pandas 2.3.3 | numpy 2.5.3 | Linux x86_64
main @ 80ea2efb9

LLM generated content, by Claude Opus 5. The measurements and the fix were produced with it; the contributor reviewed the diff and re-ran the tests.