Skip to content

Commit

Permalink
REF: Make scale.final_limit a cached property
Browse files Browse the repository at this point in the history
  • Loading branch information
has2k1 committed Jan 6, 2025
1 parent 250ae83 commit 2ff7658
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion plotnine/scales/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from abc import ABC
from copy import copy, deepcopy
from dataclasses import dataclass, field
from functools import cached_property
from typing import TYPE_CHECKING, Generic, cast

import numpy as np
Expand Down Expand Up @@ -271,7 +272,7 @@ def is_empty(self) -> bool:
return True
return self._range.is_empty() and self.limits is None

@property
@cached_property
def final_limits(self) -> Any:
raise NotImplementedError

Expand Down
3 changes: 2 additions & 1 deletion plotnine/scales/scale_continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from contextlib import suppress
from dataclasses import dataclass
from functools import cached_property
from typing import TYPE_CHECKING, Sequence
from warnings import warn

Expand Down Expand Up @@ -169,7 +170,7 @@ def _make_trans(self) -> trans:

return t

@property
@cached_property
def final_limits(self) -> tuple[float, float]:
if self.is_empty():
return (0, 1)
Expand Down
3 changes: 2 additions & 1 deletion plotnine/scales/scale_discrete.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from dataclasses import dataclass
from functools import cached_property
from typing import TYPE_CHECKING, Any, Literal, Sequence

import numpy as np
Expand Down Expand Up @@ -75,7 +76,7 @@ def __post_init__(self):
super().__post_init__()
self._range = RangeDiscrete()

@property
@cached_property
def final_limits(self) -> Sequence[str]:
if self.is_empty():
return ("0", "1")
Expand Down
3 changes: 2 additions & 1 deletion plotnine/scales/scale_xy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from dataclasses import dataclass
from functools import cached_property
from itertools import chain
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -88,7 +89,7 @@ def map(self, x, limits=None):
return list(seq)
return list(x)

@property
@cached_property
def final_limits(self):
if self.is_empty():
return (0, 1)
Expand Down

0 comments on commit 2ff7658

Please sign in to comment.