@@ -306,6 +306,7 @@ def _create_header_mapper(
306
306
dim : int ,
307
307
label_overrides : Optional [LabelOverrides ] = None ,
308
308
use_local_ids_in_headers : bool = False ,
309
+ use_primary_labels_in_attributes : bool = False ,
309
310
) -> Callable [[Any , Optional [int ]], Optional [str ]]:
310
311
"""
311
312
Prepares a header mapper function which translates header structures into appropriate labels used
@@ -317,6 +318,7 @@ def _create_header_mapper(
317
318
label_overrides (Optional[LabelOverrides]): Label overrides. Defaults to None.
318
319
use_local_ids_in_headers (bool): Use local identifiers of header attributes and metrics. Optional.
319
320
Defaults to False.
321
+ use_primary_labels_in_attributes (bool): Use primary labels in attributes. Optional. Defaults to False.
320
322
321
323
Returns:
322
324
Callable[[Any, Optional[int]], Optional[str]]: Mapper function.
@@ -334,7 +336,10 @@ def _mapper(header: Any, header_idx: Optional[int]) -> Optional[str]:
334
336
pass
335
337
elif "attributeHeader" in header :
336
338
if "labelValue" in header ["attributeHeader" ]:
337
- label = header ["attributeHeader" ]["labelValue" ]
339
+ if use_primary_labels_in_attributes :
340
+ label = header ["attributeHeader" ]["primaryLabelValue" ]
341
+ else :
342
+ label = header ["attributeHeader" ]["labelValue" ]
338
343
# explicitly handle '(empty value)' if it's None otherwise it's not recognizable in final MultiIndex
339
344
# backend represents ^^^ by "" (datasource value is "") or None (datasource value is NULL) therefore
340
345
# if both representation are used it's necessary to set label to unique header label (space) to avoid
@@ -376,6 +381,7 @@ def _headers_to_index(
376
381
response : BareExecutionResponse ,
377
382
label_overrides : LabelOverrides ,
378
383
use_local_ids_in_headers : bool = False ,
384
+ use_primary_labels_in_attributes : bool = False ,
379
385
) -> Optional [pandas .Index ]:
380
386
"""Converts headers to a pandas MultiIndex.
381
387
@@ -388,6 +394,8 @@ def _headers_to_index(
388
394
response (BareExecutionResponse): The execution response object with all data.
389
395
label_overrides (LabelOverrides): A dictionary containing label overrides for the headers.
390
396
use_local_ids_in_headers (bool, optional): If True, uses local Ids in headers, otherwise not. Defaults to False.
397
+ use_primary_labels_in_attributes (bool, optional): If True, uses primary labels in attributes, otherwise not.
398
+ Defaults to False.
391
399
392
400
Returns:
393
401
Optional[pandas.Index]: A pandas MultiIndex object created from the headers, or None if the headers are empty.
@@ -400,6 +408,7 @@ def _headers_to_index(
400
408
dim = dim_idx ,
401
409
label_overrides = label_overrides ,
402
410
use_local_ids_in_headers = use_local_ids_in_headers ,
411
+ use_primary_labels_in_attributes = use_primary_labels_in_attributes ,
403
412
)
404
413
405
414
return pandas .MultiIndex .from_arrays (
@@ -467,6 +476,7 @@ def convert_execution_response_to_dataframe(
467
476
result_size_dimensions_limits : ResultSizeDimensions ,
468
477
result_size_bytes_limit : Optional [int ] = None ,
469
478
use_local_ids_in_headers : bool = False ,
479
+ use_primary_labels_in_attributes : bool = False ,
470
480
page_size : int = _DEFAULT_PAGE_SIZE ,
471
481
) -> Tuple [pandas .DataFrame , DataFrameMetadata ]:
472
482
"""
@@ -480,6 +490,8 @@ def convert_execution_response_to_dataframe(
480
490
result_size_dimensions_limits (ResultSizeDimensions): Dimension limits for the dataframe.
481
491
result_size_bytes_limit (Optional[int], default=None): Size limit in bytes for the dataframe.
482
492
use_local_ids_in_headers (bool, default=False): Use local ids in headers if True, else use default settings.
493
+ use_primary_labels_in_attributes (bool, default=False): Use primary labels in attributes if True, else use
494
+ default settings.
483
495
page_size (int, default=_DEFAULT_PAGE_SIZE): Size of the page.
484
496
485
497
Returns:
@@ -503,13 +515,15 @@ def convert_execution_response_to_dataframe(
503
515
response = execution_response ,
504
516
label_overrides = label_overrides ,
505
517
use_local_ids_in_headers = use_local_ids_in_headers ,
518
+ use_primary_labels_in_attributes = use_primary_labels_in_attributes ,
506
519
),
507
520
columns = _headers_to_index (
508
521
dim_idx = 1 ,
509
522
headers = full_headers ,
510
523
response = execution_response ,
511
524
label_overrides = label_overrides ,
512
525
use_local_ids_in_headers = use_local_ids_in_headers ,
526
+ use_primary_labels_in_attributes = use_primary_labels_in_attributes ,
513
527
),
514
528
)
515
529
0 commit comments