From dd857aa4d75441e765bfc44d15e6bb2c74b3ae1b Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Wed, 7 Jun 2017 20:17:58 -0400 Subject: [PATCH] MAINT: Make _sortable_sentinel a singleton. --- zipline/lib/labelarray.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/zipline/lib/labelarray.py b/zipline/lib/labelarray.py index bd3ce2d6..ff121ff9 100644 --- a/zipline/lib/labelarray.py +++ b/zipline/lib/labelarray.py @@ -11,6 +11,7 @@ import pandas as pd from toolz import compose from zipline.utils.compat import unicode +from zipline.utils.functional import instance from zipline.utils.preprocess import preprocess from zipline.utils.sentinel import sentinel from zipline.utils.input_validation import ( @@ -623,7 +624,7 @@ class LabelArray(ndarray): return_inverse=True ) - if new_categories[0] == _sortable_sentinel: + if new_categories[0] is _sortable_sentinel: # f_to_use return _sortable_sentinel for locations that should be # missing values in our output. Since np.unique returns the uniques # in sorted order, and since _sortable_sentinel sorts before any @@ -731,15 +732,13 @@ class LabelArray(ndarray): return self.map_predicate(container.__contains__) +@instance # This makes _sortable_sentinel a singleton instance. @total_ordering -class _SortableSentinel(object): +class _sortable_sentinel(object): """Dummy object that sorts before any other python object. """ def __eq__(self, other): - return isinstance(other, _SortableSentinel) + return self is other def __lt__(self, other): - return not isinstance(other, _SortableSentinel) - - -_sortable_sentinel = _SortableSentinel() + return True