From 56e1dc7ef606025343ff27f899564792a323b2f1 Mon Sep 17 00:00:00 2001 From: Hassan Kibirige Date: Wed, 31 Jul 2024 16:29:15 +0300 Subject: [PATCH] TYP: Remove TupleFloat* and TupleInt* aliases --- plotnine/_mpl/_plot_side_space.py | 12 +++++------- plotnine/_mpl/_plotnine_tight_layout.py | 5 ++--- plotnine/_utils/__init__.py | 7 +++---- plotnine/coords/coord_cartesian.py | 7 +++---- plotnine/coords/coord_fixed.py | 5 ++--- plotnine/coords/coord_trans.py | 9 ++++----- plotnine/geoms/annotation_logticks.py | 17 +++++++---------- plotnine/geoms/annotation_stripes.py | 3 +-- plotnine/geoms/geom.py | 6 +++--- plotnine/geoms/geom_path.py | 7 +++---- plotnine/geoms/geom_point.py | 5 ++--- plotnine/geoms/geom_pointrange.py | 5 ++--- plotnine/geoms/geom_text.py | 6 +++--- plotnine/guides/guide.py | 10 ++++++---- plotnine/guides/guide_legend.py | 8 ++++---- plotnine/guides/guides.py | 4 ++-- plotnine/iapi.py | 15 +++++++-------- plotnine/qplot.py | 6 +++--- plotnine/scales/_expand.py | 14 +++++--------- plotnine/scales/range.py | 4 ++-- plotnine/scales/scale.py | 14 +++++++------- plotnine/scales/scale_continuous.py | 4 +--- plotnine/scales/scale_discrete.py | 8 +++----- plotnine/scales/scale_xy.py | 6 ++---- plotnine/stats/binning.py | 6 +++--- plotnine/themes/elements/element_line.py | 14 ++++++++++---- plotnine/themes/elements/element_rect.py | 20 +++++++++++++++----- plotnine/themes/elements/element_text.py | 21 ++++++++++++++------- plotnine/typing.py | 10 ++-------- 29 files changed, 126 insertions(+), 132 deletions(-) diff --git a/plotnine/_mpl/_plot_side_space.py b/plotnine/_mpl/_plot_side_space.py index 85410a37f..9f33800aa 100644 --- a/plotnine/_mpl/_plot_side_space.py +++ b/plotnine/_mpl/_plot_side_space.py @@ -37,8 +37,6 @@ from matplotlib.axis import Tick from matplotlib.text import Text - from plotnine.typing import TupleFloat2 - from .layout_engine import LayoutPack AxesLocation: TypeAlias = Literal[ @@ -113,7 +111,7 @@ def _fields_upto(item: str) -> Generator[Field, None, None]: return sum(getattr(self, f.name) for f in _fields_upto(item)) @cached_property - def _legend_size(self) -> TupleFloat2: + def _legend_size(self) -> tuple[float, float]: """ Return size of legend in figure coordinates @@ -184,7 +182,7 @@ def _calculate(self): self.plot_margin += adjustment @cached_property - def _legend_size(self) -> TupleFloat2: + def _legend_size(self) -> tuple[float, float]: if not (self.pack.legends and self.pack.legends.left): return (0, 0) @@ -233,7 +231,7 @@ def _calculate(self): self.plot_margin += adjustment @cached_property - def _legend_size(self) -> TupleFloat2: + def _legend_size(self) -> tuple[float, float]: if not (self.pack.legends and self.pack.legends.right): return (0, 0) @@ -304,7 +302,7 @@ def _calculate(self): self.plot_margin += adjustment @cached_property - def _legend_size(self) -> TupleFloat2: + def _legend_size(self) -> tuple[float, float]: if not (self.pack.legends and self.pack.legends.top): return (0, 0) @@ -379,7 +377,7 @@ def _calculate(self): self.plot_margin += adjustment @cached_property - def _legend_size(self) -> TupleFloat2: + def _legend_size(self) -> tuple[float, float]: if not (self.pack.legends and self.pack.legends.bottom): return (0, 0) diff --git a/plotnine/_mpl/_plotnine_tight_layout.py b/plotnine/_mpl/_plotnine_tight_layout.py index f7729148b..25574f769 100644 --- a/plotnine/_mpl/_plotnine_tight_layout.py +++ b/plotnine/_mpl/_plotnine_tight_layout.py @@ -28,7 +28,6 @@ from plotnine._mpl.offsetbox import FlexibleAnchoredOffsetbox from plotnine.facets.facet import facet from plotnine.iapi import legend_artists - from plotnine.typing import TupleFloat2 from .layout_engine import LayoutPack @@ -252,8 +251,8 @@ def set_legends_position( def set_position( aob: FlexibleAnchoredOffsetbox, - anchor_point: TupleFloat2, - xy_loc: TupleFloat2, + anchor_point: tuple[float, float], + xy_loc: tuple[float, float], transform: Transform = fig.transFigure, ): """ diff --git a/plotnine/_utils/__init__.py b/plotnine/_utils/__init__.py index bcd92d9ae..0c39f5c96 100644 --- a/plotnine/_utils/__init__.py +++ b/plotnine/_utils/__init__.py @@ -37,7 +37,6 @@ FloatArrayLike, IntArray, SidePosition, - TupleFloat2, ) T = TypeVar("T") @@ -50,7 +49,7 @@ # A lookup for the coordinates of specific named positions on # a unit square. -BOX_LOCATIONS: dict[str, TupleFloat2] = { +BOX_LOCATIONS: dict[str, tuple[float, float]] = { "left": (0, 0.5), "right": (1, 0.5), "top": (0.5, 1), @@ -1263,8 +1262,8 @@ def get_opposite_side(s: SidePosition) -> SidePosition: def ensure_xy_location( - loc: SidePosition | Literal["center"] | float | TupleFloat2, -) -> TupleFloat2: + loc: SidePosition | Literal["center"] | float | tuple[float, float], +) -> tuple[float, float]: """ Convert input into (x, y) location diff --git a/plotnine/coords/coord_cartesian.py b/plotnine/coords/coord_cartesian.py index 7dec37239..facc0d1c5 100644 --- a/plotnine/coords/coord_cartesian.py +++ b/plotnine/coords/coord_cartesian.py @@ -17,7 +17,6 @@ from plotnine.typing import ( FloatArray, FloatSeries, - TupleFloat2, ) @@ -40,8 +39,8 @@ class coord_cartesian(coord): def __init__( self, - xlim: Optional[TupleFloat2] = None, - ylim: Optional[TupleFloat2] = None, + xlim: Optional[tuple[float, float]] = None, + ylim: Optional[tuple[float, float]] = None, expand: bool = True, ): self.limits = SimpleNamespace(x=xlim, y=ylim) @@ -67,7 +66,7 @@ def setup_panel_params(self, scale_x: scale, scale_y: scale) -> panel_view: from mizani.transforms import identity_trans def get_scale_view( - scale: scale, coord_limits: TupleFloat2 + scale: scale, coord_limits: tuple[float, float] ) -> scale_view: expansion = scale.default_expansion(expand=self.expand) ranges = scale.expand_limits( diff --git a/plotnine/coords/coord_fixed.py b/plotnine/coords/coord_fixed.py index 63a053a8c..0fbe71ee4 100644 --- a/plotnine/coords/coord_fixed.py +++ b/plotnine/coords/coord_fixed.py @@ -8,7 +8,6 @@ from typing import Optional from plotnine.iapi import panel_view - from plotnine.typing import TupleFloat2 class coord_fixed(coord_cartesian): @@ -47,8 +46,8 @@ class coord_fixed(coord_cartesian): def __init__( self, ratio: float = 1, - xlim: Optional[TupleFloat2] = None, - ylim: Optional[TupleFloat2] = None, + xlim: Optional[tuple[float, float]] = None, + ylim: Optional[tuple[float, float]] = None, expand: bool = True, ): super().__init__(xlim=xlim, ylim=ylim, expand=expand) diff --git a/plotnine/coords/coord_trans.py b/plotnine/coords/coord_trans.py index e56423bc0..2d6c7d3e3 100644 --- a/plotnine/coords/coord_trans.py +++ b/plotnine/coords/coord_trans.py @@ -21,7 +21,6 @@ FloatArray, FloatSeries, TFloatArrayLike, - TupleFloat2, ) @@ -51,8 +50,8 @@ def __init__( self, x: str | trans = "identity", y: str | trans = "identity", - xlim: Optional[TupleFloat2] = None, - ylim: Optional[TupleFloat2] = None, + xlim: Optional[tuple[float, float]] = None, + ylim: Optional[tuple[float, float]] = None, expand: bool = True, ): from mizani.transforms import gettrans @@ -105,7 +104,7 @@ def setup_panel_params(self, scale_x: scale, scale_y: scale) -> panel_view: """ def get_scale_view( - scale: scale, coord_limits: TupleFloat2, trans: trans + scale: scale, coord_limits: tuple[float, float], trans: trans ) -> scale_view: if coord_limits: coord_limits = trans.transform(coord_limits) @@ -150,7 +149,7 @@ def distance( def transform_value( - trans: trans, value: TFloatArrayLike, range: TupleFloat2 + trans: trans, value: TFloatArrayLike, range: tuple[float, float] ) -> TFloatArrayLike: """ Transform value diff --git a/plotnine/geoms/annotation_logticks.py b/plotnine/geoms/annotation_logticks.py index df85bc966..00c3e6782 100644 --- a/plotnine/geoms/annotation_logticks.py +++ b/plotnine/geoms/annotation_logticks.py @@ -23,12 +23,7 @@ from plotnine.facets.layout import Layout from plotnine.geoms.geom import geom from plotnine.iapi import panel_view - from plotnine.typing import ( - AnyArray, - TupleFloat2, - TupleFloat3, - TupleFloat4, - ) + from plotnine.typing import AnyArray class _geom_logticks(geom_rug): @@ -69,7 +64,7 @@ def _check_log_scale( sides: str, panel_params: panel_view, coord: coord, - ) -> TupleFloat2: + ) -> tuple[float, float]: """ Check the log transforms @@ -135,7 +130,7 @@ def get_base(sc, ubase: Optional[float]) -> float: @staticmethod def _calc_ticks( - value_range: TupleFloat2, base: float + value_range: tuple[float, float], base: float ) -> tuple[AnyArray, AnyArray, AnyArray]: """ Calculate tick marks within a range @@ -268,11 +263,13 @@ def __init__( self, sides: str = "bl", alpha: float = 1, - color: str | TupleFloat3 | TupleFloat4 = "black", + color: str + | tuple[float, float, float] + | tuple[float, float, float, float] = "black", size: float = 0.5, linetype: Literal["solid", "dashed", "dashdot", "dotted"] | Sequence[float] = "solid", - lengths: TupleFloat3 = (0.036, 0.0225, 0.012), + lengths: tuple[float, float, float] = (0.036, 0.0225, 0.012), base: float | None = None, ): if len(lengths) != 3: diff --git a/plotnine/geoms/annotation_stripes.py b/plotnine/geoms/annotation_stripes.py index d4590513a..1185b17dc 100644 --- a/plotnine/geoms/annotation_stripes.py +++ b/plotnine/geoms/annotation_stripes.py @@ -21,7 +21,6 @@ from plotnine.coords.coord import coord from plotnine.facets.layout import Layout from plotnine.iapi import panel_view - from plotnine.typing import TupleFloat2 class annotation_stripes(annotate): @@ -62,7 +61,7 @@ def __init__( fill: Sequence[str] = ("#AAAAAA", "#CCCCCC"), fill_range: Literal["auto", "cycle", "no", "nocycle"] = "auto", direction: Literal["horizontal", "vertical"] = "vertical", - extend: TupleFloat2 = (0, 1), + extend: tuple[float, float] = (0, 1), **kwargs: Any, ): allowed = ("vertical", "horizontal") diff --git a/plotnine/geoms/geom.py b/plotnine/geoms/geom.py index 25b8741e8..5d94751db 100644 --- a/plotnine/geoms/geom.py +++ b/plotnine/geoms/geom.py @@ -31,7 +31,7 @@ from plotnine.facets.layout import Layout from plotnine.iapi import panel_view from plotnine.mapping import Environment - from plotnine.typing import DataLike, TupleInt2 + from plotnine.typing import DataLike class geom(ABC, metaclass=Register): @@ -534,8 +534,8 @@ def draw_legend( @staticmethod def legend_key_size( - data: pd.Series[Any], min_size: TupleInt2, lyr: layer - ) -> TupleInt2: + data: pd.Series[Any], min_size: tuple[int, int], lyr: layer + ) -> tuple[int, int]: """ Calculate the size of key that would fit the layer contents diff --git a/plotnine/geoms/geom_path.py b/plotnine/geoms/geom_path.py index 63e83ea8a..206f9a159 100644 --- a/plotnine/geoms/geom_path.py +++ b/plotnine/geoms/geom_path.py @@ -24,7 +24,6 @@ from plotnine.coords.coord import coord from plotnine.iapi import panel_view from plotnine.layer import layer - from plotnine.typing import TupleFloat2, TupleInt2 @document @@ -214,8 +213,8 @@ def draw_legend( @staticmethod def legend_key_size( - data: pd.Series[Any], min_size: TupleInt2, lyr: layer - ) -> TupleInt2: + data: pd.Series[Any], min_size: tuple[int, int], lyr: layer + ) -> tuple[int, int]: w, h = min_size pad_w, pad_h = w * 0.5, h * 0.5 _w = _h = data.get("size", 0) * SIZE_FACTOR @@ -538,7 +537,7 @@ def _get_joinstyle( return d -def _axes_get_size_inches(ax: Axes) -> TupleFloat2: +def _axes_get_size_inches(ax: Axes) -> tuple[float, float]: """ Size of axes in inches diff --git a/plotnine/geoms/geom_point.py b/plotnine/geoms/geom_point.py index 061312de3..3ff569e76 100644 --- a/plotnine/geoms/geom_point.py +++ b/plotnine/geoms/geom_point.py @@ -19,7 +19,6 @@ from plotnine.coords.coord import coord from plotnine.iapi import panel_view from plotnine.layer import layer - from plotnine.typing import TupleInt2 @document @@ -164,8 +163,8 @@ def draw_legend( @staticmethod def legend_key_size( - data: pd.Series[Any], min_size: TupleInt2, lyr: layer - ) -> TupleInt2: + data: pd.Series[Any], min_size: tuple[int, int], lyr: layer + ) -> tuple[int, int]: w, h = min_size pad_w, pad_h = w * 0.5, h * 0.5 _size = data["size"] * SIZE_FACTOR diff --git a/plotnine/geoms/geom_pointrange.py b/plotnine/geoms/geom_pointrange.py index 4edb26102..d79a8bbff 100644 --- a/plotnine/geoms/geom_pointrange.py +++ b/plotnine/geoms/geom_pointrange.py @@ -19,7 +19,6 @@ from plotnine.coords.coord import coord from plotnine.iapi import panel_view from plotnine.layer import layer - from plotnine.typing import TupleInt2 @document @@ -96,8 +95,8 @@ def draw_legend( @staticmethod def legend_key_size( - data: pd.Series[Any], min_size: TupleInt2, lyr: layer - ) -> TupleInt2: + data: pd.Series[Any], min_size: tuple[int, int], lyr: layer + ) -> tuple[int, int]: data = copy(data) data["size"] = data["size"] * lyr.geom.params["fatten"] data["stroke"] = geom_point.DEFAULT_AES["stroke"] diff --git a/plotnine/geoms/geom_text.py b/plotnine/geoms/geom_text.py index 97c3437f4..a8b9b4327 100644 --- a/plotnine/geoms/geom_text.py +++ b/plotnine/geoms/geom_text.py @@ -23,7 +23,7 @@ from plotnine.coords.coord import coord from plotnine.iapi import panel_view from plotnine.layer import layer - from plotnine.typing import DataLike, TupleInt2 + from plotnine.typing import DataLike # Note: hjust & vjust are parameters instead of aesthetics @@ -361,8 +361,8 @@ def draw_legend( @staticmethod def legend_key_size( - data: pd.Series[Any], min_size: TupleInt2, lyr: layer - ) -> TupleInt2: + data: pd.Series[Any], min_size: tuple[int, int], lyr: layer + ) -> tuple[int, int]: w, h = min_size _w = _h = data["size"] if data["color"] is not None: diff --git a/plotnine/guides/guide.py b/plotnine/guides/guide.py index e80f70b7e..7660ff97c 100644 --- a/plotnine/guides/guide.py +++ b/plotnine/guides/guide.py @@ -24,7 +24,6 @@ LegendPosition, Orientation, SidePosition, - TupleFloat2, ) from .guides import GuidesElements @@ -123,7 +122,10 @@ def setup(self, guides: guides): @property def _resolved_position_justification( self, - ) -> tuple[SidePosition, float] | tuple[TupleFloat2, TupleFloat2]: + ) -> ( + tuple[SidePosition, float] + | tuple[tuple[float, float], tuple[float, float]] + ): """ Return the final position & justification to draw the guide """ @@ -240,7 +242,7 @@ def direction(self) -> Orientation: return direction @cached_property - def position(self) -> SidePosition | TupleFloat2: + def position(self) -> SidePosition | tuple[float, float]: if (guide_pos := self.guide.position) == "inside": guide_pos = self._position_inside @@ -252,7 +254,7 @@ def position(self) -> SidePosition | TupleFloat2: return pos @cached_property - def _position_inside(self) -> SidePosition | TupleFloat2: + def _position_inside(self) -> SidePosition | tuple[float, float]: pos = self.theme.getp("legend_position_inside") if isinstance(pos, tuple): return pos diff --git a/plotnine/guides/guide_legend.py b/plotnine/guides/guide_legend.py index 28de9f77e..06d56cad9 100644 --- a/plotnine/guides/guide_legend.py +++ b/plotnine/guides/guide_legend.py @@ -25,7 +25,7 @@ from plotnine.geoms.geom import geom from plotnine.layer import layer - from plotnine.typing import SidePosition, TupleFloat2, TupleInt2 + from plotnine.typing import SidePosition # See guides.py for terminology @@ -208,7 +208,7 @@ def create_geoms(self): def _calculate_rows_and_cols( self, elements: GuideElementsLegend - ) -> TupleInt2: + ) -> tuple[int, int]: nrow, ncol = self.nrow, self.ncol nbreak = len(self.key) @@ -395,7 +395,7 @@ def key_spacing_y(self) -> float: return self.theme.getp("legend_key_spacing_y", 0) @cached_property - def _key_dimensions(self) -> list[TupleFloat2]: + def _key_dimensions(self) -> list[tuple[float, float]]: """ key width and key height for each legend entry @@ -410,7 +410,7 @@ def _key_dimensions(self) -> list[TupleFloat2]: ) # Find the size that fits each key in the legend, - sizes: list[list[TupleFloat2]] = [] + sizes: list[list[tuple[float, float]]] = [] for params in guide._layer_parameters: sizes.append([]) get_key_size = params.geom.legend_key_size diff --git a/plotnine/guides/guides.py b/plotnine/guides/guides.py index 853115dd5..b6faa203c 100644 --- a/plotnine/guides/guides.py +++ b/plotnine/guides/guides.py @@ -37,7 +37,6 @@ ScaledAestheticsName, SidePosition, TextJustification, - TupleFloat2, ) LegendOrColorbar: TypeAlias = ( @@ -327,7 +326,8 @@ def _anchored_offset_box(boxes: list[PackerBase]): # Group together guides for each position groups: dict[ - tuple[SidePosition, float] | tuple[TupleFloat2, TupleFloat2], + tuple[SidePosition, float] + | tuple[tuple[float, float], tuple[float, float]], list[PackerBase], ] = defaultdict(list) diff --git a/plotnine/iapi.py b/plotnine/iapi.py index 10be9d946..ec03ceec0 100644 --- a/plotnine/iapi.py +++ b/plotnine/iapi.py @@ -26,7 +26,6 @@ ScaledAestheticsName, ScaleLimits, StripPosition, - TupleFloat2, ) from ._mpl.offsetbox import FlexibleAnchoredOffsetbox @@ -56,8 +55,8 @@ class range_view: Range information after training """ - range: TupleFloat2 - range_coord: TupleFloat2 + range: tuple[float, float] + range_coord: tuple[float, float] @dataclass @@ -147,8 +146,8 @@ class panel_ranges: Ranges for the panel """ - x: TupleFloat2 - y: TupleFloat2 + x: tuple[float, float] + y: tuple[float, float] @dataclass @@ -316,7 +315,7 @@ class legend_justifications_view: right: float = 0.5 top: float = 0.5 bottom: float = 0.5 - inside: Optional[TupleFloat2] = None + inside: Optional[tuple[float, float]] = None @dataclass @@ -336,8 +335,8 @@ class inside_legend: """ box: FlexibleAnchoredOffsetbox - justification: TupleFloat2 - position: TupleFloat2 + justification: tuple[float, float] + position: tuple[float, float] @dataclass diff --git a/plotnine/qplot.py b/plotnine/qplot.py index 592b080e6..f9a455abd 100644 --- a/plotnine/qplot.py +++ b/plotnine/qplot.py @@ -22,7 +22,7 @@ if typing.TYPE_CHECKING: from typing import Any, Iterable, Literal, Optional - from plotnine.typing import DataLike, TupleFloat2 + from plotnine.typing import DataLike __all__ = ("qplot",) @@ -34,8 +34,8 @@ def qplot( facets: str = "", margins: bool | list[str] = False, geom: str | list[str] | tuple[str] = "auto", - xlim: Optional[TupleFloat2] = None, - ylim: Optional[TupleFloat2] = None, + xlim: Optional[tuple[float, float]] = None, + ylim: Optional[tuple[float, float]] = None, log: Optional[Literal["x", "y", "xy"]] = None, main: Optional[str] = None, xlab: Optional[str] = None, diff --git a/plotnine/scales/_expand.py b/plotnine/scales/_expand.py index b9f81e142..00a4af3f7 100644 --- a/plotnine/scales/_expand.py +++ b/plotnine/scales/_expand.py @@ -13,17 +13,13 @@ from mizani.transforms import trans - from plotnine.typing import ( - CoordRange, - TupleFloat2, - TupleFloat4, - ) + from plotnine.typing import CoordRange def _expand_range_distinct( - x: TupleFloat2, - expand: TupleFloat2 | TupleFloat4, -) -> TupleFloat2: + x: tuple[float, float], + expand: tuple[float, float] | tuple[float, float, float, float], +) -> tuple[float, float]: # Expand ascending and descending order range a, b = x if a > b: @@ -35,7 +31,7 @@ def _expand_range_distinct( def expand_range( x: CoordRange, - expand: TupleFloat2 | TupleFloat4, + expand: tuple[float, float] | tuple[float, float, float, float], trans: trans | Type[trans], ) -> range_view: """ diff --git a/plotnine/scales/range.py b/plotnine/scales/range.py index a4d4b3328..ae8e14193 100644 --- a/plotnine/scales/range.py +++ b/plotnine/scales/range.py @@ -7,7 +7,7 @@ if typing.TYPE_CHECKING: from typing import Any, Sequence - from plotnine.typing import AnyArrayLike, FloatArrayLike, TupleFloat2 + from plotnine.typing import AnyArrayLike, FloatArrayLike class Range: @@ -42,7 +42,7 @@ class RangeContinuous(Range): Continuous Range """ - range: TupleFloat2 + range: tuple[float, float] def train(self, x: FloatArrayLike): """ diff --git a/plotnine/scales/scale.py b/plotnine/scales/scale.py index 653b13e7a..b28083db4 100644 --- a/plotnine/scales/scale.py +++ b/plotnine/scales/scale.py @@ -24,8 +24,6 @@ ScaleLabels, ScaleLabelsRaw, ScaleLimits, - TupleFloat2, - TupleFloat4, ) from ..iapi import range_view, scale_view @@ -76,7 +74,9 @@ class scale( """ # multiplicative and additive expansion constants - expand: TupleFloat2 | TupleFloat4 | None = None + expand: tuple[float, float] | tuple[float, float, float, float] | None = ( + None + ) """ Multiplicative and additive expansion constants that determine how the scale is expanded. If @@ -185,7 +185,7 @@ def dimension(self, expand=None, limits=None): def expand_limits( self, limits, # : ScaleLimits - expand, # : TupleFloat2 | TupleFloat4 + expand, # : tuple[float, float] | tuple[float, float, float, float] coord_limits, # : CoordRange | None trans, # : Trans | Type[Trans] ) -> range_view: @@ -230,10 +230,10 @@ def view( def default_expansion( self, - mult: float | TupleFloat2 = 0, - add: float | TupleFloat2 = 0, + mult: float | tuple[float, float] = 0, + add: float | tuple[float, float] = 0, expand=True, - ) -> TupleFloat4: + ) -> tuple[float, float, float, float]: """ Get default expansion for this scale """ diff --git a/plotnine/scales/scale_continuous.py b/plotnine/scales/scale_continuous.py index fc2689e17..1b2ec312d 100644 --- a/plotnine/scales/scale_continuous.py +++ b/plotnine/scales/scale_continuous.py @@ -37,8 +37,6 @@ ScaleLabels, ScaleMinorBreaksRaw, TFloatArrayLike, - TupleFloat2, - TupleFloat4, ) GuideTypeT = TypeVar("GuideTypeT") @@ -311,7 +309,7 @@ def dimension(self, expand=(0, 0, 0, 0), limits=None): def expand_limits( self, limits: ContinuousLimits, - expand: TupleFloat2 | TupleFloat4, + expand: tuple[float, float] | tuple[float, float, float, float], coord_limits: CoordRange | None, trans: trans, ) -> range_view: diff --git a/plotnine/scales/scale_discrete.py b/plotnine/scales/scale_discrete.py index 9347abe55..8f6c2d410 100644 --- a/plotnine/scales/scale_discrete.py +++ b/plotnine/scales/scale_discrete.py @@ -25,8 +25,6 @@ ScaleDiscreteBreaks, ScaleDiscreteLimits, ScaleLabels, - TupleFloat2, - TupleFloat4, ) @@ -70,7 +68,7 @@ class scale_discrete( breaks. """ - drop: bool = True # drop unused factor levels from the scale + drop: bool = True """ Whether to drop unused categories from the scale """ @@ -139,8 +137,8 @@ def dimension(self, expand=(0, 0, 0, 0), limits=None): def expand_limits( self, limits: ScaleDiscreteLimits, - expand: TupleFloat2 | TupleFloat4, - coord_limits: TupleFloat2, + expand: tuple[float, float] | tuple[float, float, float, float], + coord_limits: tuple[float, float], trans: trans, ) -> range_view: """ diff --git a/plotnine/scales/scale_xy.py b/plotnine/scales/scale_xy.py index eed891ffe..4d43fc2e6 100644 --- a/plotnine/scales/scale_xy.py +++ b/plotnine/scales/scale_xy.py @@ -22,8 +22,6 @@ from mizani.transforms import trans - from plotnine.typing import TupleFloat2, TupleFloat4 - # positions scales have a couple of differences (quirks) that # make necessary to override some of the scale_discrete and @@ -140,8 +138,8 @@ def dimension(self, expand=(0, 0, 0, 0), limits=None): def expand_limits( self, limits: Sequence[str], - expand: TupleFloat2 | TupleFloat4, - coord_limits: TupleFloat2, + expand: tuple[float, float] | tuple[float, float, float, float], + coord_limits: tuple[float, float], trans: trans, ) -> range_view: # Turn discrete limits into a tuple of continuous limits diff --git a/plotnine/stats/binning.py b/plotnine/stats/binning.py index 44aee87bf..16b2bbc94 100644 --- a/plotnine/stats/binning.py +++ b/plotnine/stats/binning.py @@ -11,7 +11,7 @@ if typing.TYPE_CHECKING: from typing import Literal, Optional - from plotnine.typing import FloatArray, FloatArrayLike, TupleFloat2 + from plotnine.typing import FloatArray, FloatArrayLike __all__ = ( @@ -43,7 +43,7 @@ def freedman_diaconis_bins(a): def breaks_from_binwidth( - x_range: TupleFloat2, + x_range: tuple[float, float], binwidth: float, center: Optional[float] = None, boundary: Optional[float] = None, @@ -94,7 +94,7 @@ def breaks_from_binwidth( def breaks_from_bins( - x_range: TupleFloat2, + x_range: tuple[float, float], bins: int = 30, center: Optional[float] = None, boundary: Optional[float] = None, diff --git a/plotnine/themes/elements/element_line.py b/plotnine/themes/elements/element_line.py index 2c596dced..c1ae357e6 100644 --- a/plotnine/themes/elements/element_line.py +++ b/plotnine/themes/elements/element_line.py @@ -7,8 +7,6 @@ if TYPE_CHECKING: from typing import Any, Literal, Optional, Sequence - from plotnine.typing import TupleFloat3, TupleFloat4 - class element_line(element_base): """ @@ -35,11 +33,19 @@ class element_line(element_base): def __init__( self, *, - color: Optional[str | TupleFloat3 | TupleFloat4] = None, + color: Optional[ + str + | tuple[float, float, float] + | tuple[float, float, float, float] + ] = None, size: Optional[float] = None, linetype: Optional[str | Sequence[int]] = None, lineend: Optional[Literal["butt", "projecting", "round"]] = None, - colour: Optional[str | TupleFloat3 | TupleFloat4] = None, + colour: Optional[ + str + | tuple[float, float, float] + | tuple[float, float, float, float] + ] = None, **kwargs: Any, ): super().__init__() diff --git a/plotnine/themes/elements/element_rect.py b/plotnine/themes/elements/element_rect.py index 2b9ebd3f2..07585489d 100644 --- a/plotnine/themes/elements/element_rect.py +++ b/plotnine/themes/elements/element_rect.py @@ -11,8 +11,6 @@ if TYPE_CHECKING: from typing import Any, Optional, Sequence - from plotnine.typing import TupleFloat3, TupleFloat4 - class element_rect(element_base): """ @@ -39,11 +37,23 @@ class element_rect(element_base): def __init__( self, - fill: Optional[str | TupleFloat3 | TupleFloat4] = None, - color: Optional[str | TupleFloat3 | TupleFloat4] = None, + fill: Optional[ + str + | tuple[float, float, float] + | tuple[float, float, float, float] + ] = None, + color: Optional[ + str + | tuple[float, float, float] + | tuple[float, float, float, float] + ] = None, size: Optional[float] = None, linetype: Optional[str | Sequence[int]] = None, - colour: Optional[str | TupleFloat3 | TupleFloat4] = None, + colour: Optional[ + str + | tuple[float, float, float] + | tuple[float, float, float, float] + ] = None, **kwargs: Any, ): super().__init__() diff --git a/plotnine/themes/elements/element_text.py b/plotnine/themes/elements/element_text.py index e1ae5e7e9..5756fb5ba 100644 --- a/plotnine/themes/elements/element_text.py +++ b/plotnine/themes/elements/element_text.py @@ -14,7 +14,6 @@ from typing import Any, Literal, Optional, Sequence from plotnine import theme - from plotnine.typing import TupleFloat3, TupleFloat4 class element_text(element_base): @@ -69,9 +68,13 @@ def __init__( weight: Optional[int | str | Sequence[int | str]] = None, color: Optional[ str - | TupleFloat3 - | TupleFloat4 - | Sequence[str | TupleFloat3 | TupleFloat4] + | tuple[float, float, float] + | tuple[float, float, float, float] + | Sequence[ + str + | tuple[float, float, float] + | tuple[float, float, float, float] + ] ] = None, size: Optional[float | Sequence[float]] = None, ha: Optional[Literal["center", "left", "right"] | float] = None, @@ -88,9 +91,13 @@ def __init__( linespacing: Optional[float] = None, backgroundcolor: Optional[ str - | TupleFloat3 - | TupleFloat4 - | Sequence[str | TupleFloat3 | TupleFloat4] + | tuple[float, float, float] + | tuple[float, float, float, float] + | Sequence[ + str + | tuple[float, float, float] + | tuple[float, float, float, float] + ] ] = None, margin: Optional[ dict[Literal["t", "b", "l", "r", "units"], Any] diff --git a/plotnine/typing.py b/plotnine/typing.py index 8821e261b..46e302f3e 100644 --- a/plotnine/typing.py +++ b/plotnine/typing.py @@ -35,12 +35,6 @@ def to_pandas(self) -> pd.DataFrame: ... -# Tuples -TupleInt2: TypeAlias = tuple[int, int] -TupleFloat2: TypeAlias = tuple[float, float] -TupleFloat3: TypeAlias = tuple[float, float, float] -TupleFloat4: TypeAlias = tuple[float, float, float, float] - # Arrays (strictly numpy) AnyArray: TypeAlias = NDArray[Any] BoolArray: TypeAlias = NDArray[np.bool_] @@ -117,7 +111,7 @@ def to_pandas(self) -> pd.DataFrame: ] # limits -ScaleContinuousLimits: TypeAlias = TupleFloat2 +ScaleContinuousLimits: TypeAlias = tuple[float, float] ScaleDiscreteLimits: TypeAlias = Sequence[str] ScaleLimits: TypeAlias = ScaleContinuousLimits | ScaleDiscreteLimits @@ -168,7 +162,7 @@ def to_pandas(self) -> pd.DataFrame: ScaleLabels: TypeAlias = Sequence[str] ## Coords -CoordRange: TypeAlias = TupleFloat2 +CoordRange: TypeAlias = tuple[float, float] # Guide SidePosition: TypeAlias = Literal["left", "right", "top", "bottom"]