Skip to content

Commit 0daedc3

Browse files
committed
Turn off specialize() for Count objects
Turn off specialize() for Count objects, which is adding dedicated fill and plot functions. This is slow, and not needed for Count objects.
1 parent 4f20f1b commit 0daedc3

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

histogrammar/defs.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ def specialize(self):
123123
These objects wouldn't satisfy any of ``addImplicitMethod``'s checks anyway.
124124
"""
125125
if spec:
126+
# MB 20220517: warning, this is a slow function.
127+
# Adding functions to each object, ideally avoid this.
126128
histogrammar.specialized.addImplicitMethods(self)
127129

128130
self.fill = FillMethod(self, self.fill)
@@ -236,8 +238,12 @@ def plot(self, httpServer=None, **parameters):
236238

237239
def __getstate__(self):
238240
state = dict(self.__dict__)
239-
del state["fill"]
240-
del state["plot"]
241+
for s in ['fill', 'plot']:
242+
# these states are set dynamically by FillMethod and PlotMethod, in factory.specialize().
243+
# MB 20220517: turned off specialize() for Count objects,
244+
# for which specialized fill and plot methods are not needed.
245+
if s in state:
246+
del state[s]
241247
return state
242248

243249
def __setstate__(self, dict):

histogrammar/primitives/count.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def ed(entries):
5050
raise ValueError("entries ({0}) cannot be negative".format(entries))
5151
out = Count()
5252
out.entries = float(entries)
53-
return out.specialize()
53+
return out
5454

5555
@staticmethod
5656
def ing(transform=identity):
@@ -69,7 +69,6 @@ def __init__(self, transform=identity):
6969
self.entries = 0.0
7070
self.transform = serializable(transform)
7171
super(Count, self).__init__()
72-
self.specialize()
7372

7473
@inheritdoc(Container)
7574
def zero(self):
@@ -80,7 +79,7 @@ def __add__(self, other):
8079
if isinstance(other, Count):
8180
out = Count(self.transform)
8281
out.entries = self.entries + other.entries
83-
return out.specialize()
82+
return out
8483
else:
8584
raise ContainerException("cannot add {0} and {1}".format(self.name, other.name))
8685

@@ -106,7 +105,7 @@ def __mul__(self, factor):
106105
else:
107106
out = self.zero()
108107
out.entries = factor * self.entries
109-
return out.specialize()
108+
return out
110109

111110
@inheritdoc(Container)
112111
def __rmul__(self, factor):

0 commit comments

Comments
 (0)