예제 #1
0
파일: detect.py 프로젝트: simonbrownsb/tdda
def detect_df_from_file(df_path,
                        constraints_path,
                        outpath,
                        verbose=True,
                        **kwargs):
    if df_path == '-' or df_path is None:
        df_path = StringIO(sys.stdin.read())
    if constraints_path is None:
        if not isinstance(df_path, StringIO):
            split = os.path.splitext(df_path)
            if split[1] in ('.csv', '.feather'):
                constraints_path = split[0] + '.tdda'
        if constraints_path is None:
            print('No constraints file specified.', file=sys.stderr)
            sys.exit(1)

    df = load_df(df_path)
    from_feather = file_format(df_path) == 'feather'
    v = detect_df(df,
                  constraints_path,
                  outpath=outpath,
                  rownumber_is_index=from_feather,
                  **kwargs)
    if verbose and outpath is not None and outpath != '-':
        print(v)
    return v
예제 #2
0
def discover_df_from_file(df_path, constraints_path, verbose=True, **kwargs):
    df = load_df(df_path)
    constraints = discover_df(df, **kwargs)
    output = constraints.to_json()
    if constraints_path:
        with open(constraints_path, 'w') as f:
            f.write(output)
    elif verbose:
        print(output)
    return output
예제 #3
0
def verify_df_from_file(df_path, constraints_path, verbose=True, **kwargs):
    if df_path == '-' or df_path is None:
        df_path = StringIO(sys.stdin.read())
    if constraints_path is None:
        if not isinstance(df_path, StringIO):
            split = os.path.splitext(df_path)
            if split[1] in ('.csv', '.feather'):
                constraints_path = split[0] + '.tdda'
        if constraints_path is None:
            print('No constraints file specified.', file=sys.stderr)
            sys.exit(1)
    
    df = load_df(df_path)
    v = verify_df(df, constraints_path, **kwargs)
    if verbose:
        print(v)
    return v
예제 #4
0
파일: verify.py 프로젝트: tdda/tdda
def verify_df_from_file(df_path, constraints_path, verbose=True, **kwargs):
    if df_path == '-' or df_path is None:
        df_path = StringIO(sys.stdin.read())
    if constraints_path is None:
        if not isinstance(df_path, StringIO):
            split = os.path.splitext(df_path)
            if split[1] in ('.csv', '.feather'):
                constraints_path = split[0] + '.tdda'
        if constraints_path is None:
            print('No constraints file specified.', file=sys.stderr)
            sys.exit(1)

    df = load_df(df_path)
    v = verify_df(df, constraints_path, **kwargs)
    if verbose:
        print(v)
    return v
예제 #5
0
파일: discover.py 프로젝트: vitasiku/tdda
def discover_df_from_file(df_path, constraints_path, verbose=True, **kwargs):
    md_df_path = df_path
    if df_path == '-':
        df_path = StringIO(sys.stdin.read())
        md_df_path = None
    df = load_df(df_path)
    constraints = discover_df(df, df_path=md_df_path, **kwargs)
    if constraints is None:
        # should never happen
        return

    output = constraints.to_json(tddafile=constraints_path)
    if constraints_path and constraints_path != '-':
        with open(constraints_path, 'w') as f:
            f.write(output)
    elif verbose or constraints_path == '-':
        print(output)
    return output
예제 #6
0
파일: discover.py 프로젝트: tdda/tdda
def discover_df_from_file(df_path, constraints_path, verbose=True, **kwargs):
    md_df_path = df_path
    if df_path == '-':
        df_path = StringIO(sys.stdin.read())
        md_df_path = None
    df = load_df(df_path)
    constraints = discover_df(df, df_path=md_df_path, **kwargs)
    if constraints is None:
        # should never happen
        return

    output = constraints.to_json(tddafile=constraints_path)
    if constraints_path and constraints_path != '-':
        with open(constraints_path, 'w') as f:
            f.write(output)
    elif verbose or constraints_path == '-':
        print(output)
    return output
예제 #7
0
파일: detect.py 프로젝트: tdda/tdda
def detect_df_from_file(df_path, constraints_path, outpath,
                        verbose=True, **kwargs):
    if df_path == '-' or df_path is None:
        df_path = StringIO(sys.stdin.read())
    if constraints_path is None:
        if not isinstance(df_path, StringIO):
            split = os.path.splitext(df_path)
            if split[1] in ('.csv', '.feather'):
                constraints_path = split[0] + '.tdda'
        if constraints_path is None:
            print('No constraints file specified.', file=sys.stderr)
            sys.exit(1)

    df = load_df(df_path)
    from_feather = file_format(df_path) == 'feather'
    v = detect_df(df, constraints_path, outpath=outpath,
                  rownumber_is_index=from_feather, **kwargs)
    if verbose and outpath is not None and outpath != '-':
        print(v)
    return v
예제 #8
0
def verify_df_from_file(df_path, constraints_path, verbose=True, **kwargs):
    df = load_df(df_path)
    v = verify_df(df, constraints_path, **kwargs)
    if verbose:
        print(v)
    return v