dara-core 1.12.7__py3-none-any.whl → 1.13.1__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.
@@ -182,6 +182,7 @@ class DataVariable(AnyDataVariable):
182
182
  store: CacheStore,
183
183
  filters: Optional[Union[FilterQuery, dict]] = None,
184
184
  pagination: Optional[Pagination] = None,
185
+ format_for_display: bool = False,
185
186
  ) -> Optional[DataFrame]:
186
187
  """
187
188
  Get the value of this DataVariable.
@@ -212,6 +213,12 @@ class DataVariable(AnyDataVariable):
212
213
 
213
214
  if entry.data is not None:
214
215
  filtered_data, count = apply_filters(entry.data, coerce_to_filter_query(filters), pagination)
216
+ if format_for_display and filtered_data is not None:
217
+ filtered_data = filtered_data.copy()
218
+ for col in filtered_data.columns:
219
+ if filtered_data[col].dtype == 'object':
220
+ # We need to convert all values to string to avoid issues with displaying data in the Table component, for example when displaying datetime and number objects in the same column
221
+ filtered_data.loc[:, col] = filtered_data[col].apply(str)
215
222
  data = filtered_data
216
223
  # Store count for given filters and schema
217
224
  await asyncio.gather(
@@ -175,19 +175,7 @@ class DerivedDataVariable(AnyDataVariable, DerivedVariable):
175
175
  filtered_data, count = apply_filters(data, coerce_to_filter_query(filters), pagination)
176
176
 
177
177
  # Cache the count
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
- )
178
+ await store.set(var_entry, key=count_cache_key, value=count, pin=True)
191
179
 
192
180
  return filtered_data
193
181
 
@@ -251,6 +239,7 @@ class DerivedDataVariable(AnyDataVariable, DerivedVariable):
251
239
  store: CacheStore,
252
240
  filters: Optional[Union[FilterQuery, dict]] = None,
253
241
  pagination: Optional[Pagination] = None,
242
+ format_for_display: bool = False,
254
243
  ) -> Union[BaseTask, DataFrame, None]:
255
244
  """
256
245
  Get the filtered data from the underlying derived variable stored under the specified cache_key.
@@ -309,6 +298,12 @@ class DerivedDataVariable(AnyDataVariable, DerivedVariable):
309
298
 
310
299
  # Run the filtering
311
300
  data = await cls._filter_data(data, count_cache_key, data_entry, store, filters, pagination)
301
+ if format_for_display and data is not None:
302
+ data = data.copy()
303
+ for col in data.columns:
304
+ if data[col].dtype == 'object':
305
+ # We need to convert all values to string to avoid issues with displaying data in the Table component, for example when displaying datetime and number objects in the same column
306
+ data.loc[:, col] = data[col].apply(str)
312
307
 
313
308
  return data
314
309
 
@@ -329,11 +324,13 @@ class DerivedDataVariable(AnyDataVariable, DerivedVariable):
329
324
  return entry
330
325
 
331
326
  @classmethod
332
- async def get_schema(cls, data_entry: DataVariableRegistryEntry, store: CacheStore, cache_key: str):
327
+ async def get_schema(cls, derived_entry: DerivedVariableRegistryEntry, store: CacheStore, cache_key: str):
333
328
  """
334
329
  Get the schema of the derived data variable.
335
330
  """
336
- return cast(DataFrameSchema, await store.get(data_entry, key=cls._get_schema_cache_key(cache_key), unpin=True))
331
+ return cast(
332
+ DataFrameSchema, await store.get(derived_entry, key=cls._get_schema_cache_key(cache_key), unpin=True)
333
+ )
337
334
 
338
335
  @classmethod
339
336
  async def resolve_value(
@@ -332,6 +332,7 @@ def create_router(config: Configuration):
332
332
  store,
333
333
  body.filters,
334
334
  Pagination(offset=offset, limit=limit, orderBy=order_by, index=index),
335
+ format_for_display=True,
335
336
  )
336
337
  if isinstance(data, BaseTask):
337
338
  await task_mgr.run_task(data, body.ws_channel)
@@ -342,6 +343,7 @@ def create_router(config: Configuration):
342
343
  store,
343
344
  body.filters,
344
345
  Pagination(offset=offset, limit=limit, orderBy=order_by, index=index),
346
+ format_for_display=True,
345
347
  )
346
348
 
347
349
  dev_logger.debug(
@@ -391,17 +393,19 @@ def create_router(config: Configuration):
391
393
  try:
392
394
  store: CacheStore = utils_registry.get('Store')
393
395
  registry_mgr: RegistryLookup = utils_registry.get('RegistryLookup')
394
- variable_def = await registry_mgr.get(data_variable_registry, uid)
396
+ data_def = await registry_mgr.get(data_variable_registry, uid)
395
397
 
396
- if variable_def.type == 'plain':
397
- return await variable_def.get_schema(variable_def, store)
398
+ if data_def.type == 'plain':
399
+ return await data_def.get_schema(data_def, store)
398
400
 
399
401
  if cache_key is None:
400
402
  raise HTTPException(
401
403
  status_code=400, detail='Cache key is required when requesting DerivedDataVariable schema'
402
404
  )
403
405
 
404
- data = await variable_def.get_schema(variable_def, store, cache_key)
406
+ # Use the other registry for derived variables
407
+ derived_ref = await registry_mgr.get(derived_variable_registry, uid)
408
+ data = await data_def.get_schema(derived_ref, store, cache_key)
405
409
  content = json.dumps(jsonable_encoder(data)) if isinstance(data, dict) else data
406
410
  return Response(content=content, media_type='application/json')
407
411
  except ValueError as e:
@@ -6,7 +6,7 @@ export default defineConfig({
6
6
  plugins: [
7
7
  react({
8
8
  jsxRuntime: 'classic',
9
- }),
9
+ })
10
10
  ],
11
11
  publicDir: false,
12
12
  build: {
@@ -25,4 +25,7 @@ export default defineConfig({
25
25
  strict: false,
26
26
  },
27
27
  },
28
+ worker: {
29
+ format: 'es',
30
+ }
28
31
  });