<commit_before>import matplotlib.pyplot as plt
import os

def save_all_figs(directory = './', fmt = None, 
    default_name = 'untitled%i'):
    """
    Save all open Figures to a given directory, possbily in numerous 
    file formats
    
    Parameters
    ------------
    directory : str
        path to save figures into
    fmt : str, list of strs, or None
        the types of formats to save figures as. The elements of this
        list are passed to matplotlib's `savefig`. see example.
    default_name : str
        the default filename to use if plot has no title. must contain 
        a '%i' for the figure number
    
    Examples
    --------
    >>> save_all_figs('plots/', fmt=['pdf','png'])
    
    """
    
    for fignum in plt.get_fignums():
        try:
            # try to get title of figure(fignum)
            filename = plt.figure(fignum).get_axes()[0].get_title()
            
            # create filename if title doesnt exist
            if filename == '':
                filename = default_name % fignum
                    
            savename = os.path.join(directory, filename)
    
            if fmt is None:
                # get default format from rcParams
                ## FIX would prefer this but i couldnt find the correct key
                # fmt = plt.rcParams['savefig.extension']
                ## /FIX
                fmt = 'png'
            
            if isinstance(fmt, basestring):
                # force string into list of strings
                fmt = [fmt]
            
            for a_fmt in fmt:
                plt.savefig(savename + '.' + a_fmt)
                print ('Saved \'%s\' '% (savename + '.' + a_fmt))
        
        except(IndexError):
            # figure has no axes to get, dont save it
            pass
        

<commit_msg>fix rcParams get savefig.extensions, to support existent and non-existent keys.<commit_after>import matplotlib.pyplot as plt
import os

def save_all_figs(directory = './', fmt = None, 
    default_name = 'untitled%i'):
    """
    Save all open Figures to a given directory, possbily in numerous 
    file formats
    
    Parameters
    ------------
    directory : str
        path to save figures into
    fmt : str, list of strs, or None
        the types of formats to save figures as. The elements of this
        list are passed to matplotlib's `savefig`. see example.
    default_name : str
        the default filename to use if plot has no title. must contain 
        a '%i' for the figure number
    
    Examples
    --------
    >>> save_all_figs('plots/', fmt=['pdf','png'])
    
    """
    
    for fignum in plt.get_fignums():
        try:
            # try to get title of figure(fignum)
            filename = plt.figure(fignum).get_axes()[0].get_title()
            
            # create filename if title doesnt exist
            if filename == '':
                filename = default_name % fignum
                    
            savename = os.path.join(directory, filename)
    
            if fmt is None:
                # get default format from rcParams
                fmt = plt.rcParams.get('savefig.extension','png')
            
            if isinstance(fmt, basestring):
                # force string into list of strings
                fmt = [fmt]
            
            for a_fmt in fmt:
                plt.savefig(savename + '.' + a_fmt)
                print ('Saved \'%s\' '% (savename + '.' + a_fmt))
        
        except(IndexError):
            # figure has no axes to get, dont save it
            pass
        


{'fraction_non_alphanumeric': 0.09408151870463428, 'fraction_numerical': 0.0005583472920156337, 'mean_word_length': 1.4899235580264072, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2181953', 'n_tokens_mistral': 986, 'n_tokens_neox': 948, 'n_words': 331}