def isnull(input): ''' Replacement for numpy.isnan / -numpy.isfinite which is suitable for use on object arrays. Parameters ---------- arr: ndarray or object value Returns ------- boolean ndarray or boolean ''' if isinstance(input, np.ndarray): if input.dtype.kind in ('O', 'S'): # Working around NumPy ticket 1542 shape = input.shape result = np.empty(shape, dtype=bool) vec = _tseries.isnullobj(input.ravel()) result[:] = vec.reshape(shape) else: result = -np.isfinite(input) else: result = _tseries.checknull(input) return result
def isnull(input): ''' Replacement for numpy.isnan / -numpy.isfinite which is suitable for use on object arrays. Parameters ---------- arr: ndarray or object value Returns ------- boolean ndarray or boolean ''' from pandas.core.generic import PandasObject from pandas import Series if isinstance(input, np.ndarray): if input.dtype.kind in ('O', 'S'): # Working around NumPy ticket 1542 shape = input.shape result = np.empty(shape, dtype=bool) vec = _tseries.isnullobj(input.ravel()) result[:] = vec.reshape(shape) if isinstance(input, Series): result = Series(result, index=input.index, copy=False) else: result = -np.isfinite(input) elif isinstance(input, PandasObject): # TODO: optimize for DataFrame, etc. return input.apply(isnull) else: result = _tseries.checknull(input) return result
def _format(s, dtype, space=None, na_rep=None, float_format=None, col_width=None): def _just_help(x): if space is None: return x return x[:space].ljust(space) def _make_float_format(x): if na_rep is not None and isnull(x): if np.isnan(x): x = ' ' + na_rep return _just_help('%s' % x) if float_format: formatted = float_format(x) elif print_config.float_format: formatted = print_config.float_format(x) else: formatted = _float_format_default(x, col_width) return _just_help(formatted) def _make_int_format(x): return _just_help('% d' % x) if is_float_dtype(dtype): return _make_float_format(s) elif is_integer_dtype(dtype): return _make_int_format(s) else: if na_rep is not None and lib.checknull(s): return na_rep else: # object dtype return _just_help('%s' % _stringify(s))
def _format(x): if self.na_rep is not None and lib.checknull(x): if x is None: return 'None' return self.na_rep else: # object dtype return '%s' % formatter(x)
def _format(x): if self.na_rep is not None and lib.checknull(x): if x is None: return 'None' return self.na_rep else: # object dtype return '%s' % formatter(x)
def notnull(input): ''' Replacement for numpy.isfinite / -numpy.isnan which is suitable for use on object arrays. Parameters ---------- arr: ndarray or object value Returns ------- boolean ndarray or boolean ''' if isinstance(input, np.ndarray): return -isnull(input) else: return not _tseries.checknull(input)
def isnull(obj): ''' Replacement for numpy.isnan / -numpy.isfinite which is suitable for use on object arrays. Parameters ---------- arr: ndarray or object value Returns ------- boolean ndarray or boolean ''' if np.isscalar(obj) or obj is None: return lib.checknull(obj) from pandas.core.generic import PandasObject from pandas import Series if isinstance(obj, np.ndarray): if obj.dtype.kind in ('O', 'S'): # Working around NumPy ticket 1542 shape = obj.shape result = np.empty(shape, dtype=bool) vec = lib.isnullobj(obj.ravel()) result[:] = vec.reshape(shape) if isinstance(obj, Series): result = Series(result, index=obj.index, copy=False) elif obj.dtype == np.dtype('M8[ns]'): # this is the NaT pattern result = np.array(obj).view('i8') == lib.NaT else: result = -np.isfinite(obj) return result elif isinstance(obj, PandasObject): # TODO: optimize for DataFrame, etc. return obj.apply(isnull) else: return obj is None
def _format(s, dtype, space=None, na_rep=None, float_format=None, col_width=None): def _just_help(x): if space is None: return x return x[:space].ljust(space) def _make_float_format(x): if na_rep is not None and isnull(x): if np.isnan(x): x = ' ' + na_rep return _just_help('%s' % x) if float_format: formatted = float_format(x) elif print_config.float_format: formatted = print_config.float_format(x) else: formatted = _float_format_default(x, col_width) return _just_help(formatted) def _make_int_format(x): return _just_help('% d' % x) if is_float_dtype(dtype): return _make_float_format(s) elif is_integer_dtype(dtype): return _make_int_format(s) else: if na_rep is not None and lib.checknull(s): return na_rep else: # object dtype return _just_help('%s' % _stringify(s))
def isnull(obj): ''' Replacement for numpy.isnan / -numpy.isfinite which is suitable for use on object arrays. Parameters ---------- arr: ndarray or object value Returns ------- boolean ndarray or boolean ''' if np.isscalar(obj) or obj is None: return lib.checknull(obj) from pandas.core.generic import PandasObject from pandas import Series if isinstance(obj, np.ndarray): if obj.dtype.kind in ('O', 'S'): # Working around NumPy ticket 1542 shape = obj.shape result = np.empty(shape, dtype=bool) vec = lib.isnullobj(obj.ravel()) result[:] = vec.reshape(shape) if isinstance(obj, Series): result = Series(result, index=obj.index, copy=False) else: result = -np.isfinite(obj) return result elif isinstance(obj, PandasObject): # TODO: optimize for DataFrame, etc. return obj.apply(isnull) else: return obj is None