def test_is_null(): # 0 is not considered NULL, as 0 is a legit number too... # and causes issues with datetimes, since epoch(0)->1970, 1, 1 # same with other 'empty' values like '', [], etc. from metrique.utils import is_null import pandas import numpy nulls = [None] not_nulls = ['hello', -1, 1, 0.0, 0, 0L, '', ' \t\n\t ', {'key': 'value'}, [1], {}, [], pandas.DataFrame()] nulls += [pandas.NaT, numpy.NaN] for x in nulls: null = is_null(x, except_=False) print '%s is null? %s' % (repr(x), null) assert null is True for x in not_nulls: null = is_null(x, except_=False) print '%s is null? %s' % (repr(x), null) assert null is False try: null = is_null(x, except_=True) except RuntimeError: pass else: assert False
def test_is_null(): # 0 is not considered NULL, as 0 is a legit number too... # and causes issues with datetimes, since epoch(0)->1970, 1, 1 # same with other 'empty' values like '', [], etc. from metrique.utils import is_null import pandas import numpy nulls = [None] not_nulls = [ 'hello', -1, 1, 0.0, 0, 0L, '', ' \t\n\t ', { 'key': 'value' }, [1], {}, [], pandas.DataFrame() ] nulls += [pandas.NaT, numpy.NaN] for x in nulls: null = is_null(x, except_=False) print '%s is null? %s' % (repr(x), null) assert null is True for x in not_nulls: null = is_null(x, except_=False) print '%s is null? %s' % (repr(x), null) assert null is False try: null = is_null(x, except_=True) except RuntimeError: pass else: assert False
def _update(self, objects): if is_null(objects): pass elif is_array(objects, except_=False): [self.add(x) for x in tuple(objects)] elif isinstance(objects, MetriqueContainer): [self.add(o) for o in objects.itervalues()] else: raise ValueError( "objs must be None, a list, tuple, dict or MetriqueContainer")