diff --git a/seaborn/_core/properties.py b/seaborn/_core/properties.py index b8a6b72851..8a6a4a6523 100644 --- a/seaborn/_core/properties.py +++ b/seaborn/_core/properties.py @@ -86,7 +86,7 @@ def infer_scale(self, arg: Any, data: Series) -> Scale: if isinstance(arg, str): if any(arg.startswith(k) for k in trans_args): # TODO validate numeric type? That should happen centrally somewhere - return Continuous(transform=arg) + return Continuous(trans=arg) else: msg = f"Unknown magic arg for {self.variable} scale: '{arg}'." raise ValueError(msg) diff --git a/seaborn/_core/scales.py b/seaborn/_core/scales.py index 452e7d1bf2..ca61714740 100644 --- a/seaborn/_core/scales.py +++ b/seaborn/_core/scales.py @@ -368,7 +368,7 @@ def spacer(x): def _get_transform(self): - arg = self.transform + arg = self.trans def get_param(method, default): if arg == method: @@ -407,7 +407,7 @@ class Continuous(ContinuousBase): A numeric scale supporting norms and functional transforms. """ values: tuple | str | None = None - transform: str | Transforms | None = None + trans: str | Transforms | None = None # TODO Add this to deal with outliers? # outside: Literal["keep", "drop", "clip"] = "keep" @@ -455,7 +455,7 @@ def tick( f"Tick locator must be an instance of {Locator!r}, " f"not {type(locator)!r}." ) - log_base, symlog_thresh = self._parse_for_log_params(self.transform) + log_base, symlog_thresh = self._parse_for_log_params(self.trans) if log_base or symlog_thresh: if count is not None and between is None: raise RuntimeError("`count` requires `between` with log transform.") @@ -523,21 +523,23 @@ def label( } return new - def _parse_for_log_params(self, transform): + def _parse_for_log_params( + self, trans: str | Transforms | None + ) -> tuple[float | None, float | None]: log_base = symlog_thresh = None - if isinstance(transform, str): - m = re.match(r"^log(\d*)", transform) + if isinstance(trans, str): + m = re.match(r"^log(\d*)", trans) if m is not None: log_base = float(m[1] or 10) - m = re.match(r"symlog(\d*)", transform) + m = re.match(r"symlog(\d*)", trans) if m is not None: symlog_thresh = float(m[1] or 1) return log_base, symlog_thresh def _get_locators(self, locator, at, upto, count, every, between, minor): - log_base, symlog_thresh = self._parse_for_log_params(self.transform) + log_base, symlog_thresh = self._parse_for_log_params(self.trans) if locator is not None: major_locator = locator @@ -595,7 +597,7 @@ def _get_locators(self, locator, at, upto, count, every, between, minor): def _get_formatter(self, locator, formatter, like, base, unit): - log_base, symlog_thresh = self._parse_for_log_params(self.transform) + log_base, symlog_thresh = self._parse_for_log_params(self.trans) if base is None: if symlog_thresh: log_base = 10 @@ -646,7 +648,7 @@ class Temporal(ContinuousBase): # those yet, and having a clear distinction betewen date(time) / time # may be more useful. - transform = None + trans = None _priority: ClassVar[int] = 2 diff --git a/tests/_core/test_scales.py b/tests/_core/test_scales.py index 24d12e6aac..ca9b23047d 100644 --- a/tests/_core/test_scales.py +++ b/tests/_core/test_scales.py @@ -54,12 +54,12 @@ def test_coordinate_defaults(self, x): def test_coordinate_transform(self, x): - s = Continuous(transform="log")._setup(x, Coordinate()) + s = Continuous(trans="log")._setup(x, Coordinate()) assert_series_equal(s(x), np.log10(x)) def test_coordinate_transform_with_parameter(self, x): - s = Continuous(transform="pow3")._setup(x, Coordinate()) + s = Continuous(trans="pow3")._setup(x, Coordinate()) assert_series_equal(s(x), np.power(x, 3)) def test_interval_defaults(self, x): @@ -118,7 +118,7 @@ def test_color_with_transform(self, x): x = pd.Series([1, 10, 100], name="x", dtype=float) cmap = color_palette("ch:", as_cmap=True) - s = Continuous(transform="log")._setup(x, Color()) + s = Continuous(trans="log")._setup(x, Color()) assert_array_equal(s(x), cmap([0, .5, 1])[:, :3]) # FIXME RGBA def test_tick_locator(self, x): @@ -184,7 +184,7 @@ def test_tick_minor(self, x): def test_log_tick_default(self, x): - s = Continuous(transform="log")._setup(x, Coordinate()) + s = Continuous(trans="log")._setup(x, Coordinate()) a = PseudoAxis(s._matplotlib_scale) a.set_view_interval(.5, 1050) ticks = a.major.locator() @@ -193,16 +193,16 @@ def test_log_tick_default(self, x): def test_log_tick_upto(self, x): n = 3 - s = Continuous(transform="log").tick(upto=n)._setup(x, Coordinate()) + s = Continuous(trans="log").tick(upto=n)._setup(x, Coordinate()) a = PseudoAxis(s._matplotlib_scale) assert a.major.locator.numticks == n def test_log_tick_count(self, x): with pytest.raises(RuntimeError, match="`count` requires"): - Continuous(transform="log").tick(count=4) + Continuous(trans="log").tick(count=4) - s = Continuous(transform="log").tick(count=4, between=(1, 1000)) + s = Continuous(trans="log").tick(count=4, between=(1, 1000)) a = PseudoAxis(s._setup(x, Coordinate())._matplotlib_scale) a.set_view_interval(.5, 1050) assert_array_equal(a.major.locator(), [1, 10, 100, 1000]) @@ -210,11 +210,11 @@ def test_log_tick_count(self, x): def test_log_tick_every(self, x): with pytest.raises(RuntimeError, match="`every` not supported"): - Continuous(transform="log").tick(every=2) + Continuous(trans="log").tick(every=2) def test_symlog_tick_default(self, x): - s = Continuous(transform="symlog")._setup(x, Coordinate()) + s = Continuous(trans="symlog")._setup(x, Coordinate()) a = PseudoAxis(s._matplotlib_scale) a.set_view_interval(-1050, 1050) ticks = a.major.locator() @@ -275,7 +275,7 @@ def test_label_unit_with_sep(self, x): def test_label_base_from_transform(self, x): - s = Continuous(transform="log") + s = Continuous(trans="log") a = PseudoAxis(s._setup(x, Coordinate())._matplotlib_scale) a.set_view_interval(10, 1000) label, = a.major.formatter.format_ticks([100])