Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dtype to be inferred by pandas with argument infer_dtype in execute_mdx_dataframe_shaped #879

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions TM1py/Services/CellService.py
Original file line number Diff line number Diff line change
Expand Up @@ -2798,13 +2798,15 @@ def extract_cellset_dataframe(
@tidy_cellset
@require_pandas
def extract_cellset_dataframe_shaped(self, cellset_id: str, sandbox_name: str = None,
display_attribute: bool = False, **kwargs) -> 'pd.DataFrame':
display_attribute: bool = False, infer_dtype: bool = False, **kwargs) -> 'pd.DataFrame':
""" Retrieves data from cellset in the shape of the query.
Dimensions on rows can be stacked. One dimension must be placed on columns. Title selections are ignored.

:param cellset_id
:param sandbox_name: str
:param display_attribute: bool, show element name or first attribute from MDX PROPERTIES clause
:param infer_dtype: bool, if True, lets pandas infer dtypes, otherwise all columns will be of type str.

"""
url = "/api/v1/Cellsets('{}')?$expand=" \
"Axes($filter=Ordinal eq 0 or Ordinal eq 1;$expand=Tuples(" \
Expand Down Expand Up @@ -2860,7 +2862,10 @@ def extract_cellset_dataframe_shaped(self, cellset_id: str, sandbox_name: str =

for element_tuple, cells in zip(element_names_by_row, cell_values_by_row):
body.append(list(element_tuple) + cells)
return pd.DataFrame(body, columns=headers, dtype=str)
if infer_dtype:
return pd.DataFrame(body, columns=headers)
else:
return pd.DataFrame(body, columns=headers, dtype=str)

@require_pandas
def extract_cellset_dataframe_pivot(self, cellset_id: str, dropna: bool = False, fill_value: bool = False,
Expand Down