Skip to content

Commit

Permalink
TYP: Raw to User as suffix user api typealiases
Browse files Browse the repository at this point in the history
  • Loading branch information
has2k1 committed Jul 31, 2024
1 parent 56e1dc7 commit a277bd2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
14 changes: 7 additions & 7 deletions plotnine/scales/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@
ScaleBreaks,
ScaledAestheticsName,
ScaleLabels,
ScaleLabelsRaw,
ScaleLabelsUser,
ScaleLimits,
)

from ..iapi import range_view, scale_view

RangeT = TypeVar("RangeT", bound=Range)
BreaksRawT = TypeVar("BreaksRawT")
LimitsRawT = TypeVar("LimitsRawT")
BreaksUserT = TypeVar("BreaksUserT")
LimitsUserT = TypeVar("LimitsUserT")
GuideTypeT = TypeVar("GuideTypeT")


@dataclass(kw_only=True)
class scale(
Generic[RangeT, BreaksRawT, LimitsRawT, GuideTypeT],
Generic[RangeT, BreaksUserT, LimitsUserT, GuideTypeT],
ABC,
metaclass=Register,
):
Expand All @@ -52,22 +52,22 @@ class scale(
"""

# # major breaks
breaks: BreaksRawT
breaks: BreaksUserT
"""
List of major break points. Or a callable that takes a tuple of limits
and returns a list of breaks. If `True`, automatically calculate the
breaks.
"""

limits: LimitsRawT
limits: LimitsUserT
"""
Limits of the scale. Most commonly, these are the min & max values
for the scales. For scales that deal with categoricals, these may be a
subset or superset of the categories.
"""

# labels at the breaks
labels: ScaleLabelsRaw = True
labels: ScaleLabelsUser = True
"""
Labels at the `breaks`. Alternatively, a callable that takes an
array_like of break points as input and returns a list of strings.
Expand Down
20 changes: 11 additions & 9 deletions plotnine/scales/scale_continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from plotnine.typing import (
CoordRange,
ScaleLabels,
ScaleMinorBreaksRaw,
ScaleMinorBreaksUser,
TFloatArrayLike,
)

Expand All @@ -47,13 +47,13 @@
ContinuousPalette: TypeAlias = "Callable[[FloatArrayLike], AnyArrayLike]"
ContinuousBreaks: TypeAlias = Sequence[float]
ContinuousLimits: TypeAlias = tuple[float, float]
ContinuousBreaksRaw: TypeAlias = (
ContinuousBreaksUser: TypeAlias = (
bool
| None
| ContinuousBreaks
| Callable[[ContinuousLimits], ContinuousBreaks]
)
ContinuousLimitsRaw: TypeAlias = (
ContinuousLimitsUser: TypeAlias = (
None | ContinuousLimits | Callable[[ContinuousLimits], ContinuousLimits]
)
TransUser: TypeAlias = trans | str | Type[trans] | None
Expand All @@ -63,8 +63,8 @@
class scale_continuous(
scale[
RangeContinuous,
ContinuousBreaksRaw,
ContinuousLimitsRaw,
ContinuousBreaksUser,
ContinuousLimitsUser,
# subclasses are still generic and must specify the
# type of the guide
GuideTypeT,
Expand All @@ -79,7 +79,7 @@ class scale_continuous(
keyword arguments.
"""

limits: ContinuousLimitsRaw = None
limits: ContinuousLimitsUser = None
"""
Limits of the scale. Most commonly, these are the minimum & maximum
values for the scale. If not specified they are derived from the data.
Expand All @@ -100,12 +100,12 @@ class scale_continuous(
is to turn them into `np.nan`, which then get dropped.
"""

breaks: ContinuousBreaksRaw = True
breaks: ContinuousBreaksUser = True
"""
Major breaks
"""

minor_breaks: ScaleMinorBreaksRaw = True
minor_breaks: ScaleMinorBreaksUser = True
"""
If a list-like, it is the minor breaks points. If an integer, it is the
number of minor breaks between any set of major breaks.
Expand All @@ -127,7 +127,9 @@ def __post_init__(self):
self._trans = self._make_trans()
self.limits = self._prep_limits(self.limits)

def _prep_limits(self, value: ContinuousLimitsRaw) -> ContinuousLimitsRaw:
def _prep_limits(
self, value: ContinuousLimitsUser
) -> ContinuousLimitsUser:
"""
Limits for the continuous scale
Expand Down
12 changes: 6 additions & 6 deletions plotnine/scales/scale_discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
DiscretePalette: TypeAlias = "Callable[[int], AnyArrayLike | dict[Any, Any]]"
DiscreteBreaks: TypeAlias = Sequence[str]
DiscreteLimits: TypeAlias = Sequence[str]
DiscreteBreaksRaw: TypeAlias = (
DiscreteBreaksUser: TypeAlias = (
bool | None | DiscreteBreaks | Callable[[DiscreteLimits], DiscreteBreaks]
)
DiscreteLimitsRaw: TypeAlias = (
DiscreteLimitsUser: TypeAlias = (
None | DiscreteLimits | Callable[[DiscreteLimits], DiscreteLimits]
)

Expand All @@ -44,24 +44,24 @@
class scale_discrete(
scale[
RangeDiscrete,
DiscreteBreaksRaw,
DiscreteLimitsRaw,
DiscreteBreaksUser,
DiscreteLimitsUser,
Literal["legend"] | None,
]
):
"""
Base class for all discrete scales
"""

limits: DiscreteLimitsRaw = None
limits: DiscreteLimitsUser = None
"""
Limits of the scale. These are the categories (unique values) of
the variables. If is only a subset of the values, those that are
left out will be treated as missing data and represented with a
`na_value`.
"""

breaks: DiscreteBreaksRaw = True
breaks: DiscreteBreaksUser = True
"""
List of major break points. Or a callable that takes a tuple of limits
and returns a list of breaks. If `True`, automatically calculate the
Expand Down
26 changes: 12 additions & 14 deletions plotnine/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ def to_pandas(self) -> pd.DataFrame:
ScaleDiscreteLimits: TypeAlias = Sequence[str]
ScaleLimits: TypeAlias = ScaleContinuousLimits | ScaleDiscreteLimits

ScaleLimitsRaw: TypeAlias = (
ScaleLimitsUser: TypeAlias = (
None | ScaleLimits | Callable[[ScaleLimits], ScaleLimits]
)
ScaleContinuousLimitsRaw: TypeAlias = (
ScaleContinuousLimitsUser: TypeAlias = (
None
| ScaleContinuousLimits
| Callable[[ScaleContinuousLimits], ScaleContinuousLimits]
)
ScaleDiscreteLimitsRaw: TypeAlias = (
ScaleDiscreteLimitsUser: TypeAlias = (
None
| ScaleDiscreteLimits
| Callable[[ScaleDiscreteLimits], ScaleDiscreteLimits]
Expand All @@ -134,25 +134,25 @@ def to_pandas(self) -> pd.DataFrame:
ScaleDiscreteBreaks: TypeAlias = Sequence[str]
ScaleBreaks: TypeAlias = ScaleContinuousBreaks | ScaleDiscreteBreaks

ScaleBreaksRaw: TypeAlias = (
ScaleBreaksUser: TypeAlias = (
bool | None | ScaleBreaks | Callable[[ScaleLimits], ScaleBreaks]
)
ScaleContinuousBreaksRaw: TypeAlias = (
ScaleContinuousBreaksUser: TypeAlias = (
bool
| None
| ScaleContinuousBreaks
| Callable[[ScaleContinuousLimits], ScaleContinuousBreaks]
)
ScaleDiscreteBreaksRaw: TypeAlias = (
ScaleDiscreteBreaksUser: TypeAlias = (
bool
| None
| ScaleDiscreteBreaks
| Callable[[ScaleDiscreteLimits], ScaleDiscreteBreaks]
)
ScaleMinorBreaksRaw: TypeAlias = ScaleContinuousBreaksRaw | int
ScaleMinorBreaksUser: TypeAlias = ScaleContinuousBreaksUser | int

# Labels
ScaleLabelsRaw: TypeAlias = (
ScaleLabelsUser: TypeAlias = (
bool
| None
| Sequence[str]
Expand Down Expand Up @@ -182,11 +182,11 @@ def to_pandas(self) -> pd.DataFrame:
# A array variable we can pass to a transforming function and expect
# result to be of the same type
TFloatArrayLike = TypeVar("TFloatArrayLike", bound=FloatArrayLike)
BreaksRawT = TypeVar(
"BreaksRawT", ScaleDiscreteBreaksRaw, ScaleContinuousBreaksRaw
BreaksUserT = TypeVar(
"BreaksUserT", ScaleDiscreteBreaksUser, ScaleContinuousBreaksUser
)
LimitsRawT = TypeVar(
"LimitsRawT", ScaleDiscreteLimitsRaw, ScaleContinuousLimitsRaw
LimitsUserT = TypeVar(
"LimitsUserT", ScaleDiscreteLimitsUser, ScaleContinuousLimitsUser
)
GuideTypeT = TypeVar(
"GuideTypeT",
Expand All @@ -204,8 +204,6 @@ def to_pandas(self) -> pd.DataFrame:
"TContinuousDomainDType", float, datetime, timedelta
)

# TBreaksRaw = TDiscreteBreaksRaw | TContinuousBreaksRaw

# Column transformation function
TransformCol: TypeAlias = Callable[[FloatSeries], FloatSeries | FloatArray]

Expand Down

0 comments on commit a277bd2

Please sign in to comment.