<commit_before>#!/usr/bin/env python

import agate
import agateexcel
import dbf
import six

from csvkit.convert.fixed import fixed2csv
from csvkit.convert.geojs import geojson2csv

agateexcel.patch()

SUPPORTED_FORMATS = ['csv', 'dbf', 'geojson', 'json', 'ndjson', 'fixed', 'xls', 'xlsx']


def convert(f, format, schema=None, key=None, output=None, **kwargs):
    """
    Convert a file of a specified format to CSV.
    """
    if not f:
        raise ValueError('f must not be None')

    if not format:
        raise ValueError('format must not be None')

    if format == 'fixed':
        if not schema:
            raise ValueError('schema must not be null when format is "fixed"')

        output_file.write(fixed2csv(f, schema, **kwargs))
    elif format == 'geojson':
        output_file.write(geojson2csv(f, **kwargs))
    elif format in ('csv', 'dbf', 'json', 'ndjson', 'xls', 'xlsx'):
        if format == 'csv':
            table = agate.Table.from_csv(f, **kwargs)
        elif format == 'json':
            table = agate.Table.from_json(f, key=key, **kwargs)
        elif format == 'ndjson':
            table = agate.Table.from_json(f, key=key, newline=True, **kwargs)
        elif format == 'xls':
            table = agate.Table.from_xls(f, sheet=kwargs.get('sheet', None))
        elif format == 'xlsx':
            table = agate.Table.from_xlsx(f, sheet=kwargs.get('sheet', None))
        elif format == 'dbf':
            with dbf.Table(f.name) as db:
                column_names = db.field_names
                table = agate.Table(db, column_names)

        table.to_csv(output)<commit_msg>Fix typo<commit_after>#!/usr/bin/env python

import agate
import agateexcel
import dbf
import six

from csvkit.convert.fixed import fixed2csv
from csvkit.convert.geojs import geojson2csv

agateexcel.patch()

SUPPORTED_FORMATS = ['csv', 'dbf', 'geojson', 'json', 'ndjson', 'fixed', 'xls', 'xlsx']


def convert(f, format, schema=None, key=None, output=None, **kwargs):
    """
    Convert a file of a specified format to CSV.
    """
    if not f:
        raise ValueError('f must not be None')

    if not format:
        raise ValueError('format must not be None')

    if format == 'fixed':
        if not schema:
            raise ValueError('schema must not be null when format is "fixed"')

        output.write(fixed2csv(f, schema, **kwargs))
    elif format == 'geojson':
        output.write(geojson2csv(f, **kwargs))
    elif format in ('csv', 'dbf', 'json', 'ndjson', 'xls', 'xlsx'):
        if format == 'csv':
            table = agate.Table.from_csv(f, **kwargs)
        elif format == 'json':
            table = agate.Table.from_json(f, key=key, **kwargs)
        elif format == 'ndjson':
            table = agate.Table.from_json(f, key=key, newline=True, **kwargs)
        elif format == 'xls':
            table = agate.Table.from_xls(f, sheet=kwargs.get('sheet', None))
        elif format == 'xlsx':
            table = agate.Table.from_xlsx(f, sheet=kwargs.get('sheet', None))
        elif format == 'dbf':
            with dbf.Table(f.name) as db:
                column_names = db.field_names
                table = agate.Table(db, column_names)

        table.to_csv(output)
{'fraction_non_alphanumeric': 0.14067849361967008, 'fraction_numerical': 0.0024898848428260194, 'mean_word_length': 2.6275395033860045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6928731', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1029, 'n_words': 286}