Skip to content

Commit 2ff7658

Browse files
committed
REF: Make scale.final_limit a cached property
1 parent 250ae83 commit 2ff7658

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

Diff for: plotnine/scales/scale.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from abc import ABC
44
from copy import copy, deepcopy
55
from dataclasses import dataclass, field
6+
from functools import cached_property
67
from typing import TYPE_CHECKING, Generic, cast
78

89
import numpy as np
@@ -271,7 +272,7 @@ def is_empty(self) -> bool:
271272
return True
272273
return self._range.is_empty() and self.limits is None
273274

274-
@property
275+
@cached_property
275276
def final_limits(self) -> Any:
276277
raise NotImplementedError
277278

Diff for: plotnine/scales/scale_continuous.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from contextlib import suppress
44
from dataclasses import dataclass
5+
from functools import cached_property
56
from typing import TYPE_CHECKING, Sequence
67
from warnings import warn
78

@@ -169,7 +170,7 @@ def _make_trans(self) -> trans:
169170

170171
return t
171172

172-
@property
173+
@cached_property
173174
def final_limits(self) -> tuple[float, float]:
174175
if self.is_empty():
175176
return (0, 1)

Diff for: plotnine/scales/scale_discrete.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from dataclasses import dataclass
4+
from functools import cached_property
45
from typing import TYPE_CHECKING, Any, Literal, Sequence
56

67
import numpy as np
@@ -75,7 +76,7 @@ def __post_init__(self):
7576
super().__post_init__()
7677
self._range = RangeDiscrete()
7778

78-
@property
79+
@cached_property
7980
def final_limits(self) -> Sequence[str]:
8081
if self.is_empty():
8182
return ("0", "1")

Diff for: plotnine/scales/scale_xy.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from dataclasses import dataclass
4+
from functools import cached_property
45
from itertools import chain
56
from typing import TYPE_CHECKING
67

@@ -88,7 +89,7 @@ def map(self, x, limits=None):
8889
return list(seq)
8990
return list(x)
9091

91-
@property
92+
@cached_property
9293
def final_limits(self):
9394
if self.is_empty():
9495
return (0, 1)

0 commit comments

Comments
 (0)