Skip to content

Commit 6fd3d7d

Browse files
committed
removing support for passing bare storage types (#193)
* removing support for passing bare storage types * adding preconfigured instances for lazy people
1 parent 50a7b52 commit 6fd3d7d

File tree

3 files changed

+21
-91
lines changed

3 files changed

+21
-91
lines changed

boost_histogram/_internal/hist.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .axis import _to_axis, Axis
77
from .axistuple import AxesTuple
88
from .sig_tools import inject_signature
9-
from .storage import Double, _to_storage
9+
from .storage import Double
1010

1111
import warnings
1212
import numpy as np
@@ -115,8 +115,6 @@ def __init__(self, *axes, **kwargs):
115115
with KWArgs(kwargs) as k:
116116
storage = k.optional("storage", Double())
117117

118-
storage = storage._get_storage_()
119-
120118
# Allow a tuple to represent a regular axis
121119
axes = [_arg_shortcut(arg) for arg in axes]
122120

@@ -218,7 +216,7 @@ def _axis(self, i):
218216

219217
@property
220218
def _storage_type(self):
221-
return _to_storage(self._hist._storage_type)
219+
return self._hist._storage_type
222220

223221

224222
class BoostHistogram(BaseHistogram):

boost_histogram/_internal/storage.py

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,12 @@
22

33
del absolute_import, division, print_function
44

5-
from .._core import storage as store
6-
7-
8-
class Storage(object):
9-
__slots__ = ()
10-
11-
def __eq__(self, other):
12-
return issubclass(other.__class__, self.__class__) or issubclass(
13-
self.__class__, other.__class__
14-
)
15-
16-
# Override this to allow configurable storages
17-
@classmethod
18-
def _get_storage_(cls):
19-
return cls._STORAGE()
20-
21-
22-
class Int(Storage):
23-
_STORAGE = store.int
24-
25-
26-
class Double(Storage):
27-
_STORAGE = store.double
28-
29-
30-
class AtomicInt(Storage):
31-
_STORAGE = store.atomic_int
32-
33-
34-
class Unlimited(Storage):
35-
_STORAGE = store.unlimited
36-
37-
38-
class Weight(Storage):
39-
_STORAGE = store.weight
40-
41-
42-
class Mean(Storage):
43-
_STORAGE = store.mean
44-
45-
46-
class WeightedMean(Storage):
47-
_STORAGE = store.weighted_mean
48-
49-
50-
def _to_storage(st):
51-
for base in Storage.__subclasses__():
52-
if st == base._STORAGE:
53-
return base
54-
55-
raise TypeError("Invalid storage passed in")
5+
from .._core import storage
6+
7+
Int = storage.int
8+
Double = storage.double
9+
AtomicInt = storage.atomic_int
10+
Unlimited = storage.unlimited
11+
Weight = storage.weight
12+
Mean = storage.mean
13+
WeightedMean = storage.weighted_mean

boost_histogram/storage.py

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from __future__ import absolute_import, division, print_function
1+
from __future__ import absolute_import
22

3-
del absolute_import, division, print_function
3+
del absolute_import
44

55
import warnings
66

@@ -14,37 +14,11 @@
1414
WeightedMean,
1515
)
1616

17-
18-
class DepStorageMixin(object):
19-
@classmethod
20-
def _get_storage_(cls):
21-
warnings.warn("Use Int instead", DeprecationWarning)
22-
return cls._STORAGE()
23-
24-
25-
class int(DepStorageMixin, Int):
26-
pass
27-
28-
29-
class double(DepStorageMixin, Double):
30-
pass
31-
32-
33-
class unlimited(DepStorageMixin, Unlimited):
34-
pass
35-
36-
37-
class atomic_int(DepStorageMixin, AtomicInt):
38-
pass
39-
40-
41-
class weight(DepStorageMixin, Weight):
42-
pass
43-
44-
45-
class mean(DepStorageMixin, Mean):
46-
pass
47-
48-
49-
class weighted_mean(DepStorageMixin, WeightedMean):
50-
pass
17+
# for lazy folks
18+
int = Int()
19+
double = Double()
20+
unlimited = Unlimited()
21+
atomic_int = AtomicInt()
22+
weight = Weight()
23+
mean = Mean()
24+
weighted_mean = WeightedMean()

0 commit comments

Comments
 (0)