Ejemplo n.º 1
0
def scalar_formatter(
        result: List, pricing_key: PricingKey
) -> Optional[Union[FloatWithInfo, SeriesWithInfo]]:
    if not result:
        return None

    result = __flatten_result(result)

    if len(result) > 1 and 'date' in result[0]:
        r = [
            __float_with_info_from_result(
                r, pricing_key.for_pricing_date(r['date'])) for r in result
        ]
        return FloatWithInfo.compose(r, pricing_key)
    else:
        return __float_with_info_from_result(result[0], pricing_key)
Ejemplo n.º 2
0
def scalar_formatter(result: List, pricing_key: PricingKey, _instrument: InstrumentBase)\
        -> Optional[Union[FloatWithInfo, SeriesWithInfo]]:
    if not result:
        return None

    result = __flatten_result(result)

    if len(result) > 1 and 'date' in result[0]:
        columns = [x for x in result[0].keys() if x != 'value']
        compressed_results = pd.DataFrame(result).groupby(columns).sum().reset_index().to_dict('records')
        r = [__float_with_info_from_result(r, pricing_key.for_pricing_date(r['date'])) for r in compressed_results]
        return FloatWithInfo.compose(
            r,
            pricing_key)
    else:
        return __float_with_info_from_result(result[0], pricing_key)