Skip to content

Commit

Permalink
TYP: Remove TupleFloat* and TupleInt* aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
has2k1 committed Jul 31, 2024
1 parent 7546375 commit 56e1dc7
Show file tree
Hide file tree
Showing 29 changed files with 126 additions and 132 deletions.
12 changes: 5 additions & 7 deletions plotnine/_mpl/_plot_side_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

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

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

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

Expand Down
5 changes: 2 additions & 3 deletions plotnine/_mpl/_plotnine_tight_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
):
"""
Expand Down
7 changes: 3 additions & 4 deletions plotnine/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
FloatArrayLike,
IntArray,
SidePosition,
TupleFloat2,
)

T = TypeVar("T")
Expand All @@ -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),
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions plotnine/coords/coord_cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from plotnine.typing import (
FloatArray,
FloatSeries,
TupleFloat2,
)


Expand All @@ -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)
Expand All @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions plotnine/coords/coord_fixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import Optional

from plotnine.iapi import panel_view
from plotnine.typing import TupleFloat2


class coord_fixed(coord_cartesian):
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions plotnine/coords/coord_trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
FloatArray,
FloatSeries,
TFloatArrayLike,
TupleFloat2,
)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
17 changes: 7 additions & 10 deletions plotnine/geoms/annotation_logticks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -69,7 +64,7 @@ def _check_log_scale(
sides: str,
panel_params: panel_view,
coord: coord,
) -> TupleFloat2:
) -> tuple[float, float]:
"""
Check the log transforms
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions plotnine/geoms/annotation_stripes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions plotnine/geoms/geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions plotnine/geoms/geom_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions plotnine/geoms/geom_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions plotnine/geoms/geom_pointrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions plotnine/geoms/geom_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions plotnine/guides/guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
LegendPosition,
Orientation,
SidePosition,
TupleFloat2,
)

from .guides import GuidesElements
Expand Down Expand Up @@ -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
"""
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
Loading

0 comments on commit 56e1dc7

Please sign in to comment.