Skip to content

Commit

Permalink
Rename transform parameter to trans
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Jun 26, 2022
1 parent 4a900d9 commit 69ae545
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion seaborn/_core/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 12 additions & 10 deletions seaborn/_core/scales.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
20 changes: 10 additions & 10 deletions tests/_core/test_scales.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand All @@ -193,28 +193,28 @@ 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])

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()
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 69ae545

Please sign in to comment.