Skip to content

Commit de65b5e

Browse files
Merge pull request #1075 from gooddata/snapshot-master-70c7c408-to-rel/dev
[bot] Merge master/70c7c408 into rel/dev
2 parents d37c39b + 70c7c40 commit de65b5e

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

gooddata-pandas/gooddata_pandas/data_access.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
class ExecutionDefinitionBuilder:
3434
_DEFAULT_INDEX_NAME: str = "0"
3535

36-
def __init__(self, columns: ColumnsDef, index_by: Optional[IndexDef] = None) -> None:
36+
def __init__(self, columns: ColumnsDef, index_by: Optional[IndexDef] = None, is_cancellable: bool = False) -> None:
3737
"""
3838
Initializes the ExecutionDefinitionBuilder instance with columns and an
3939
optional index_by definition. Processes the given columns and index_by
@@ -42,13 +42,16 @@ def __init__(self, columns: ColumnsDef, index_by: Optional[IndexDef] = None) ->
4242
Args:
4343
columns (ColumnsDef): Input columns to process and build internal mappings.
4444
index_by (Optional[IndexDef], optional): Index definition to process. Defaults to None.
45+
is_cancellable (Optional[bool]): Whether the execution of this definition should be cancelled when
46+
the connection is interrupted.
4547
4648
"""
4749
self._attributes: list[Attribute] = []
4850
self._metrics: list[Metric] = []
4951
self._col_to_attr_idx: dict[str, int] = dict()
5052
self._index_to_attr_idx: dict[str, int] = dict()
5153
self._col_to_metric_idx: dict[str, int] = dict()
54+
self._is_cancellable = is_cancellable
5255

5356
self._process_columns(columns)
5457
self._process_index(index_by)
@@ -248,6 +251,7 @@ def build_execution_definition(
248251
metrics=self._metrics,
249252
filters=filters,
250253
dimensions=dimensions,
254+
is_cancellable=self._is_cancellable,
251255
)
252256

253257

@@ -257,6 +261,7 @@ def _compute(
257261
columns: ColumnsDef,
258262
index_by: Optional[IndexDef] = None,
259263
filter_by: Optional[Union[Filter, list[Filter]]] = None,
264+
is_cancellable: bool = False,
260265
) -> tuple[Execution, dict[str, int], dict[str, int], dict[str, int]]:
261266
"""
262267
Internal function that computes an execution-by-convention to retrieve data for a data frame with the provided
@@ -268,6 +273,8 @@ def _compute(
268273
columns (ColumnsDef): The columns definition.
269274
index_by (Optional[IndexDef]): The index definition, if any.
270275
filter_by (Optional[Union[Filter, list[Filter]]]): A filter or a list of filters, if any.
276+
is_cancellable (bool, optional): Whether the execution of this definition should be cancelled when
277+
the connection is interrupted.
271278
272279
Returns:
273280
tuple: A tuple containing the following elements:
@@ -277,7 +284,7 @@ def _compute(
277284
- dict[str, int]: A mapping of pandas index names to attribute dimension indices.
278285
"""
279286

280-
builder = ExecutionDefinitionBuilder(columns, index_by)
287+
builder = ExecutionDefinitionBuilder(columns, index_by, is_cancellable=is_cancellable)
281288
exec_def = builder.build_execution_definition(filter_by)
282289

