Skip to content

Commit

Permalink
Clear out some TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Oct 9, 2021
1 parent 636f868 commit 6cb5470
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 35 deletions.
50 changes: 16 additions & 34 deletions seaborn/_core/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def _homogenize_values(self, values):

def setup(
self,
data: Series, # TODO generally rename Series arguments to distinguish from DF?
scale: Scale | None = None, # TODO or always have a Scale?
data: Series,
scale: Scale | None = None,
) -> SemanticMapping:

raise NotImplementedError()
Expand Down Expand Up @@ -116,8 +116,8 @@ def _default_values(self, n: int) -> list:

def setup(
self,
data: Series, # TODO generally rename Series arguments to distinguish from DF?
scale: Scale | None = None, # TODO or always have a Scale?
data: Series,
scale: Scale | None = None,
) -> LookupMapping:

values = self._values
Expand Down Expand Up @@ -147,13 +147,11 @@ def _default_values(self, n: int) -> list:
warnings.warn(msg, UserWarning)
return [x for x, _ in zip(itertools.cycle([True, False]), range(n))]

# TODO Should we have some generalied way of doing input checking?


class ContinuousSemantic(Semantic):

norm: Normalize
transform: Callable # TODO sort out argument typing in a way that satisfies mypy
transform: RangeTransform
_default_range: tuple[float, float] = (0, 1)

def __init__(
Expand Down Expand Up @@ -187,8 +185,8 @@ def _infer_map_type(

def setup(
self,
data: Series, # TODO generally rename Series arguments to distinguish from DF?
scale: Scale | None = None, # TODO or always have a Scale?
data: Series,
scale: Scale | None = None,
) -> NormedMapping | LookupMapping:

values = self.default_range if self._values is None else self._values
Expand Down Expand Up @@ -219,7 +217,6 @@ def setup(
elif map_type == "categorical":

if isinstance(values, tuple):
# TODO even spacing between these values, large to small?
numbers = np.linspace(1, 0, len(levels))
transform = RangeTransform(values)
mapping_dict = dict(zip(levels, transform(numbers)))
Expand Down Expand Up @@ -253,8 +250,8 @@ def __init__(self, palette: PaletteSpec = None, variable: str = "color"):

def setup(
self,
data: Series, # TODO generally rename Series arguments to distinguish from DF?
scale: Scale | None = None, # TODO or always have a Scale?
data: Series,
scale: Scale | None = None,
) -> LookupMapping | NormedMapping:
"""Infer the type of mapping to use and define it using this vector of data."""
mapping: LookupMapping | NormedMapping
Expand Down Expand Up @@ -352,7 +349,6 @@ def _setup_numeric(
cmap = color_palette(palette, as_cmap=True)

# Now sort out the data normalization
# TODO consolidate in ScaleWrapper so we always have a Normalize here?
if norm is None:
norm = mpl.colors.Normalize()
elif isinstance(norm, tuple):
Expand Down Expand Up @@ -391,10 +387,6 @@ class MarkerSemantic(DiscreteSemantic):
# TODO full types
def __init__(self, shapes: list | dict | None = None, variable: str = "marker"):

# TODO fill or filled parameter?
# allow singletons? e.g. map_marker(shapes="o", filled=[True, False])?
# allow full matplotlib fillstyle API?

if isinstance(shapes, list):
shapes = [MarkerStyle(s) for s in shapes]
elif isinstance(shapes, dict):
Expand Down Expand Up @@ -443,14 +435,13 @@ def _default_values(self, n: int) -> list[MarkerStyle]:
])
s += 1

# TODO use filled (maybe have different defaults depending on fill/nofill?)
markers = [MarkerStyle(m) for m in markers]

# TODO or have this as an infinite generator?
return markers[:n]


# TODO or linestyle?
# TODO or LineStyle?
class DashSemantic(DiscreteSemantic):

def __init__(
Expand Down Expand Up @@ -560,40 +551,35 @@ class HatchSemantic(DiscreteSemantic):
...


# TODO allow subclass to define validation function for values?


# TODO markersize? pointsize? How to specify diameter but scale area?
class AreaSemantic(ContinuousSemantic):
...


class WidthSemantic(ContinuousSemantic):

_default_range = .2, .8


class LineWidthSemantic(ContinuousSemantic):
# TODO or opacity?
class AlphaSemantic(ContinuousSemantic):
_default_range = .3, 1


class LineWidthSemantic(ContinuousSemantic):
@property
def default_range(self) -> tuple[float, float]:
base = mpl.rcParams["lines.linewidth"]
return base * .5, base * 2


class EdgeWidthSemantic(ContinuousSemantic):

@property
def default_range(self) -> tuple[float, float]:
# TODO use patch.linewidth or lines.markeredgewidth here?
base = mpl.rcParams["patch.linewidth"]
return base * .5, base * 2


# TODO or opacity?
class AlphaSemantic(ContinuousSemantic):
...


# ==================================================================================== #

class SemanticMapping:
Expand Down Expand Up @@ -626,10 +612,6 @@ def __init__(self, norm: Normalize, transform: Callable[[ArrayLike], Any]):

def __call__(self, x: Any) -> Any:

# TODO can we work out whether transform is vectorized and use it that way?
# (Or ensure that it is, since we control it?)
# TODO note that matplotlib Normalize is going to return a masked array
# maybe this is fine since we're handing the output off to matplotlib?
if isinstance(x, pd.Series):
# Compatability for matplotlib<3.4.3
# https://github.com/matplotlib/matplotlib/pull/20511
Expand Down
1 change: 0 additions & 1 deletion seaborn/tests/_core/test_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from numpy.testing import assert_array_equal
from pandas.testing import assert_series_equal

# TODO from seaborn._compat import MarkerStyle
from seaborn._compat import MarkerStyle
from seaborn._core.rules import categorical_order
from seaborn._core.scales import ScaleWrapper, CategoricalScale
Expand Down

0 comments on commit 6cb5470

Please sign in to comment.