Allow dtype to be inferred by pandas with argument infer_dtype in execute_mdx_dataframe_shaped #879
+7
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Allows tm1py user to specify the infer_dtype argument on tm1.cells.execute_mdx_dataframe_shaped.
If infer_dtype=True, tm1py lets pandas decide the dtype of each column. If infer_dtype=False, it will default to the current behaviour and load all columns as string unless there is no columns (see "if not number_columns") or no rows (see "if not number_rows") (in which case tm1.cells.execute_mdx_dataframe_shaped will already infer the dtype automatically).
If the infer_dtype argument is not specified, tm1.cells.execute_mdx_dataframe_shaped will default to its current behaviour equivalent to infer_dtype=False.
Why
Default behaviour requires to mutate dtypes after retrieving dataframe. If all columns are numerical, the dataframe retrieved would still have string values. This PR allows the user to choose.
Test
Below test shows how a numeric column would be inferred as a proper dtype automatically. The numeric column can them directly be multiplied. The string column on the other hand not.
@MariusWirtz , the test is based on the tm1_cloud sample instance:
Outcome