Skip to content

Commit 7770f34

Browse files
committed
up to SparselyBin with reduced tests
1 parent 664eedd commit 7770f34

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

histogrammar/primitives/bag.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ def __eq__(self, other):
318318
if isinstance(v1i, numbers.Real) and isinstance(v2i, numbers.Real):
319319
if not numeq(v1i, v2i):
320320
return False
321+
elif isinstance(v1i, basestring) and isinstance(v2i, basestring):
322+
if v1i != v2i:
323+
return False
321324
else:
322325
return False
323326
else:

histogrammar/util.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ def floatOrNan(x):
140140

141141
def floatToJson(x):
142142
"""Custom rule for converting non-finite numbers to JSON as quoted strings: ``"inf"``, ``"-inf"``, and ``"nan"``. This avoids Python's bad habit of putting literal ``Infinity``, ``-Infinity``, and ``NaN`` in the JSON (without quotes)."""
143-
if math.isnan(x):
143+
if x in ("nan", "inf", "-inf"):
144+
return x
145+
elif math.isnan(x):
144146
return "nan"
145147
elif math.isinf(x) and x > 0.0:
146148
return "inf"
@@ -222,9 +224,10 @@ def function(datum):
222224
# fill the namespace with math.* functions
223225
context.update(math.__dict__)
224226

225-
# if you have Numpy, override the namespace with numpy.* functions
227+
# if you have Numpy, include numpy.* functions
226228
if numpy is not None:
227-
context.update(numpy.__dict__)
229+
context["numpy"] = numpy
230+
context["np"] = numpy
228231

229232
# if the datum is a dict, override the namespace with its dict keys
230233
if isinstance(datum, dict): # if it's a dict

0 commit comments

Comments
 (0)