mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 21:12:16 +00:00
* #2583 [CT] Add and use denomination helper * #2583 [CT] Fix Yahoo Finance denomination * #2583 [CT] Fix typings for dict * #2583 [CT] Add YF model get financials tests * #2583 [CT] Fix stubbed currency * #2583 [CT] Add test coverage for denomination helpers * #2583 [CT] Fix YF view not exporting raw data Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com>
62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
# IMPORTATION STANDARD
|
|
from typing import Callable
|
|
import pytest
|
|
from pandas._typing import Axis
|
|
from pandas.testing import assert_frame_equal
|
|
import pandas as pd
|
|
|
|
# IMPORTATION INTERNAL
|
|
|
|
from openbb_terminal.helpers_denomination import (
|
|
DENOMINATION,
|
|
transform as transform_by_denomination,
|
|
get_denomination,
|
|
get_denominations,
|
|
)
|
|
|
|
df = pd.DataFrame(
|
|
data={"Revenue": [1000000, 2000000, 3000000], "EPS": [3, 4, 5]},
|
|
index=["ttm", "2022-01-01", "2021-01-01"],
|
|
)
|
|
dftr = df.transpose()
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"source, target, maxValue, axis, skipPredicate",
|
|
[
|
|
("Units", None, None, 0, None),
|
|
("Units", None, 100, 0, None),
|
|
("Millions", "Thousands", None, 1, lambda s: s.name == "EPS"),
|
|
],
|
|
)
|
|
def test_given_arguments_then_it_transforms_as_expected(
|
|
source: DENOMINATION,
|
|
target: DENOMINATION,
|
|
maxValue: float,
|
|
axis: Axis,
|
|
skipPredicate: Callable[[pd.Series], bool],
|
|
):
|
|
target_df = dftr if axis == 1 else df
|
|
expectedMax = maxValue if maxValue is not None else target_df.max().max()
|
|
expectedTargetDenomination = (
|
|
target if target is not None else get_denomination(expectedMax)[0]
|
|
)
|
|
|
|
expected_df = target_df.apply(
|
|
lambda series: series
|
|
if skipPredicate is not None and skipPredicate(series)
|
|
else series
|
|
* (
|
|
get_denominations()[source]
|
|
/ get_denominations()[expectedTargetDenomination]
|
|
),
|
|
axis,
|
|
)
|
|
|
|
(dft, denomination) = transform_by_denomination(
|
|
target_df, source, target, maxValue, axis, skipPredicate
|
|
)
|
|
|
|
assert denomination == expectedTargetDenomination
|
|
assert_frame_equal(dft, expected_df)
|