<commit_before>import warnings

def _determine_type(string, verbose):

    s = string.lower()

    extension = s.split('.')[-1]

    if extension in ['gz', 'bzip2', 'Z']:
        extension = s.split('.')[-2]

    if extension in ['fits', 'fit']:
        if verbose:
            print "Auto-detected input type: FITS table"
        table_type = 'fits'

    elif extension in ['xml', 'vot']:
        if verbose:
            print "Auto-detected input type: VO table"
        table_type = 'vo'

    elif extension in ['tbl', 'ipac']:
        if verbose:
            print "Auto-detected input type: IPAC table"
        table_type = 'ipac'

    elif s in ['sqlite', 'postgres', 'mysql']:
        if verbose:
            print "Auto-detected input type: SQL table"
        table_type = 'sql'

    else:
        raise Exception('Could not determine input type')

    return table_type


class AutoMethods(object):

    def read(self, *args, **kwargs):
        '''
        Read in a table or table set from a file/database.

        This method attempts to automatically guess the file/database format
        based on the arguments supplied. The type can be overridden by
        specifying type=string where string can be one of:

            * ``fits``
            * ``ipac``
            * ``sql``
            * ``vo``

        The arguments to supply to ``read()`` depend on the type of the input.
        For more information, see the help pages for the following methods:

           * ``fits_read``
           * ``ipac_read``
           * ``sql_read``
           * ``vo_read``
        '''

        if 'verbose' in kwargs:
            verbose = kwargs['verbose']
        else:
            verbose = True

        if 'type' in kwargs:
            table_type = kwargs.pop('type').lower()
        elif type(args[0]) == str:
            table_type = _determine_type(args[0], verbose)
        else:
            raise Exception('Could not determine input type')

        original_filters = warnings.filters[:]

        if verbose:
            warnings.simplefilter("always")
        else:
            warnings.simplefilter("ignore")

        try:

            if verbose:
                warnings.simplefilter("always")
            else:
                warnings.simplefilter("ignore")

            if table_type == 'fits':
                self.fits_read(*args, **kwargs)
            elif table_type == 'vo':
                self.vo_read(*args, **kwargs)
            elif table_type == 'ipac':
                self.ipac_read(*args, **kwargs)
            elif table_type == 'sql':
                self.sql_read(*args, **kwargs)
            else:
                raise Exception("Unknown table type: " + table_type)

        finally:
            warnings.filters = original_filters

        return

    def write(self, *args, **kwargs):
        '''
        Write out a table or table set to a file/database.

        This method attempts to automatically guess the file/database format
        based on the arguments supplied. The type can be overridden by
        specifying type=string where string can be one of:

            * ``fits``
            * ``ipac``
            * ``sql``
            * ``vo``

        The arguments to supply to ``write()`` depend on the type of the
        output. For more information, see the help pages for the following
        methods:

           * ``fits_write``
           * ``ipac_write``
           * ``sql_write``
           * ``vo_write``
        '''

        if 'verbose' in kwargs:<commit_msg>Improved read() and write() docstrings to mention verbosity control<commit_after>import warnings

def _determine_type(string, verbose):

    s = string.lower()

    extension = s.split('.')[-1]

    if extension in ['gz', 'bzip2', 'Z']:
        extension = s.split('.')[-2]

    if extension in ['fits', 'fit']:
        if verbose:
            print "Auto-detected input type: FITS table"
        table_type = 'fits'

    elif extension in ['xml', 'vot']:
        if verbose:
            print "Auto-detected input type: VO table"
        table_type = 'vo'

    elif extension in ['tbl', 'ipac']:
        if verbose:
            print "Auto-detected input type: IPAC table"
        table_type = 'ipac'

    elif s in ['sqlite', 'postgres', 'mysql']:
        if verbose:
            print "Auto-detected input type: SQL table"
        table_type = 'sql'

    else:
        raise Exception('Could not determine input type')

    return table_type


class AutoMethods(object):

    def read(self, *args, **kwargs):
        '''
        Read in a table or table set from a file/database.

        Optional Keyword Arguments (independent of table type):

            *verbose*: [ True | False ]
                Whether to print out warnings when reading (default is True)

            *type*: [ string ]
                The read method attempts to automatically guess the
                file/database format based on the arguments supplied. The type
                can be overridden by setting this argument to one of:

                    * ``fits``
                    * ``ipac``
                    * ``sql``
                    * ``vo``

        The remaining arguments to supply to ``read()`` depend on the type of
        the input. For more information, see the help pages for the following
        methods:

           * ``fits_read``
           * ``ipac_read``
           * ``sql_read``
           * ``vo_read``
        '''

        if 'verbose' in kwargs:
            verbose = kwargs['verbose']
        else:
            verbose = True

        if 'type' in kwargs:
            table_type = kwargs.pop('type').lower()
        elif type(args[0]) == str:
            table_type = _determine_type(args[0], verbose)
        else:
            raise Exception('Could not determine input type')

        original_filters = warnings.filters[:]

        if verbose:
            warnings.simplefilter("always")
        else:
            warnings.simplefilter("ignore")

        try:

            if verbose:
                warnings.simplefilter("always")
            else:
                warnings.simplefilter("ignore")

            if table_type == 'fits':
                self.fits_read(*args, **kwargs)
            elif table_type == 'vo':
                self.vo_read(*args, **kwargs)
            elif table_type == 'ipac':
                self.ipac_read(*args, **kwargs)
            elif table_type == 'sql':
                self.sql_read(*args, **kwargs)
            else:
                raise Exception("Unknown table type: " + table_type)

        finally:
            warnings.filters = original_filters

        return

    def write(self, *args, **kwargs):
        '''
        Write out a table or table set to a file/database.

        Optional Keyword Arguments (independent of table type):

            *verbose*: [ True | False ]
                Whether to print out warnings when writing (default is True)

            *type*: [ string ]
                The write method attempts to automatically guess the
                file/database format based on the arguments supplied. The type
                can be overridden by setting this argument to one of:

                    * ``fits``
                    * ``ipac``
                    * ``sql``
                    * ``vo``

        The remaining arguments to supply to ``write()`` depend on the type of
        the output. For more information, see the help pages for the following
        methods:

           * ``fits_write``
           * ``ipac_write``
           * ``sql_write``
           * ``vo_write``
        '''

        if 'verbose' in kwargs:
{'fraction_non_alphanumeric': 0.10531817587874036, 'fraction_numerical': 0.0013066771200836273, 'mean_word_length': 1.6622608695652175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3258262', 'n_tokens_mistral': 2059, 'n_tokens_neox': 1945, 'n_words': 675}