import pandas as pd


def check_oseries(oseries, freq, fillnan='drop'):
    """Check the observed time series before running a simulation.

    Parameters
    ----------
    oseries: pd.Series
        Pandas series object containing the observed time series.
    freq: str
        String containing the desired frequency. The required string format is found
        at http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset
        -aliases
    fillnan: optional: str or float
        Methods or float number to fill nan-values. Default values is
        'drop'. Currently supported options are: 'interpolate', float,
        and 'mean'. Interpolation is performed with a standard linear
        interpolation.

    Returns
    -------
    oseries: pd.Series
        Pandas series object check for nan-values and with the required frequency.

    """
    assert isinstance(oseries, pd.Series), 'Expected a Pandas Series object, ' \
                                           'got %s' % type(oseries)

    # make a deep copy to preserve original imported data
    oseries = oseries.loc[oseries.first_valid_index():oseries.last_valid_index(
    )].copy(deep=True)

    # Deal with frequency of the time series
    if freq:
        oseries = oseries.resample(freq)

    # Handle nan-values in oseries
    if oseries.hasnans:
        print '%i nan-value(s) was/were found and handled/filled with: %s' % (
            oseries.isnull().values.sum(), fillnan)
        if fillnan == 'mean':
            oseries.fillna(stress.mean(), inplace=True)
        elif fillnan == 'interpolate':
            oseries.interpolate(method='time', inplace=True)
        elif type(fillnan) == float:
            oseries.fillna(fillnan, inplace=True)
        else:
            oseries.dropna(inplace=True) # Default option

    return oseries


def check_tseries(stress, freq, fillnan):
    """ Check the stress series when creating a time series model.

    Parameters
    ----------
    tseries: pd.Series
        Pandas series object containing the stress time series.
    freq: str
        String containing the desired frequency. The required string format is found
        at http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset
        -aliases
    fillnan: optional: str or float
        Methods or float number to fill nan-values. Default values is
        'mean'. Currently supported options are: 'interpolate', float,
        and 'mean'. Interpolation is performed with a standard linear
        interpolation.

    Returns
    -------
    the corrected stress as pd.Series:
        - nan-values dropped at begin and end.
        - frequency made constant.
        - handled nan-values in between.
    """

    assert isinstance(stress, pd.Series), 'Expected a Pandas Series, ' \
                                          'got %s' % type(stress)

    # Drop nan-values at the beginning of the time series
    stress = stress.loc[stress.first_valid_index():stress.last_valid_index(
    )].copy(deep=True)

    # Make frequency of the stress series constant
    if freq:
        stress = stress.asfreq(freq)
    else:
        freq = pd.infer_freq(stress.index)
        print 'Tried to infer frequency from time series: freq=%s' %freq
        stress = stress.asfreq(freq)

    # Handle nan-values in stress series
    if stress.hasnans:
        print '%i nan-value(s) was/were found and filled with: %s' % (
            stress.isnull().values.sum(), fillnan)
        if fillnan == 'interpolate':
            stress.interpolate(method='time')
        elif type(fillnan) == float:
            print fillnan, 'init'
            stress.fillna(fillnan, inplace=True)
        else:
            stress.fillna(stress.mean(), inplace=True)  # Default option
    return stress

@@ -1,12 +1,85 @@
+%22%22%22%0Achecks module%0A    This module is used to check the time series.%0A%0A%22%22%22%0A
 import panda
@@ -700,34 +700,42 @@
 at,%0A        
-and 
 'mean'
+ and, 'drop'
 . Interpolat
@@ -879,16 +879,18 @@
 ct check
+ed
  for nan
@@ -1301,32 +1301,54 @@
 es%0A    if freq:%0A
+        print Warning%0A
         oseries 
@@ -1454,32 +1454,47 @@
 '%25i nan-value(s)
+ in the oseries
  was/were found 
@@ -1508,24 +1508,43 @@
 dled/filled 
+' %5C%0A              '
 with: %25s' %25 
@@ -1544,29 +1544,16 @@
  %25s' %25 (
-%0A            
 oseries.
@@ -1605,16 +1605,107 @@
 llnan ==
+ 'drop':%0A            oseries.dropna(inplace=True)  # Default option%0A        elif fillnan ==
  'mean':
@@ -1724,37 +1724,38 @@
  oseries.fillna(
-stres
+oserie
 s.mean(), inplac
@@ -1979,52 +1979,106 @@
     
-oseries.dropna(inplace=True) # Default optio
+print 'User-defined option for fillnan %25s isinstance() not supported' %5C%0A                  %25 fillna
 n%0A%0A 
@@ -2241,22 +2241,21 @@
 ---%0A    
-tserie
+stres
 s: pd.Se
@@ -3162,16 +3162,24 @@
 ginning 
+and end 
 of the t
@@ -3462,22 +3462,16 @@
 nt '
-Tried to i
+I
 nfer
+red
  fre
@@ -3505,16 +3505,17 @@
 eq=%25s' %25
+ 
 freq%0A   
@@ -3748,32 +3748,137 @@
    if fillnan ==
+ 'mean':%0A            stress.fillna(stress.mean(), inplace=True)  # Default option%0A        elif fillnan ==
  'interpolate':%0A
@@ -4073,68 +4073,108 @@
     
-stress.fillna(stress.mean(), inplace=True)  # Default option
+print 'User-defined option for fillnan %25s isinstance() not supported' %5C%0A                  %25 fillnan%0A
 %0A   

Update checks