Skip to content

Commit

Permalink
Release 1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusWirtz committed Apr 14, 2023
1 parent 44a20e0 commit f9d374b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
30 changes: 24 additions & 6 deletions TM1py/Services/CellService.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def write_dataframe(self, cube_name: str, data: 'pd.DataFrame', dimensions: Iter
use_ti: bool = False, use_blob: bool = False, use_changeset: bool = False,
precision: int = None,
skip_non_updateable: bool = False, measure_dimension_elements: Dict = None,
sum_numeric_duplicates: bool = True, **kwargs) -> str:
sum_numeric_duplicates: bool = True, remove_blob: bool = True, **kwargs) -> str:
"""
Function expects same shape as `execute_mdx_dataframe` returns.
Column order must match dimensions in the target cube with an additional column for the values.
Expand All @@ -648,7 +648,8 @@ def write_dataframe(self, cube_name: str, data: 'pd.DataFrame', dimensions: Iter
:param measure_dimension_elements: dictionary of measure elements and their types to improve
performance when `use_ti` is `True`.
When all written values are numeric you can pass a default dict with default key 'Numeric'
:sum_numeric_duplicates: Aggregate numerical values for duplicated intersections
:param sum_numeric_duplicates: Aggregate numerical values for duplicated intersections
:param remove_blob: remove blob file after writing with use_blob=True
:return: changeset or None
"""
if not isinstance(data, pd.DataFrame):
Expand All @@ -671,6 +672,7 @@ def write_dataframe(self, cube_name: str, data: 'pd.DataFrame', dimensions: Iter
sandbox_name=sandbox_name,
use_ti=use_ti,
use_blob=use_blob,
remove_blob=remove_blob,
use_changeset=use_changeset,
precision=precision,
skip_non_updateable=skip_non_updateable,
Expand Down Expand Up @@ -834,7 +836,7 @@ def write(self, cube_name: str, cellset_as_dict: Dict, dimensions: Iterable[str]
deactivate_transaction_log: bool = False, reactivate_transaction_log: bool = False,
sandbox_name: str = None, use_ti: bool = False, use_blob: bool = False, use_changeset: bool = False,
precision: int = None, skip_non_updateable: bool = False, measure_dimension_elements: Dict = None,
**kwargs) -> Optional[str]:
remove_blob: bool = True, **kwargs) -> Optional[str]:
""" Write values to a cube
Same signature as `write_values` method, but faster since it uses `write_values_through_cellset`
Expand All @@ -859,6 +861,7 @@ def write(self, cube_name: str, cellset_as_dict: Dict, dimensions: Iterable[str]
:param measure_dimension_elements: dictionary of measure elements and their types to improve
performance when `use_ti` is `True`.
When all written values are numeric you can pass a default dict with default key 'Numeric'
:param remove_blob: remove blob file after writing with use_blob=True
:return: changeset or None
"""

Expand All @@ -885,6 +888,7 @@ def write(self, cube_name: str, cellset_as_dict: Dict, dimensions: Iterable[str]
reactivate_transaction_log=reactivate_transaction_log,
skip_non_updateable=skip_non_updateable,
dimensions=dimensions,
remove_blob=remove_blob,
**kwargs)