283290
return (
@@ -413,6 +420,7 @@ def compute_and_extract(
413420
index_by: Optional[IndexDef] = None,
414421
filter_by: Optional[Union[Filter, list[Filter]]] = None,
415422
on_execution_submitted: Optional[Callable[[Execution], None]] = None,
423+
is_cancellable: bool = False,
416424
) -> tuple[dict, dict]:
417425
"""
418426
Convenience function that computes and extracts data from the execution response.
@@ -425,6 +433,8 @@ def compute_and_extract(
425433
filter_by (Optional[Union[Filter, list[Filter]]]): A filter or a list of filters, if any.
426434
on_execution_submitted (Optional[Callable[[Execution], None]]): Callback to call when the execution was
427435
submitted to the backend.
436+
is_cancellable (bool, optional): Whether the execution of this definition should be cancelled when
437+
the connection is interrupted.
428438
429439
Returns:
430440
tuple: A tuple containing the following dictionaries:
@@ -440,6 +450,7 @@ def compute_and_extract(
440450
index_by=index_by,
441451
columns=columns,
442452
filter_by=filter_by,
453+
is_cancellable=is_cancellable,
443454
)
444455

445456
execution, col_to_attr_idx, col_to_metric_idx, index_to_attr_idx = result

gooddata-pandas/gooddata_pandas/dataframe.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def indexed(
7474
columns: ColumnsDef,
7575
filter_by: Optional[Union[Filter, list[Filter]]] = None,
7676
on_execution_submitted: Optional[Callable[[Execution], None]] = None,
77+
is_cancellable: bool = False,
7778
) -> pandas.DataFrame:
7879
"""
7980
Creates a data frame indexed by values of the label. The data frame columns will be created from either
@@ -88,6 +89,7 @@ def indexed(
8889
Optional filters to apply during computation on the server.
8990
on_execution_submitted (Optional[Callable[[Execution], None]]): Callback to call when the execution was
9091
submitted to the backend.
92+
is_cancellable (bool, optional): Whether the execution should be cancelled when the connection is interrupted.
9193
9294
Returns:
9395
pandas.DataFrame: A DataFrame instance.
@@ -99,6 +101,7 @@ def indexed(
99101
index_by=index_by,
100102
filter_by=filter_by,
101103
on_execution_submitted=on_execution_submitted,
104+
is_cancellable=is_cancellable,
102105
)
103106

104107
_idx = make_pandas_index(index)
@@ -110,6 +113,7 @@ def not_indexed(
110113
columns: ColumnsDef,
111114
filter_by: Optional[Union[Filter, list[Filter]]] = None,
112115
on_execution_submitted: Optional[Callable[[Execution], None]] = None,
116+
is_cancellable: bool = False,
113117
) -> pandas.DataFrame:
114118
"""
115119
Creates a data frame with columns created from metrics and or labels.
@@ -120,6 +124,7 @@ def not_indexed(
120124
computation on the server.
121125
on_execution_submitted (Optional[Callable[[Execution], None]]): Callback to call when the execution was
122126
submitted to the backend.
127+
is_cancellable (bool, optional): Whether the execution should be cancelled when the connection is interrupted.
123128
124129
Returns:
125130
pandas.DataFrame: A DataFrame instance.
@@ -131,6 +136,7 @@ def not_indexed(
131136
columns=columns,
132137
filter_by=filter_by,
133138
on_execution_submitted=on_execution_submitted,
139+
is_cancellable=is_cancellable,
134140
)
135141

136142
return pandas.DataFrame(data=data)
@@ -141,6 +147,7 @@ def for_items(
141147
filter_by: Optional[Union[Filter, list[Filter]]] = None,
142148
auto_index: bool = True,
143149
on_execution_submitted: Optional[Callable[[Execution], None]] = None,
150+
is_cancellable: bool = False,
144151
) -> pandas.DataFrame:
145152
"""
146153
Creates a data frame for named items. This is a convenience method that will create DataFrame with or
@@ -154,6 +161,7 @@ def for_items(
154161
of the items.
155162
on_execution_submitted (Optional[Callable[[Execution], None]]): Callback to call when the execution was
156163
submitted to the backend.
164+
is_cancellable (bool, optional): Whether the execution should be cancelled when the connection is interrupted.
157165
158166
Returns:
159167
pandas.DataFrame: A DataFrame instance.
@@ -183,13 +191,15 @@ def for_items(
183191
columns=resolved_measure_cols,
184192
filter_by=filter_by,
185193
on_execution_submitted=on_execution_submitted,
194+
is_cancellable=is_cancellable,
186195
)
187196

188197
def for_visualization(
189198
self,
190199
visualization_id: str,
191200
auto_index: bool = True,
192201
on_execution_submitted: Optional[Callable[[Execution], None]] = None,
202+
is_cancellable: bool = False,
193203
) -> pandas.DataFrame:
194204
"""
195205
Creates a data frame with columns based on the content of the visualization with the provided identifier.
@@ -200,6 +210,7 @@ def for_visualization(
200210
of the visualization.
201211
on_execution_submitted (Optional[Callable[[Execution], None]]): Callback to call when the execution was
202212
submitted to the backend.
213+
is_cancellable (bool, optional): Whether the execution should be cancelled when the connection is interrupted.
203214
204215
Returns:
205216
pandas.DataFrame: A DataFrame instance.
@@ -215,13 +226,18 @@ def for_visualization(
215226
}
216227

217228
return self.for_items(
218-
columns, filter_by=filter_by, auto_index=auto_index, on_execution_submitted=on_execution_submitted
229+
columns,
230+
filter_by=filter_by,
231+
auto_index=auto_index,
232+
on_execution_submitted=on_execution_submitted,
233+
is_cancellable=is_cancellable,
219234
)
220235

221236
def for_created_visualization(
222237
self,
223238
created_visualizations_response: dict,
224239
on_execution_submitted: Optional[Callable[[Execution], None]] = None,
240+
is_cancellable: bool = False,
225241
) -> tuple[pandas.DataFrame, DataFrameMetadata]:
226242
"""
227243
Creates a data frame using a created visualization.
@@ -230,11 +246,14 @@ def for_created_visualization(
230246
created_visualizations_response (dict): Created visualization response.
231247
on_execution_submitted (Optional[Callable[[Execution], None]]): Callback to call when the execution was
232248
submitted to the backend.
249+
is_cancellable (bool, optional): Whether the execution should be cancelled when the connection is interrupted.
233250
234251
Returns:
235252
pandas.DataFrame: A DataFrame instance.
236253
"""
237-
execution_definition = self._sdk.compute.build_exec_def_from_chat_result(created_visualizations_response)
254+
execution_definition = self._sdk.compute.build_exec_def_from_chat_result(
255+
created_visualizations_response, is_cancellable=is_cancellable
256+
)
238257
return self.for_exec_def(
239258
exec_def=execution_definition,
240259
on_execution_submitted=on_execution_submitted,

gooddata-pandas/gooddata_pandas/series.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def indexed(
2929
data_by: Union[SimpleMetric, str, ObjId, Attribute],
3030
filter_by: Optional[Union[Filter, list[Filter]]] = None,
3131
on_execution_submitted: Optional[Callable[[Execution], None]] = None,
32+
is_cancellable: bool = False,
3233
) -> pandas.Series:
3334
"""Creates pandas Series from data points calculated from a single `data_by`.
3435
@@ -65,6 +66,8 @@ def indexed(
6566
on_execution_submitted (Optional[Callable[[Execution], None]]): Callback to call when the execution was
6667
submitted to the backend.
6768
69+
is_cancellable (bool, optional): Whether the execution should be cancelled when the connection is interrupted.
70+
6871
Returns:
6972
pandas.Series: pandas series instance
7073
"""
@@ -76,6 +79,7 @@ def indexed(
7679
columns={"_series": data_by},
7780
filter_by=filter_by,
7881
on_execution_submitted=on_execution_submitted,
82+
is_cancellable=is_cancellable,
7983
)
8084

8185
_idx = make_pandas_index(index)
@@ -88,6 +92,7 @@ def not_indexed(
8892
granularity: Optional[Union[list[LabelItemDef], IndexDef]] = None,
8993
filter_by: Optional[Union[Filter, list[Filter]]] = None,
9094
on_execution_submitted: Optional[Callable[[Execution], None]] = None,
95+
is_cancellable: bool = False,
9196
) -> pandas.Series:
9297
"""
9398
Creates a pandas.Series from data points calculated from a single `data_by` without constructing an index.
@@ -116,6 +121,7 @@ def not_indexed(
116121
Defaults to None.
117122
on_execution_submitted (Optional[Callable[[Execution], None]]): Callback to call when the execution was
118123
submitted to the backend.
124+
is_cancellable (bool, optional): Whether the execution should be cancelled when the connection is interrupted.
119125
120126
Returns:
121127
pandas.Series: The resulting pandas Series instance.
@@ -133,6 +139,7 @@ def not_indexed(
133139
columns={"_series": data_by},
134140
filter_by=filter_by,
135141
on_execution_submitted=on_execution_submitted,
142+
is_cancellable=is_cancellable,
136143
)
137144

138145
return pandas.Series(data=data["_series"])

gooddata-sdk/gooddata_sdk/compute/service.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,16 @@ def retrieve_result_cache_metadata(self, workspace_id: str, result_id: str) -> R
8989
)
9090
return ResultCacheMetadata(result_cache_metadata=result_cache_metadata)
9191

92-
def build_exec_def_from_chat_result(self, chat_result: ChatResult) -> ExecutionDefinition:
92+
def build_exec_def_from_chat_result(
93+
self, chat_result: ChatResult, is_cancellable: bool = False
94+
) -> ExecutionDefinition:
9395
"""
9496
Build execution definition from chat result.
9597
9698
Args:
9799
chat_result: ChatResult object containing visualization details from AI chat response
100+
is_cancellable (bool, optional): Whether the execution of this definition should be cancelled when
101+
the connection is interrupted.
98102
99103
Returns:
100104
ExecutionDefinition: Execution definition built from chat result visualization
@@ -112,8 +116,13 @@ def build_exec_def_from_chat_result(self, chat_result: ChatResult) -> ExecutionD
112116
TableDimension(item_ids=["measureGroup"]),
113117
]
114118

115-
exec_def = ExecutionDefinition(dimensions=dimensions, metrics=metrics, filters=filters, attributes=attributes)
116-
return exec_def
119+
return ExecutionDefinition(
120+
dimensions=dimensions,
121+
metrics=metrics,
122+
filters=filters,
123+
attributes=attributes,
124+
is_cancellable=is_cancellable,
125+
)
117126

118127
def ai_chat(self, workspace_id: str, question: str) -> ChatResult:
119128
"""

0 commit comments

Comments
 (0)