Skip to content

Commit 8f8275f

Browse files
committed
Revert some perf updates to fix pytests
1 parent ccf23e9 commit 8f8275f

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

histogrammar/defs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import math
2121
import random
2222
import re
23+
2324
try:
2425
from collections import OrderedDict
2526
except ImportError:
@@ -54,12 +55,6 @@ def __len__(self):
5455
from histogrammar.pycparser import c_ast
5556
import histogrammar.version
5657

57-
try:
58-
import histogrammar.specialized
59-
spec = True
60-
except (ImportError, AttributeError):
61-
spec = False
62-
6358

6459
class ContainerException(Exception):
6560
"""Exception type for improperly configured containers."""
@@ -122,10 +117,13 @@ def specialize(self):
122117
since they are created before the histogrammar.specialized module can be defined.
123118
These objects wouldn't satisfy any of ``addImplicitMethod``'s checks anyway.
124119
"""
125-
if spec:
120+
try:
126121
# MB 20220517: warning, this is a slow function.
127122
# Adding functions to each object, ideally avoid this.
123+
import histogrammar.specialized
128124
histogrammar.specialized.addImplicitMethods(self)
125+
except (ImportError, AttributeError):
126+
pass
129127

130128
self.fill = FillMethod(self, self.fill)
131129
self.plot = PlotMethod(self, self.plot)
@@ -237,6 +235,7 @@ def plot(self, httpServer=None, **parameters):
237235
raise NotImplementedError
238236

239237
def __getstate__(self):
238+
# used by pickling
240239
state = dict(self.__dict__)
241240
for s in ['fill', 'plot']:
242241
# these states are set dynamically by FillMethod and PlotMethod, in factory.specialize().
@@ -247,6 +246,7 @@ def __getstate__(self):
247246
return state
248247

249248
def __setstate__(self, dict):
249+
# used by unpickling
250250
self.__dict__ = dict
251251
self.fill = FillMethod(self, self.fill)
252252
self.plot = PlotMethod(self, self.plot)

histogrammar/util.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,19 @@ class PlotMethod(object):
5555
def __init__(self, container, plot):
5656
self.container = container
5757
self.plot = plot
58-
if hasattr(container, 'plotroot'):
58+
59+
try:
5960
self.root = container.plotroot
60-
if hasattr(container, 'plotbokeh'):
61+
except (AttributeError, KeyError):
62+
pass
63+
try:
6164
self.bokeh = container.plotbokeh
62-
if hasattr(container, 'plotmatplotlib'):
65+
except (AttributeError, KeyError):
66+
pass
67+
try:
6368
self.matplotlib = container.plotmatplotlib
69+
except (AttributeError, KeyError):
70+
pass
6471

6572
def __call__(self, *args, **kwds):
6673
return self.plot(*args, **kwds)

0 commit comments

Comments
 (0)