Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions TM1py/Services/CellService.py
Original file line number Diff line number Diff line change
Expand Up @@ -2298,6 +2298,7 @@ def extract_cellset_csv(
sandbox_name: str = None,
include_attributes: bool = False,
use_compact_json: bool = False,
include_headers: bool = True,
**kwargs) -> str:
""" Execute cellset and return only the 'Content', in csv format

Expand All @@ -2314,23 +2315,29 @@ def extract_cellset_csv(
:param sandbox_name: str
:param include_attributes: include attribute columns
:param use_compact_json: bool
:param include_headers: bool
:return: Raw format from TM1.
"""
if 'delete_cellset' in kwargs:
delete_cellset = kwargs.pop('delete_cellset')
else:
delete_cellset = True
_, _, rows, columns = self.extract_cellset_composition(cellset_id, delete_cellset=False,
sandbox_name=sandbox_name, **kwargs)
cellset_dict = self.extract_cellset_raw(cellset_id, cell_properties=["Value"], top=top, skip=skip,
skip_contexts=True, skip_zeros=skip_zeros,
skip_consolidated_cells=skip_consolidated_cells,
skip_rule_derived_cells=skip_rule_derived_cells,
delete_cellset=True, sandbox_name=sandbox_name,
delete_cellset=delete_cellset, sandbox_name=sandbox_name,
elem_properties=['Name'],
member_properties=['Name',
'Attributes'] if include_attributes else None,
use_compact_json=use_compact_json,
**kwargs)
return build_csv_from_cellset_dict(rows, columns, cellset_dict, csv_dialect=csv_dialect,
line_separator=line_separator, value_separator=value_separator,
top=top, include_attributes=include_attributes)
top=top, include_attributes=include_attributes,
include_headers=include_headers)

def extract_cellset_csv_iter_json(
self,
Expand Down
9 changes: 6 additions & 3 deletions TM1py/Utils/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ def build_csv_from_cellset_dict(
csv_dialect: 'csv.Dialect' = None,
line_separator: str = "\r\n",
value_separator: str = ",",
include_attributes: bool = False) -> str:
include_attributes: bool = False,
include_headers: bool = True) -> str:
""" transform raw cellset data into concise dictionary
:param column_dimensions:
:param row_dimensions:
Expand All @@ -349,6 +350,7 @@ def build_csv_from_cellset_dict(
:param line_separator:
:param value_separator:
:param include_attributes: include attribute columns
:param include_headers: bool
:return:
"""

Expand All @@ -366,8 +368,9 @@ def build_csv_from_cellset_dict(

column_axis, row_axis, _ = extract_axes_from_cellset(raw_cellset_as_dict=raw_cellset_as_dict)

headers = _build_headers_for_csv(row_axis, column_axis, row_dimensions, column_dimensions, include_attributes)
csv_writer.writerow(headers)
if include_headers:
headers = _build_headers_for_csv(row_axis, column_axis, row_dimensions, column_dimensions, include_attributes)
csv_writer.writerow(headers)

for ordinal, cell in enumerate(cells[:top or len(cells)]):
# if skip is used in execution we must use the original ordinal from the cell, if not we can simply enumerate
Expand Down