def test_aggregate_handles_axis(axis): with pytest.raises(ValueError): aggregate( pd.DataFrame(index=pd.DatetimeIndex(['2017-01'])), pd.DataFrame(index=pd.DatetimeIndex(['2017-01'])), axis=axis, )
def test_aggregate_output_type_weight_dataframe( indices_3years, weights_3years, ): """The aggregate function should return a pandas Series.""" # GIVEN indices and weights pandas DataFrames # WHEN they are aggregated together # THEN returned aggregated is of type pandas Series aggregated = aggregate(indices_3years, weights_3years) assert isinstance(aggregated, pd.core.series.Series)
def test_aggregate_output_type_weight_series( indices_6months, weights_6months, ): """The aggregate function should return a pandas Series.""" # GIVEN indices DataFrame and weights Series # WHEN they are aggregated together # THEN returned aggregated is of type pandas Series aggregated = aggregate(indices_6months, weights_6months) assert isinstance(aggregated, pd.Series)
def test_aggregate(aggregate_combinator): """Functional test to test for expected output. Tests the following scenarios: * 3 years, 3 indices, 3 weights * 1 year, 3 indices, 3 weights * 6 months, 3 indices, 3 weights * 3 years, 3 indices (transposed), 3 weights (transposed) * 3 years, 3 indices (missing values), 3 weights * 3 years, 3 indices (missing values + transposed), 3 weights (transposed) """ # GIVEN indices and weights # AND the outcome # WHEN indices and weights are aggregated together # THEN they should equal the outcome indices, weights, outcome, axis = aggregate_combinator aggregated = aggregate(indices, weights, axis=axis) assert_series_equal(aggregated, outcome, check_names=False)
(Timestamp('2013-04-01 00:00:00'), 103.9939693, 103.707301, 102.8423593), (Timestamp('2013-05-01 00:00:00'), 107.55573159999999, np.nan, 106.4030102), (Timestamp('2013-06-01 00:00:00'), 102.15950079999999, 102.1210296, 103.6548477), (Timestamp('2013-07-01 00:00:00'), 106.83231370000001, 105.71647240000001, 106.23764979999999), ], ).set_index(0, drop=True) weights2 = pd.DataFrame.from_records([ (Timestamp('2013-01-01 00:00:00'), 13.1223919, 7.90254844, 3.20531341), ]).set_index(0, drop=True).squeeze() aggregated2 = aggregate(indices2.T, weights2.T, axis=0, ignore_na_indices=True) aggregated3 = aggregate(indices2, weights2, axis=1, ignore_na_indices=True) def aggregate_indices_missing(aggregate_indices_3years): """ """ aggregate_indices_missing = aggregate_indices_3years.copy() change_to_nans = [ ('2012-06', 2), ('2012-12', 3), ('2013-10', 2), ('2014-07', 1), ] for sl in change_to_nans: