Esempio n. 1
0
def test_across_dataframe_single_column_with_lambda():

    convert_date = lambda x: x.strftime('%b %-d, %Y') if not x is pd.NaT else x

    df = generate_periods(delta_range=(1, 10), rows=20)
    df = make_null_dates(df, null_values_percent=.2)

    exp = df.copy(deep=True)
    exp.effective = exp.effective.apply(convert_date)

    got = across(df, columns='effective', function=convert_date)

    assert exp.equals(got) == True
Esempio n. 2
0
def test_across_raise_function_parm_none_ValueError():

    convert_date = lambda x: pd.to_datetime(
        x, dayfirst=True, format='%d%m%Y', errors='coerce')

    test = [30112019, 2942019, 3022019, 2822019, 2019430]
    got = pd.DataFrame(test, columns=['dates'])

    # Convert expected values to datetime format
    exp = ['30/11/2019', '29/4/2019', pd.NaT, '28/2/2019', pd.NaT]
    exp = pd.DataFrame(exp, columns=['dates'])
    exp.dates = exp.dates.astype('datetime64[ns]')

    with pytest.raises(ValueError):
        got = across(got, columns='dates', function=None)
Esempio n. 3
0
def test_across_dataframe_multiple_columns_raise_invalid_column():

    convert_date = lambda x: x.strftime('%b %-d, %Y') if not x is pd.NaT else x

    df = generate_periods(delta_range=(1, 10), rows=20)
    df = make_null_dates(df, null_values_percent=.2)

    exp = df.copy(deep=True)
    exp.effective = exp.effective.apply(convert_date)
    exp.expired = exp.expired.apply(convert_date)

    with pytest.raises(ValueError):
        got = across(df,
                     columns=['effective', 'invalid'],
                     function=convert_date)
Esempio n. 4
0
def test_across_str_date_single_col_lambda():
    ''' '''
    convert_date = lambda x: pd.to_datetime(
        x, dayfirst=True, format='%d%m%Y', errors='coerce')

    test = [30112019, 2942019, 3022019, 2822019, 2019430]
    got = pd.DataFrame(test, columns=['dates'])

    # Convert expected values to datetime format
    exp = ['30/11/2019', '29/4/2019', pd.NaT, '28/2/2019', pd.NaT]
    exp = pd.DataFrame(exp, columns=['dates'])
    exp.dates = exp.dates.astype('datetime64[ns]')

    got = across(got, 'dates', convert_date)

    assert exp.equals(got) == True
Esempio n. 5
0
def test_across_str_date_single_col_pd_to_datetime():
    ''' '''
    test = ['30/11/2019', '29/4/2019', '30/2/2019', '28/2/2019', '2019/4/30']
    got = pd.DataFrame(test, columns=['dates'])

    # Convert expected values to datetime format
    exp = ['30/11/2019', '29/4/2019', pd.NaT, '28/2/2019', pd.NaT]
    exp = pd.DataFrame(exp, columns=['dates'])
    exp.dates = exp.dates.astype('datetime64[ns]')

    got = across(got,
                 'dates',
                 pd.to_datetime,
                 format='%d/%m/%Y',
                 errors='coerce')

    assert exp.equals(got) == True