How to use the clevercsv._optional.import_optional_dependency function in clevercsv

To help you get started, we’ve selected a few clevercsv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alan-turing-institute / CleverCSV / clevercsv / __main__.py View on Github external
def main():
    # Check that necessary dependencies are available
    import_optional_dependency("cleo")
    import_optional_dependency("clikit")
    import_optional_dependency(
        "tabview", raise_on_missing=not sys.platform == "win32"
    )

    # if so, load the actual main function and call it.
    from .console import main as realmain

    sys.exit(realmain())
github alan-turing-institute / CleverCSV / clevercsv / __main__.py View on Github external
def main():
    # Check that necessary dependencies are available
    import_optional_dependency("cleo")
    import_optional_dependency("clikit")
    import_optional_dependency(
        "tabview", raise_on_missing=not sys.platform == "win32"
    )

    # if so, load the actual main function and call it.
    from .console import main as realmain

    sys.exit(realmain())
github alan-turing-institute / CleverCSV / clevercsv / __main__.py View on Github external
def main():
    # Check that necessary dependencies are available
    import_optional_dependency("cleo")
    import_optional_dependency("clikit")
    import_optional_dependency(
        "tabview", raise_on_missing=not sys.platform == "win32"
    )

    # if so, load the actual main function and call it.
    from .console import main as realmain

    sys.exit(realmain())
github alan-turing-institute / CleverCSV / clevercsv / wrappers.py View on Github external
num_chars: int
        Number of characters to use for dialect detection. If None, use the 
        entire file.

        Note that using less than the entire file will speed up detection, but 
        can reduce the accuracy of the detected dialect.

    **kwargs:
        Additional keyword arguments for the ``pandas.read_csv`` function. You 
        can specify the file encoding here if needed, and it will be used 
        during dialect detection.

    """
    if not (os.path.exists(filename) and os.path.isfile(filename)):
        raise ValueError("Filename must be a regular file")
    pd = import_optional_dependency("pandas")

    # Use provided encoding or detect it, and record it for pandas
    enc = kwargs.get("encoding") or get_encoding(filename)
    kwargs["encoding"] = enc

    with open(filename, "r", newline="", encoding=enc) as fid:
        data = fid.read(num_chars) if num_chars else fid.read()
        dialect = Detector().detect(data)
    csv_dialect = dialect.to_csv_dialect()

    # This is used to catch pandas' warnings when a dialect is supplied.
    with warnings.catch_warnings():
        warnings.filterwarnings(
            "ignore",
            message="^Conflicting values for .*",
            category=pd.errors.ParserWarning,