dara-core 1.12.1__py3-none-any.whl → 1.12.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,10 +17,12 @@ limitations under the License.
17
17
 
18
18
  from __future__ import annotations
19
19
 
20
+ import asyncio
20
21
  from typing import Any, Callable, Coroutine, List, Optional, Union, cast
21
22
  from uuid import uuid4
22
23
 
23
24
  from pandas import DataFrame
25
+ from pandas.io.json._table_schema import build_table_schema
24
26
 
25
27
  from dara.core.base_definitions import (
26
28
  BaseTask,
@@ -48,7 +50,7 @@ from dara.core.interactivity.filtering import (
48
50
  )
49
51
  from dara.core.internal.cache_store import CacheStore
50
52
  from dara.core.internal.hashing import hash_object
51
- from dara.core.internal.pandas_utils import append_index
53
+ from dara.core.internal.pandas_utils import append_index, df_convert_to_internal
52
54
  from dara.core.internal.tasks import MetaTask, Task, TaskManager
53
55
  from dara.core.logging import eng_logger
54
56
 
@@ -135,6 +137,15 @@ class DerivedDataVariable(AnyDataVariable, DerivedVariable):
135
137
  ),
136
138
  )
137
139
 
140
+ @staticmethod
141
+ def _get_schema_cache_key(cache_key: str) -> str:
142
+ """
143
+ Get a unique cache key for the data variable's schema.
144
+
145
+ :param cache_key: cache_key of the DerivedDataVariable
146
+ """
147
+ return f'schema-{cache_key}'
148
+
138
149
  @staticmethod
