def _is_monotonic_ret(dforig, dfcheck, dfderive, *args, **kwargs): _ret, ret_specd = _pull_out_ret(kwargs, dforig) increasing = _read_arg_or_kwarg(args, 0, kwargs, 'increasing', None) strict = _read_arg_or_kwarg(args, 1, kwargs, 'strict', False) items = _read_arg_or_kwarg(args, 2, kwargs, 'items', {k: (increasing, strict) for k in dfcheck}) results = {} for col, (increasing, strict) in items.items(): s = pd.Index(dfcheck[col]) if increasing: good = getattr(s, 'is_monotonic_increasing') elif increasing is None: good = getattr(s, 'is_monotonic') | getattr(s, 'is_monotonic_decreasing') else: good = getattr(s, 'is_monotonic_decreasing') if strict: if increasing: good = good & (s.to_series().diff().dropna() > 0).all() elif increasing is None: good = good & ((s.to_series().diff().dropna() > 0).all() | (s.to_series().diff().dropna() < 0).all()) else: good = good & (s.to_series().diff().dropna() < 0).all() results[col] = not good ret_specd['obj'] = results ret_specd['ndframe'] = pd.Series(results) ret_specd['bool'] = any(list(results.values())) return _ret_proper_objects(_ret, ret_specd)
def _is_monotonic_ret(dforig, dfcheck, dfderive, *args, **kwargs): _ret, ret_specd = _pull_out_ret(kwargs, dforig) increasing = _read_arg_or_kwarg(args, 0, kwargs, 'increasing', None) strict = _read_arg_or_kwarg(args, 1, kwargs, 'strict', False) items = _read_arg_or_kwarg(args, 2, kwargs, 'items', {k: (increasing, strict) for k in dfcheck}) results = {} for col, (increasing, strict) in items.items(): s = pd.Index(dfcheck[col]) if increasing: good = getattr(s, 'is_monotonic_increasing') elif increasing is None: good = getattr(s, 'is_monotonic') | getattr( s, 'is_monotonic_decreasing') else: good = getattr(s, 'is_monotonic_decreasing') if strict: if increasing: good = good & (s.to_series().diff().dropna() > 0).all() elif increasing is None: good = good & ((s.to_series().diff().dropna() > 0).all() | (s.to_series().diff().dropna() < 0).all()) else: good = good & (s.to_series().diff().dropna() < 0).all() results[col] = not good ret_specd['obj'] = results ret_specd['ndframe'] = pd.Series(results) ret_specd['bool'] = any(list(results.values())) return _ret_proper_objects(_ret, ret_specd)
def _unique_index_ret(dforig, dfcheck, dfderive, *args, **kwargs): _ret, ret_specd = _pull_out_ret(kwargs, dforig) ret_specd['obj'] = Counter(list(dfcheck.index)) ret_specd['ndframe'] = pd.Series(ret_specd['obj']) ret_specd['bool'] = not dfcheck.index.is_unique return _ret_proper_objects(_ret, ret_specd)
def _is_shape_ret(dforig, dfcheck, dfderive, *args, **kwargs): _ret, ret_specd = _pull_out_ret(kwargs, dforig) shape = _read_required_arg_or_kwarg(args, 0, kwargs, 'shape') ret_specd['obj'] = "is_shape has no output object" ret_specd['ndframe'] = "is_shape has no output ndframe" ret_specd['bool'] = not dfcheck.shape == shape return _ret_proper_objects(_ret, ret_specd)
def _none_missing_ret(dforig, dfcheck, dfderive, *args, **kwargs): _ret, ret_specd = _pull_out_ret(kwargs, dforig) columns = _read_arg_or_kwarg(args, 0, kwargs, 'columns', dfcheck.columns) ret_specd['obj'] = dfcheck[columns].isnull() ret_specd['ndframe'] = ret_specd['obj'].any() ret_specd['bool'] = ret_specd['ndframe'].any() return _ret_proper_objects(_ret, ret_specd)
def _equal_columns_sum_ret(dforig, dfcheck, dfderive, *args, **kwargs): _ret, ret_specd = _pull_out_ret(kwargs, dforig) cola = _read_arg_or_kwarg(args, 0, kwargs, 'cola', dfcheck.columns[0]) colb = _read_arg_or_kwarg(args, 1, kwargs, 'colb', dfcheck.columns[1]) results = {cola : dfcheck[cola].dropna().sum(), colb : dfcheck[colb].dropna().sum()} ret_specd['obj'] = results ret_specd['ndframe'] = pd.Series(results) ret_specd['bool'] = not results[cola] == results[colb] return _ret_proper_objects(_ret, ret_specd)
def _has_dtypes_ret(dforig, dfcheck, dfderive, *args, **kwargs): _ret, ret_specd = _pull_out_ret(kwargs, dforig) items = _read_required_arg_or_kwarg(args, 0, kwargs, 'items') results = {} dtypes = dfcheck.dtypes for k, v in items.items(): results[k] = not dtypes[k] == v ret_specd['obj'] = results ret_specd['ndframe'] = pd.Series(results) ret_specd['bool'] = any(list(results.values())) return _ret_proper_objects(_ret, ret_specd)
def _within_range_ret(dforig, dfcheck, dfderive, *args, **kwargs): _ret, ret_specd = _pull_out_ret(kwargs, dforig) items = _read_required_arg_or_kwarg(args, 0, kwargs, 'items') results = {} for k, (lower, upper) in items.items(): results[k] = (lower > dfcheck[k]).any() or (upper < dfcheck[k]).any() ret_specd['obj'] = results ret_specd['ndframe'] = pd.Series(results) ret_specd['bool'] = any(list(results.values())) return _ret_proper_objects(_ret, ret_specd)
def _within_set_ret(dforig, dfcheck, dfderive, *args, **kwargs): _ret, ret_specd = _pull_out_ret(kwargs, dforig) items = _read_required_arg_or_kwarg(args, 0, kwargs, 'items') results = {} for k, v in items.items(): results[k] = not dfcheck[k].isin(v).all() ret_specd['obj'] = results ret_specd['ndframe'] = pd.Series(results) ret_specd['bool'] = any(list(results.values())) return _ret_proper_objects(_ret, ret_specd)
def _within_n_std_ret(dforig, dfcheck, dfderive, *args, **kwargs): _ret, ret_specd = _pull_out_ret(kwargs, dforig) n = _read_arg_or_kwarg(args, 0, kwargs, 'n', 3) means = dfderive.mean() stds = dfderive.std() results = (pd.np.abs(dfcheck - means) < n * stds) ret_specd['obj'] = results ret_specd['ndframe'] = results ret_specd['bool'] = not results.all().all() return _ret_proper_objects(_ret, ret_specd)
def _equal_columns_sum_ret(dforig, dfcheck, dfderive, *args, **kwargs): _ret, ret_specd = _pull_out_ret(kwargs, dforig) cola = _read_arg_or_kwarg(args, 0, kwargs, 'cola', dfcheck.columns[0]) colb = _read_arg_or_kwarg(args, 1, kwargs, 'colb', dfcheck.columns[1]) results = { cola: dfcheck[cola].dropna().sum(), colb: dfcheck[colb].dropna().sum() } ret_specd['obj'] = results ret_specd['ndframe'] = pd.Series(results) ret_specd['bool'] = not results[cola] == results[colb] return _ret_proper_objects(_ret, ret_specd)
def _has_in_index_ret(dforig, dfcheck, dfderive, *args, **kwargs): _ret, ret_specd = _pull_out_ret(kwargs, dforig) orig_obj_to_check = _read_required_arg_or_kwarg(args, 0, kwargs, 'obj') obj_to_check = orig_obj_to_check try_ix = _read_arg_or_kwarg(args, 1, kwargs, 'try_ix', False) try_strftime = _read_arg_or_kwarg(args, 2, kwargs, 'try_strftime', False) check_na = _read_arg_or_kwarg(args, 3, kwargs, 'check_na', False) ans = obj_to_check in dfcheck.index if try_strftime: try: obj_to_check = obj_to_check.strftime(try_strftime) except: pass # at this point, if it's in the index, ans will be True if try_ix: try: ans = ans or (len(dfcheck.ix[obj_to_check]) > 0) except: pass # at this point, if it's in the index, or if it's string representation # is in the index, ans will be True if check_na: try: isna = dfcheck.ix[obj_to_check].isnull()[0] except: isna = True ans = not ((not ans) or isna) results = {orig_obj_to_check : ans} ret_specd['obj'] = results ret_specd['ndframe'] = pd.Series(results) ret_specd['bool'] = not ans return _ret_proper_objects(_ret, ret_specd)
def _has_in_index_ret(dforig, dfcheck, dfderive, *args, **kwargs): _ret, ret_specd = _pull_out_ret(kwargs, dforig) orig_obj_to_check = _read_required_arg_or_kwarg(args, 0, kwargs, 'obj') obj_to_check = orig_obj_to_check try_ix = _read_arg_or_kwarg(args, 1, kwargs, 'try_ix', False) try_strftime = _read_arg_or_kwarg(args, 2, kwargs, 'try_strftime', False) check_na = _read_arg_or_kwarg(args, 3, kwargs, 'check_na', False) ans = obj_to_check in dfcheck.index if try_strftime: try: obj_to_check = obj_to_check.strftime(try_strftime) except: pass # at this point, if it's in the index, ans will be True if try_ix: try: ans = ans or (len(dfcheck.ix[obj_to_check]) > 0) except: pass # at this point, if it's in the index, or if it's string representation # is in the index, ans will be True if check_na: try: isna = dfcheck.ix[obj_to_check].isnull()[0] except: isna = True ans = not ((not ans) or isna) results = {orig_obj_to_check: ans} ret_specd['obj'] = results ret_specd['ndframe'] = pd.Series(results) ret_specd['bool'] = not ans return _ret_proper_objects(_ret, ret_specd)