From a277bd25775c3cc14e258d82761b4fc9bcb8b6de Mon Sep 17 00:00:00 2001 From: Hassan Kibirige Date: Wed, 31 Jul 2024 17:03:05 +0300 Subject: [PATCH] TYP: Raw to User as suffix user api typealiases --- plotnine/scales/scale.py | 14 +++++++------- plotnine/scales/scale_continuous.py | 20 +++++++++++--------- plotnine/scales/scale_discrete.py | 12 ++++++------ plotnine/typing.py | 26 ++++++++++++-------------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/plotnine/scales/scale.py b/plotnine/scales/scale.py index b28083db4..badac5a76 100644 --- a/plotnine/scales/scale.py +++ b/plotnine/scales/scale.py @@ -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, ): @@ -52,14 +52,14 @@ 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 @@ -67,7 +67,7 @@ class scale( """ # 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. diff --git a/plotnine/scales/scale_continuous.py b/plotnine/scales/scale_continuous.py index 1b2ec312d..7ea049b53 100644 --- a/plotnine/scales/scale_continuous.py +++ b/plotnine/scales/scale_continuous.py @@ -35,7 +35,7 @@ from plotnine.typing import ( CoordRange, ScaleLabels, - ScaleMinorBreaksRaw, + ScaleMinorBreaksUser, TFloatArrayLike, ) @@ -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 @@ -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, @@ -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. @@ -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. @@ -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 diff --git a/plotnine/scales/scale_discrete.py b/plotnine/scales/scale_discrete.py index 8f6c2d410..69f9158ce 100644 --- a/plotnine/scales/scale_discrete.py +++ b/plotnine/scales/scale_discrete.py @@ -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] ) @@ -44,8 +44,8 @@ class scale_discrete( scale[ RangeDiscrete, - DiscreteBreaksRaw, - DiscreteLimitsRaw, + DiscreteBreaksUser, + DiscreteLimitsUser, Literal["legend"] | None, ] ): @@ -53,7 +53,7 @@ class scale_discrete( 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 @@ -61,7 +61,7 @@ class scale_discrete( `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 diff --git a/plotnine/typing.py b/plotnine/typing.py index 46e302f3e..c5d39791d 100644 --- a/plotnine/typing.py +++ b/plotnine/typing.py @@ -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] @@ -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] @@ -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", @@ -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]