Skip to content

Commit

Permalink
📝 Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
judynah committed Dec 4, 2024
1 parent 9604566 commit 1c663bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/viadot/sources/tm1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from viadot.config import get_source_credentials
from viadot.exceptions import ValidationError
from viadot.sources.base import Source
from viadot.utils import add_viadot_metadata_columns


class TM1Credentials(BaseModel):
Expand All @@ -28,7 +29,7 @@ class TM1Credentials(BaseModel):


class TM1(Source):
"""Class for downloading data from TM1 Software using TM1py library."""
"""TM1 connector."""

def __init__(
self,
Expand All @@ -45,17 +46,14 @@ def __init__(
*args,
**kwargs,
):
"""Creating an instance of TM1 source class.
To download the data to the dataframe user needs to specify MDX query or
combination of cube and view.
"""Create a TM1 connector instance.
Args:
credentials (dict[str, Any], optional): Credentials stored in a dictionary.
Required credentials: username, password, address, port.
Defaults to None.
config_key (str, optional): Credential key to dictionary where credentials
are stored. Defaults to "TM1".
config_key (str, optional): The key in the viadot config holding relevant
credentials. Defaults to "TM1".
mdx_query (str, optional): MDX select query needed to download the data.
Defaults to None.
cube (str, optional): Cube name from which data will be downloaded.
Expand Down Expand Up @@ -169,8 +167,9 @@ def get_available_elements(self) -> list:
dimension_name=self.dimension, hierarchy_name=self.hierarchy
)

@add_viadot_metadata_columns
def to_df(self, if_empty: Literal["warn", "fail", "skip"] = "skip") -> pd.DataFrame:
"""Function for downloading data from TM1 to pd.DataFrame.
"""Download data into a pandas DataFrame.
To download the data to the dataframe user needs to specify MDX query
or combination of cube and view.
Expand All @@ -180,7 +179,7 @@ def to_df(self, if_empty: Literal["warn", "fail", "skip"] = "skip") -> pd.DataFr
DataFrame is empty. Defaults to "skip".
Returns:
pd.DataFrame: DataFrame with data downloaded from TM1 view.
pd.DataFrame: DataFrame with the data.
Raises:
ValidationError: When mdx and cube + view are not specified
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_tm1.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_to_df(tm1):
result = tm1.to_df()
assert isinstance(result, pd.DataFrame)
assert not result.empty
assert len(result.columns) == 2
assert len(result.columns) == 4

def test_to_df_fail(tm1_mock):
with pytest.raises(ValidationError) as excinfo:
Expand Down

0 comments on commit 1c663bc

Please sign in to comment.