return self.write_through_cellset(cube_name, cellset_as_dict, dimensions, increment, deactivate_transaction_log,
Expand Down Expand Up @@ -1017,15 +1021,15 @@ def write_through_unbound_process(self, cube_name: str, cellset_as_dict: Dict, i
@require_pandas
def write_through_blob(self, cube_name: str, cellset_as_dict: dict, increment: bool = False,
sandbox_name: str = None, skip_non_updateable: bool = False,
delete_blob=True, dimensions: str = None, **kwargs):
remove_blob=True, dimensions: str = None, **kwargs):
"""
Writes data back to TM1 via an unbound TI process having an uploaded CSV as data source
:param cube_name: str
:param cellset_as_dict:
:param increment: increment or update cell values
:param sandbox_name: str
:param skip_non_updateable skip cells that are not updateable (e.g. rule derived or consolidated)
:param delete_blob: choose False for debugging purposes
:param remove_blob: choose False to persist blob after write. Can be helpful for troubleshooting.
:param dimensions: optional. Dimension names in their natural order. Will speed up the execution!
:param kwargs:
:return: Success: bool, Messages: list, ChangeSet: None
Expand Down Expand Up @@ -1074,7 +1078,7 @@ def write_through_blob(self, cube_name: str, cellset_as_dict: dict, increment: b
raise TM1pyWriteFailureException([status], [log_file])

finally:
if delete_blob:
if remove_blob:
file_service.delete(file_name=file_name)

def _build_blob_to_cube_process(self, cube_name: str, process_name: str, blob_filename: str, dimensions: List[str],
Expand Down Expand Up @@ -1954,6 +1958,9 @@ def execute_mdx_dataframe(self, mdx: Union[str, MdxBuilder], top: int = None, sk
Takes all arguments from the pandas.read_csv method:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html
If 'use_blob' and 'shaped' are True, 'skip_zeros' will be overruled to False.
This is necessary to assure column order is in line with cube view in TM1
:param mdx: Valid MDX Query
:param top: Int, number of cells to return (counting from top)
:param skip: Int, number of cells to skip (counting from top)
Expand All @@ -1970,6 +1977,10 @@ def execute_mdx_dataframe(self, mdx: Union[str, MdxBuilder], top: int = None, sk
:return: Pandas Dataframe
"""
if use_blob:
# necessary to assure column order in line with cube view
if shaped:
skip_zeros = False

raw_csv = self.execute_mdx_csv(
mdx=mdx,
top=top,
Expand Down Expand Up @@ -2195,6 +2206,9 @@ def execute_view_dataframe(self, cube_name: str, view_name: str, private: bool =
Context dimensions are omitted in the resulting Dataframe !
Cells with Zero/null are omitted !
If 'use_blob' and 'shaped' are True, 'skip_zeros' will be overruled to False.
This is necessary to assure column order is in line with cube view in TM1
Takes all arguments from the pandas.read_csv method:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html
Expand All @@ -2213,6 +2227,10 @@ def execute_view_dataframe(self, cube_name: str, view_name: str, private: bool =
:return: Pandas Dataframe
"""
if use_blob:
# necessary to assure column order in line with cube view
if shaped:
skip_zeros = False

raw_csv = self.execute_view_csv(
cube_name=cube_name,
view_name=view_name,
Expand Down
18 changes: 9 additions & 9 deletions TM1py/Services/CubeService.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get_number_of_cubes(self, skip_control_cubes: bool = False, **kwargs) -> int
:skip_control_cubes: bool, True will exclude control cubes from count
:return: int, count
"""
"""
if skip_control_cubes:
response = self._rest.GET(url=format_url("/api/v1/ModelCubes()?$select=Name&$top=0&$count"), **kwargs)
return int(response.json()['@odata.count'])
Expand Down Expand Up @@ -161,8 +161,8 @@ def get_all_names(self, skip_control_cubes: bool = False, **kwargs) -> List[str]
:return: List of Strings
"""
url = format_url(
"/api/v1/{}?$select=Name",
'ModelCubes()' if skip_control_cubes else 'Cubes'
"/api/v1/{}?$select=Name",
'ModelCubes()' if skip_control_cubes else 'Cubes'
)

response = self._rest.GET(url, **kwargs)
Expand All @@ -176,8 +176,8 @@ def get_all_names_with_rules(self, skip_control_cubes: bool = False, **kwargs) -
:return: List of Strings
"""
url = format_url(
"/api/v1/{}?$select=Name,Rules&$filter=Rules ne null",
'ModelCubes()' if skip_control_cubes else 'Cubes'
"/api/v1/{}?$select=Name,Rules&$filter=Rules ne null",
'ModelCubes()' if skip_control_cubes else 'Cubes'
)

response = self._rest.GET(url, **kwargs)
Expand All @@ -191,8 +191,8 @@ def get_all_names_without_rules(self, skip_control_cubes: bool = False, **kwargs
"""

url = format_url(
"/api/v1/{}?$select=Name,Rules&$filter=Rules eq null",
'ModelCubes()' if skip_control_cubes else 'Cubes'
"/api/v1/{}?$select=Name,Rules&$filter=Rules eq null",
'ModelCubes()' if skip_control_cubes else 'Cubes'
)

response = self._rest.GET(url, **kwargs)
Expand Down Expand Up @@ -248,7 +248,7 @@ def search_for_dimension_substring(self, substring: str, skip_control_cubes: boo
response = self._rest.GET(url, **kwargs)
cube_dict = {entry['Name']: [dim['Name'] for dim in entry['Dimensions']] for entry in response.json()['value']}
return cube_dict

def search_for_rule_substring(self, substring: str, skip_control_cubes: bool = False, case_insensitive=True,
space_insensitive=True, **kwargs) -> List[Cube]:
""" get all cubes from TM1 Server as TM1py.Cube instances where rules for given cube contain specified substring
Expand Down Expand Up @@ -276,7 +276,7 @@ def search_for_rule_substring(self, substring: str, skip_control_cubes: bool = F

response = self._rest.GET(url, **kwargs)
cubes = [Cube.from_dict(cube_as_dict=cube) for cube in response.json()['value']]
return cubes
return cubes

@require_version(version="11.4")
def get_storage_dimension_order(self, cube_name: str, **kwargs) -> List[str]:
Expand Down
2 changes: 1 addition & 1 deletion TM1py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@
from TM1py.Services.ViewService import ViewService
from TM1py.Utils import Utils

__version__ = "1.10.2"
__version__ = "1.11"
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@

# General information about the project.
project = 'TM1py'
copyright = '2022, Cubewise CODE'
copyright = '2023, Cubewise CODE'
author = 'Marius Wirtz'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '1.10.2'
version = '1.11'
# The full version, including alpha/beta/rc tags.
release = '1.10.2'
release = '1.11'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TM1py>=1.10.1
pandas>=1.2.2
mdxpy>=0.4
mdxpy>=1.3
python-dateutil>=2.8.1
requests>=2.25.1
urllib3>=1.26.3
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
'requests',
'pytz',
'requests_negotiate_sspi;platform_system=="Windows"',
'mdxpy>=0.4'],
'mdxpy>=1.3'],
extras_require={
"pandas": ["pandas"]
},
Expand Down

0 comments on commit f9d374b

Please sign in to comment.