139
150
  async def _filter_data(
140
151
  data: Union[DataFrame, Any, None],
@@ -164,7 +175,19 @@ class DerivedDataVariable(AnyDataVariable, DerivedVariable):
164
175
  filtered_data, count = apply_filters(data, coerce_to_filter_query(filters), pagination)
165
176
 
166
177
  # Cache the count
167
- await store.set(var_entry, key=count_cache_key, value=count, pin=True)
178
+ await asyncio.gather(
179
+ store.set(var_entry, key=count_cache_key, value=count, pin=True),
180
+ store.set(
181
+ registry_entry=var_entry,
182
+ key=DerivedDataVariable._get_schema_cache_key(
183
+ count_cache_key.split('_')[0] # remove the filter part from the key
184
+ ),
185
+ value=build_table_schema(df_convert_to_internal(cast(DataFrame, filtered_data)))
186
+ if isinstance(filtered_data, DataFrame)
187
+ else None,
188
+ pin=True,
189
+ ),
190
+ )
168
191
 
169
192
  return filtered_data
170
193
 
@@ -194,7 +217,19 @@ class DerivedDataVariable(AnyDataVariable, DerivedVariable):
194
217
  value = await super().get_value(var_entry, store, task_mgr, args, force)
195
218
 
196
219
  # Pin the value in the store until it's read by get data
197
- await store.set(registry_entry=var_entry, key=value['cache_key'], value=value['value'], pin=True)
220
+ await asyncio.gather(
221
+ store.set(registry_entry=var_entry, key=value['cache_key'], value=value['value'], pin=True),
222
+ store.set(
223
+ registry_entry=var_entry,
224
+ key=cls._get_schema_cache_key(value['cache_key']),
225
+ value=build_table_schema(
226
+ df_convert_to_internal(cast(DataFrame, value['value'])),
227
+ )
228
+ if isinstance(value['value'], DataFrame)
229
+ else None,
230
+ pin=True,
231
+ ),
232
+ )
198
233
 
199
234
  eng_logger.info(
200
235
  f'Derived Data Variable {_uid_short} received result from superclass',
@@ -298,7 +333,7 @@ class DerivedDataVariable(AnyDataVariable, DerivedVariable):
298
333
  """
299
334
  Get the schema of the derived data variable.
300
335
  """
301
- return cast(DataFrameSchema, await store.get(data_entry, key=cache_key, unpin=True))
336
+ return cast(DataFrameSchema, await store.get(data_entry, key=cls._get_schema_cache_key(cache_key), unpin=True))
302
337
 
303
338
  @classmethod
304
339
  async def resolve_value(
@@ -17,6 +17,7 @@ limitations under the License.
17
17
 
18
18
  from __future__ import annotations
19
19
 
20
+ import re
20
21
  from datetime import datetime, timezone
21
22
  from enum import Enum
22
23
  from typing import Any, List, Optional, Tuple, Union
@@ -27,6 +28,8 @@ from pydantic import BaseModel
27
28
 
28
29
  from dara.core.logging import dev_logger
29
30
 
31
+ COLUMN_PREFIX_REGEX = re.compile(r'__(?:col|index)__\d+__')
32
+
30
33
 
31
34
  class Pagination(BaseModel):
32
35
  """
@@ -207,10 +210,10 @@ def _filter_to_series(data: DataFrame, column: str, operator: QueryOperator, val
207
210
 
208
211
  def _resolve_filter_query(data: DataFrame, query: FilterQuery) -> 'Optional[Series[bool]]':
209
212
  """
210
- Resolve a FilterQuery to a Series[bool] for filtering
213
+ Resolve a FilterQuery to a Series[bool] for filtering. Strips the internal column index from the query.
211
214
  """
212
215
  if isinstance(query, ValueQuery):
213
- return _filter_to_series(data, query.column, query.operator, query.value)
216
+ return _filter_to_series(data, re.sub(COLUMN_PREFIX_REGEX, '', query.column, 1), query.operator, query.value)
214
217
  elif isinstance(query, ClauseQuery):
215
218
  filters = None
216
219
 
@@ -271,7 +274,9 @@ def apply_filters(
271
274
  order_by = order_by[1:]
272
275
  ascending = False
273
276
 
274
- new_data = new_data.sort_values(by=order_by, ascending=ascending, inplace=False)
277
+ new_data = new_data.sort_values(
278
+ by=re.sub(COLUMN_PREFIX_REGEX, '', order_by), ascending=ascending, inplace=False
279
+ )
275
280
 
276
281
  # PAGINATE
277
282
  start_index = pagination.offset if pagination.offset is not None else 0
@@ -386,11 +386,8 @@ def create_router(config: Configuration):
386
386
  except ValueError as e:
387
387
  raise HTTPException(status_code=400, detail=str(e))
388
388
 
389
- class DataVariableSchemaRequestBody(BaseModel):
390
- cache_key: Optional[str]
391
-
392
389
  @core_api_router.get('/data-variable/{uid}/schema', dependencies=[Depends(verify_session)])
393
- async def get_data_variable_schema(uid: str, body: Optional[DataVariableSchemaRequestBody] = None):
390
+ async def get_data_variable_schema(uid: str, cache_key: Optional[str] = None):
394
391
  try:
395
392
  store: CacheStore = utils_registry.get('Store')
396
393
  registry_mgr: RegistryLookup = utils_registry.get('RegistryLookup')
@@ -399,12 +396,12 @@ def create_router(config: Configuration):
399
396
  if variable_def.type == 'plain':
400
397
  return await variable_def.get_schema(variable_def, store)
401
398
 
402
- if body is None or body.cache_key is None:
399
+ if cache_key is None:
403
400
  raise HTTPException(
404
- status_code=400, detail="Cache key is required when requesting DerivedDataVariable's schema"
401
+ status_code=400, detail='Cache key is required when requesting DerivedDataVariable schema'
405
402
  )
406
403
 
407
- data = await variable_def.get_schema(variable_def, store, body.cache_key)
404
+ data = await variable_def.get_schema(variable_def, store, cache_key)
408
405
  content = json.dumps(jsonable_encoder(data)) if isinstance(data, dict) else data
409
406
  return Response(content=content, media_type='application/json')
410
407
  except ValueError as e:
@@ -57520,9 +57520,10 @@ You must set sticky: 'left' | 'right' for the '${bugWithUnderColumnsSticky.Heade
57520
57520
  return response.json();
57521
57521
  }
57522
57522
  async function fetchDataVariableSchema(uid2, extras, cacheKey) {
57523
+ const queryString = cacheKey ? new URLSearchParams({ cache_key: cacheKey }).toString() : "";
57523
57524
  const response = await request(
57524
- `/api/core/data-variable/${uid2}/schema`,
57525
- { body: JSON.stringify({ cache_key: cacheKey }), method: HTTP_METHOD.GET },
57525
+ `/api/core/data-variable/${uid2}/schema?${queryString}`,
57526
+ { method: HTTP_METHOD.GET },
57526
57527
  extras
57527
57528
  );
57528
57529
  await handleAuthErrors(response, true);
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dara-core
3
- Version: 1.12.1
3
+ Version: 1.12.3
4
4
  Summary: Dara Framework Core
5
5
  Home-page: https://dara.causalens.com/
6
6
  License: Apache-2.0
@@ -20,10 +20,10 @@ Requires-Dist: async-asgi-testclient (>=1.4.11,<2.0.0)
20
20
  Requires-Dist: certifi (>=2024.7.4)
21
21
  Requires-Dist: click (==8.1.3)
22
22
  Requires-Dist: colorama (>=0.4.6,<0.5.0)
23
- Requires-Dist: create-dara-app (==1.12.1)
23
+ Requires-Dist: create-dara-app (==1.12.3)
24
24
  Requires-Dist: croniter (>=1.0.15,<2.0.0)
25
25
  Requires-Dist: cryptography (>=42.0.4)
26
- Requires-Dist: dara-components (==1.12.1) ; extra == "all"
26
+ Requires-Dist: dara-components (==1.12.3) ; extra == "all"
27
27
  Requires-Dist: exceptiongroup (>=1.1.3,<2.0.0)
28
28
  Requires-Dist: fastapi (==0.109.0)
29
29
  Requires-Dist: fastapi-vite (==0.3.1)
@@ -51,7 +51,7 @@ Description-Content-Type: text/markdown
51
51
 
52
52
  # Dara Application Framework
53
53
 
54
- <img src="https://github.com/causalens/dara/blob/v1.12.1/img/dara_light.svg?raw=true">
54
+ <img src="https://github.com/causalens/dara/blob/v1.12.3/img/dara_light.svg?raw=true">
55
55
 
56
56
  ![Master tests](https://github.com/causalens/dara/actions/workflows/tests.yml/badge.svg?branch=master)
57
57
  [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
@@ -96,7 +96,7 @@ source .venv/bin/activate
96
96
  dara start
97
97
  ```
98
98
 
99
- ![Dara App](https://github.com/causalens/dara/blob/v1.12.1/img/components_gallery.png?raw=true)
99
+ ![Dara App](https://github.com/causalens/dara/blob/v1.12.3/img/components_gallery.png?raw=true)
100
100
 
101
101
  Note: `pip` installation uses [PEP 660](https://peps.python.org/pep-0660/) `pyproject.toml`-based editable installs which require `pip >= 21.3` and `setuptools >= 64.0.0`. You can upgrade both with:
102
102
 
@@ -113,9 +113,9 @@ Explore some of our favorite apps - a great way of getting started and getting t
113
113
 
114
114
  | Dara App | Description |
115
115
  | -------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
116
- | ![Large Language Model](https://github.com/causalens/dara/blob/v1.12.1/img/llm.png?raw=true) | Demonstrates how to use incorporate a LLM chat box into your decision app to understand model insights |
117
- | ![Plot Interactivity](https://github.com/causalens/dara/blob/v1.12.1/img/plot_interactivity.png?raw=true) | Demonstrates how to enable the user to interact with plots, trigger actions based on clicks, mouse movements and other interactions with `Bokeh` or `Plotly` plots |
118
- | ![Graph Editor](https://github.com/causalens/dara/blob/v1.12.1/img/graph_viewer.png?raw=true) | Demonstrates how to use the `CausalGraphViewer` component to display your graphs or networks, customising the displayed information through colors and tooltips, and updating the page based on user interaction. |
116
+ | ![Large Language Model](https://github.com/causalens/dara/blob/v1.12.3/img/llm.png?raw=true) | Demonstrates how to use incorporate a LLM chat box into your decision app to understand model insights |
117
+ | ![Plot Interactivity](https://github.com/causalens/dara/blob/v1.12.3/img/plot_interactivity.png?raw=true) | Demonstrates how to enable the user to interact with plots, trigger actions based on clicks, mouse movements and other interactions with `Bokeh` or `Plotly` plots |
118
+ | ![Graph Editor](https://github.com/causalens/dara/blob/v1.12.3/img/graph_viewer.png?raw=true) | Demonstrates how to use the `CausalGraphViewer` component to display your graphs or networks, customising the displayed information through colors and tooltips, and updating the page based on user interaction. |
119
119
 
120
120
  Check out our [App Gallery](https://dara.causalens.com/gallery) for more inspiration!
121
121
 
@@ -127,9 +127,9 @@ This repository covers the Dara Application Framework first-party packages.
127
127
  - `dara-components`: Components for the Dara Framework.
128
128
  - `create-dara-app`: A CLI tool for creating new Dara applications.
129
129
 
130
- More information on the repository structure can be found in the [CONTRIBUTING.md](https://github.com/causalens/dara/blob/v1.12.1/CONTRIBUTING.md) file.
130
+ More information on the repository structure can be found in the [CONTRIBUTING.md](https://github.com/causalens/dara/blob/v1.12.3/CONTRIBUTING.md) file.
131
131
 
132
132
  ## License
133
133
 
134
- Dara is open-source and licensed under the [Apache 2.0 License](https://github.com/causalens/dara/blob/v1.12.1/LICENSE).
134
+ Dara is open-source and licensed under the [Apache 2.0 License](https://github.com/causalens/dara/blob/v1.12.3/LICENSE).
135
135
 
@@ -20,9 +20,9 @@ dara/core/interactivity/any_data_variable.py,sha256=npgtgAIEKNix8VGYLFCc1G3jwXr1
20
20
  dara/core/interactivity/any_variable.py,sha256=HuQTcCw1ysqYcJ5T9Jl--nV_1XzDWMfGw26g6eaQM2k,13281
21
21
  dara/core/interactivity/condition.py,sha256=ynK53cGuVMC852X6kkbrgltcdpIX7Otw7j1DEXEO4Q8,1424
22
22
  dara/core/interactivity/data_variable.py,sha256=KIN2V2ipESfhczBtmyPnZUi0iirlZXdN1S1P0aPPVRA,11099
23
- dara/core/interactivity/derived_data_variable.py,sha256=5TqUdKQD4ncv7MTJuRFcyjWuQnF_TCjK85DCwx6eiUM,13860
23
+ dara/core/interactivity/derived_data_variable.py,sha256=Y3Yw5gdnjvVIUrZhyHafCEaQZMyVT9S5SJ7sC8lcYxA,15176
24
24
  dara/core/interactivity/derived_variable.py,sha256=6xOv-E5wQj-fd9S2RVmRdE_DfkvxVGyptfZlDSj0fmY,21497
25
- dara/core/interactivity/filtering.py,sha256=F80lkbI6_9wfEiV6jRDA7p4RWIFPwFqOQ6bf8JerfaI,8815
25
+ dara/core/interactivity/filtering.py,sha256=RniL8Qq9HIzY0D3p6ZXFQD363ksqZ6b7uCxtklUILyo,9035
26
26
  dara/core/interactivity/non_data_variable.py,sha256=ewPaNaTpMixR5YCVY1pjmyHgeC53K0CsjQxMusbJsiw,1147
27
27
  dara/core/interactivity/plain_variable.py,sha256=iuISw0x14ruOnZqrRg1Zay6ny7Ey0QImRUHVg0S11e0,8017
28
28
  dara/core/interactivity/url_variable.py,sha256=DEHEvg1mE7xXlK69p1D5iZZbf4emzNe6r_RH6DHcyoc,4219
@@ -54,7 +54,7 @@ dara/core/internal/port_utils.py,sha256=AQOUNiFNBYKVUwQ7i9UlY1NQ3sWb5xh5GkO6P1Bm
54
54
  dara/core/internal/registries.py,sha256=9WDczIsNeSmzi6aViIq_b14lmmYGGkdsUGHpv0Sg9zo,3278
55
55
  dara/core/internal/registry.py,sha256=ONCDusqaL0q59Py_r8-fFVN3vbkkDf5TXzNvbB9SrGQ,4305
56
56
  dara/core/internal/registry_lookup.py,sha256=bUtb3lJYYM9NdHUtSWhizKkmTfM3STkoD6t1H3igvnc,2063
57
- dara/core/internal/routing.py,sha256=balTwv1aq_vLasKFuIs5Vhw14NRg-iLAQUusflmPazg,22665
57
+ dara/core/internal/routing.py,sha256=mdFOz8Q7g0IWUAl-qR5cHzK9qXn8QbNHhTuKVrxTp7E,22530
58
58
  dara/core/internal/scheduler.py,sha256=z6OYwazBf3GYo8CzMC9IuGC2P96gI7JwxquT8GaoTMk,12944
59
59
  dara/core/internal/settings.py,sha256=wAWxl-HXjq7PW3twe_CrR-UuMRw9VBudC3eRmevZAhM,3869
60
60
  dara/core/internal/store.py,sha256=qVyU7JfC3zE2vYC2mfjmvECWMlFS9b-nMF1k-alg4Y8,7756
@@ -81,7 +81,7 @@ dara/core/metrics/cache.py,sha256=ybofUhZO0TCHeyhB_AtldWk1QTmTKh7GucTXpOkeTFA,25
81
81
  dara/core/metrics/runtime.py,sha256=YP-6Dz0GeI9_Yr7bUk_-OqShyFySGH_AKpDO126l6es,1833
82
82
  dara/core/metrics/utils.py,sha256=rYlBinxFc7VehFT5cTNXLk8gC74UEj7ZGq6vLgIDpSg,2247
83
83
  dara/core/persistence.py,sha256=TO94rPAN7jxZKVCC5YA4eE7GGDoNlCPe-BkkItV2VUE,10379
84
- dara/core/umd/dara.core.umd.js,sha256=r50GaubVbv_sIpixLI6lPHhgrhp97ZvJjZk6A-Pz3vU,4875647
84
+ dara/core/umd/dara.core.umd.js,sha256=2AENw8gbOqzcrJb4t6wRkhib7sSHN4E4EpUxbbsPQ0g,4875712
85
85
  dara/core/umd/style.css,sha256=YQtQ4veiSktnyONl0CU1iU1kKfcQhreH4iASi1MP7Ak,4095007
86
86
  dara/core/visual/__init__.py,sha256=QN0wbG9HPQ_vXh8BO8DnBXeYLIENVTNtRmYzZf1lx7c,577
87
87
  dara/core/visual/components/__init__.py,sha256=O-Em_glGdZNO0LLl2RWmJSrQiXKxliXg_PuhVXGT81I,1811
@@ -105,8 +105,8 @@ dara/core/visual/themes/__init__.py,sha256=aM4mgoIYo2neBSw5FRzswsht7PUKjLthiHLmF
105
105
  dara/core/visual/themes/dark.py,sha256=UQGDooOc8ric73eHs9E0ltYP4UCrwqQ3QxqN_fb4PwY,1942
106
106
  dara/core/visual/themes/definitions.py,sha256=m3oN0txs65MZepqjj7AKMMxybf2aq5fTjcTwJmHqEbk,2744
107
107
  dara/core/visual/themes/light.py,sha256=-Tviq8oEwGbdFULoDOqPuHO0UpAZGsBy8qFi0kAGolQ,1944
108
- dara_core-1.12.1.dist-info/LICENSE,sha256=r9u1w2RvpLMV6YjuXHIKXRBKzia3fx_roPwboGcLqCc,10944
109
- dara_core-1.12.1.dist-info/METADATA,sha256=Rt7HMrbFkk3_AeTRYv9NRkNmCIn4O5b_-gBT2JRa_AM,6771
110
- dara_core-1.12.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
111
- dara_core-1.12.1.dist-info/entry_points.txt,sha256=H__D5sNIGuPIhVam0DChNL-To5k8Y7nY7TAFz9Mz6cc,139
112
- dara_core-1.12.1.dist-info/RECORD,,
108
+ dara_core-1.12.3.dist-info/LICENSE,sha256=r9u1w2RvpLMV6YjuXHIKXRBKzia3fx_roPwboGcLqCc,10944
109
+ dara_core-1.12.3.dist-info/METADATA,sha256=9atEUgmSrN6Ayv3CsSadWdZt9ryz1VL0Ss_bfoAFEhk,6771
110
+ dara_core-1.12.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
111
+ dara_core-1.12.3.dist-info/entry_points.txt,sha256=H__D5sNIGuPIhVam0DChNL-To5k8Y7nY7TAFz9Mz6cc,139
112
+ dara_core-1.12.3.dist-info/RECORD,,