evo-objects 0.7.0__tar.gz → 0.9.1__tar.gz

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.
Files changed (49) hide show
  1. {evo_objects-0.7.0 → evo_objects-0.9.1}/PKG-INFO +13 -2
  2. {evo_objects-0.7.0 → evo_objects-0.9.1}/pyproject.toml +2 -2
  3. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/client/api_client.py +57 -4
  4. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/client/object_client.py +4 -2
  5. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/client/parse.py +2 -1
  6. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/endpoints/__init__.py +1 -1
  7. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/endpoints/api/data_api.py +2 -2
  8. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/endpoints/api/metadata_api.py +3 -3
  9. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/endpoints/api/objects_api.py +85 -15
  10. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/endpoints/api/stages_api.py +2 -2
  11. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/endpoints/models.py +102 -12
  12. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/parquet/loader.py +7 -2
  13. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/__init__.py +4 -0
  14. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/block_model_ref.py +8 -3
  15. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/utils/__init__.py +10 -4
  16. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/utils/data.py +24 -31
  17. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/utils/tables.py +108 -7
  18. {evo_objects-0.7.0 → evo_objects-0.9.1}/.gitignore +0 -0
  19. {evo_objects-0.7.0 → evo_objects-0.9.1}/LICENSE.md +0 -0
  20. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/__init__.py +0 -0
  21. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/_model_config.py +0 -0
  22. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/client/__init__.py +0 -0
  23. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/data.py +0 -0
  24. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/endpoints/api/__init__.py +0 -0
  25. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/exceptions.py +0 -0
  26. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/io.py +0 -0
  27. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/parquet/__init__.py +0 -0
  28. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/py.typed +0 -0
  29. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/_data.py +0 -0
  30. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/_downhole.py +0 -0
  31. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/_grid.py +0 -0
  32. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/_model.py +0 -0
  33. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/_prefetch.py +0 -0
  34. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/_utils.py +0 -0
  35. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/attributes.py +0 -0
  36. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/base.py +0 -0
  37. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/downhole_collection.py +0 -0
  38. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/downhole_intervals.py +0 -0
  39. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/exceptions.py +0 -0
  40. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/pointset.py +0 -0
  41. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/regular_grid.py +0 -0
  42. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/regular_masked_grid.py +0 -0
  43. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/spatial.py +0 -0
  44. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/tensor_grid.py +0 -0
  45. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/types.py +0 -0
  46. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/typed/variogram.py +0 -0
  47. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/utils/downhole.py +0 -0
  48. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/utils/table_formats.py +0 -0
  49. {evo_objects-0.7.0 → evo_objects-0.9.1}/src/evo/objects/utils/types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: evo-objects
3
- Version: 0.7.0
3
+ Version: 0.9.1
4
4
  Summary: Python SDK for using the Seequent Evo Geoscience Object API
5
5
  Project-URL: Source, https://github.com/SeequentEvo/evo-python-sdk
6
6
  Project-URL: Tracker, https://github.com/SeequentEvo/evo-python-sdk/issues
@@ -14,7 +14,7 @@ Requires-Dist: pydantic<3,>=2
14
14
  Provides-Extra: aiohttp
15
15
  Requires-Dist: evo-sdk-common[aiohttp]>=0.6.0; extra == 'aiohttp'
16
16
  Provides-Extra: blockmodels
17
- Requires-Dist: evo-blockmodels[utils]>=0.10.0; extra == 'blockmodels'
17
+ Requires-Dist: evo-blockmodels[utils]>=0.11.0; extra == 'blockmodels'
18
18
  Provides-Extra: notebooks
19
19
  Requires-Dist: evo-sdk-common[notebooks]>=0.6.0; extra == 'notebooks'
20
20
  Provides-Extra: utils
@@ -51,6 +51,17 @@ data, empowering our users to build responsive modern workflows.
51
51
  pip install evo-objects
52
52
  ```
53
53
 
54
+ The base installation supports object operations and low-level data transfers without PyArrow.
55
+ `ObjectAPIClient.prepare_data_upload()` and `prepare_data_download()` return contexts for transferring existing Parquet files. You must create or read the files yourself and provide matching table descriptions when creating objects.
56
+
57
+ The optional `ObjectDataClient` provides higher-level operations on PyArrow tables without requiring pandas. Its
58
+ DataFrame methods and other pandas-based helpers additionally require pandas. Install the `utils` extra for these
59
+ dependencies:
60
+
61
+ ```shell
62
+ pip install "evo-objects[utils]"
63
+ ```
64
+
54
65
  ## Usage
55
66
 
56
67
  See [the evo-sdk-common documentation](https://github.com/SeequentEvo/evo-python-sdk/blob/main/packages/evo-sdk-common/README.md)
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "evo-objects"
3
3
  description = "Python SDK for using the Seequent Evo Geoscience Object API"
4
- version = "0.7.0"
4
+ version = "0.9.1"
5
5
  requires-python = ">=3.11.5"
6
6
  license-files = ["LICENSE.md"]
7
7
  dynamic = ["readme"]
@@ -24,7 +24,7 @@ Documentation = "https://developer.seequent.com/"
24
24
  aiohttp = ["evo-sdk-common[aiohttp]>=0.6.0"]
25
25
  notebooks = ["evo-sdk-common[notebooks]>=0.6.0"]
26
26
  utils = ["pyarrow", "pyarrow-stubs", "pandas", "numpy"]
27
- blockmodels = ["evo-blockmodels[utils]>=0.10.0"]
27
+ blockmodels = ["evo-blockmodels[utils]>=0.11.0"]
28
28
 
29
29
  [dependency-groups]
30
30
  # Dev dependencies. The version is left unspecified so the latest is installed.
@@ -21,7 +21,7 @@ from evo.common.utils import get_service_health, parse_order_by
21
21
 
22
22
  from ..data import ObjectMetadata, ObjectOrderByEnum, ObjectReference, ObjectVersion, OrgObjectMetadata, Stage
23
23
  from ..endpoints import MetadataApi, ObjectsApi, StagesApi
24
- from ..endpoints.models import GeoscienceObject, MetadataUpdateBody, UpdateGeoscienceObject
24
+ from ..endpoints.models import GeoscienceObject, MetadataUpdateBody, MoveObjectRequest, UpdateGeoscienceObject
25
25
  from ..exceptions import ObjectUUIDError
26
26
  from ..io import ObjectDataDownload, ObjectDataUpload
27
27
  from . import parse
@@ -190,7 +190,6 @@ class ObjectAPIClient(BaseAPIClient):
190
190
  order_by=parsed_order_by,
191
191
  schema_id=schema_id,
192
192
  request_timeout=request_timeout,
193
- permitted_workspaces_only=True,
194
193
  deleted=deleted,
195
194
  )
196
195
  return parse.page_of_metadata(response, self._environment)
@@ -332,9 +331,13 @@ class ObjectAPIClient(BaseAPIClient):
332
331
  async def move_geoscience_object(
333
332
  self, path: str, object_dict: dict, request_timeout: int | float | tuple[int | float, int | float] | None = None
334
333
  ) -> ObjectMetadata:
335
- """Move an existing geoscience object to a new path in the geoscience object service.
334
+ """Move and/or rename an existing geoscience object by uploading it to a new path.
336
335
 
337
- :param path: The new path to move the object to.
336
+ The path includes the object name, so a path in the same folder with a different name renames the object.
337
+ This uploads the object to the new path, which creates a new version of the object. To move or rename an
338
+ object without creating a new version, use `move_geoscience_object_by_id` instead.
339
+
340
+ :param path: The new path of the object, including its name.
338
341
  :param object_dict: The geoscience object to be moved.
339
342
  :param request_timeout: Timeout setting for this request. If one number is provided, it will be the
340
343
  total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.
@@ -356,6 +359,56 @@ class ObjectAPIClient(BaseAPIClient):
356
359
  )
357
360
  return parse.object_metadata(result, self._environment)
358
361
 
362
+ async def move_geoscience_object_by_id(
363
+ self,
364
+ object_id: UUID,
365
+ name: str | None = None,
366
+ folder_path: str | None = None,
367
+ folder_id: UUID | None = None,
368
+ request_timeout: int | float | tuple[int | float, int | float] | None = None,
369
+ ) -> ObjectMetadata:
370
+ """Move and/or rename an existing geoscience object (by UUID) without creating a new version.
371
+
372
+ Despite the name, this method also renames objects. Arguments that are `None` are left unchanged:
373
+
374
+ - Provide only `name` to rename the object in its current folder.
375
+ - Provide only `folder_path` and/or `folder_id` to move the object while keeping its name.
376
+ - Provide `name` together with a folder to move and rename the object in a single request.
377
+
378
+ If both `folder_path` and `folder_id` are provided, they must refer to the same folder.
379
+
380
+ :param object_id: The UUID of the geoscience object.
381
+ :param name: The new name of the object, including the `.json` extension.
382
+ :param folder_path: The path of the destination folder, starting with `/` and excluding the object name.
383
+ Missing intermediate folders are created.
384
+ :param folder_id: The UUID of an existing destination folder in the same workspace.
385
+ :param request_timeout: Timeout setting for this request. If one number is provided, it will be the
386
+ total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.
387
+
388
+ :return: The metadata of the object. If nothing changed, because no arguments were provided or the destination
389
+ is the object's current location, the current metadata is returned and `modified_at` is unchanged.
390
+
391
+ :raises ObjectAlreadyExistsError: If an object with the same name already exists in the destination folder.
392
+ """
393
+ org_id = str(self._environment.org_id)
394
+ workspace_id = str(self._environment.workspace_id)
395
+ result = await self._objects_api.move_object_by_id(
396
+ object_id=str(object_id),
397
+ org_id=org_id,
398
+ workspace_id=workspace_id,
399
+ move_object_request=MoveObjectRequest(name=name, folder_id=folder_id, folder_path=folder_path),
400
+ request_timeout=request_timeout,
401
+ )
402
+ if isinstance(result, EmptyResponse):
403
+ # The service responds with 204 No Content when nothing changed, so fetch the current metadata.
404
+ result = await self._objects_api.get_object_by_id(
405
+ object_id=str(object_id),
406
+ org_id=org_id,
407
+ workspace_id=workspace_id,
408
+ request_timeout=request_timeout,
409
+ )
410
+ return parse.object_metadata(result, self._environment)
411
+
359
412
  async def update_geoscience_object(
360
413
  self, object_dict: dict, request_timeout: int | float | tuple[int | float, int | float] | None = None
361
414
  ) -> ObjectMetadata:
@@ -40,6 +40,7 @@ try:
40
40
  ParquetLoader,
41
41
  TableInfo,
42
42
  )
43
+ from ..utils.tables import table_to_dataframe
43
44
  except ImportError as e:
44
45
  print(e)
45
46
  _LOADER_AVAILABLE = False
@@ -486,10 +487,11 @@ class DownloadedObject(IContext):
486
487
  nan_description structure.
487
488
  :param column_names: An optional list of column names for the table, instead of those from the Parquet file.
488
489
 
489
- :returns: A Pandas DataFrame containing the downloaded data.
490
+ :returns: A Pandas DataFrame containing the downloaded data. Column dtypes are derived from the
491
+ Geoscience Object column types; integer and boolean columns use pandas nullable dtypes.
490
492
  """
491
493
  table = await self.download_table(table_info, fb=fb, nan_values=nan_values, column_names=column_names)
492
- return table.to_pandas()
494
+ return table_to_dataframe(table)
493
495
 
494
496
  async def download_category_dataframe(
495
497
  self,
@@ -98,7 +98,8 @@ def schema(schema_id: str) -> ObjectSchema:
98
98
 
99
99
 
100
100
  def object_metadata(
101
- model: models.ListedObject | models.GetObjectResponse | models.PostObjectResponse, environment: Environment
101
+ model: models.ListedObject | models.GetObjectResponse | models.PostObjectResponse | models.MoveObjectResponse,
102
+ environment: Environment,
102
103
  ) -> ObjectMetadata:
103
104
  """Parse an ObjectMetadata from the generated model.
104
105
 
@@ -21,7 +21,7 @@ For more information on using the Geoscience Object API, see the [Geoscience Obj
21
21
 
22
22
 
23
23
  This code is generated from the OpenAPI specification for Geoscience Object API.
24
- API version: 1.21.0
24
+ API version: 1.26.0
25
25
  """
26
26
 
27
27
  # Import endpoint apis.
@@ -21,11 +21,11 @@ For more information on using the Geoscience Object API, see the [Geoscience Obj
21
21
 
22
22
 
23
23
  This code is generated from the OpenAPI specification for Geoscience Object API.
24
- API version: 1.21.0
24
+ API version: 1.26.0
25
25
  """
26
26
 
27
27
  from evo.common.connector import APIConnector
28
- from evo.common.data import RequestMethod
28
+ from evo.common.data import EmptyResponse, RequestMethod # noqa: F401
29
29
  from evo.common.utils import get_header_metadata
30
30
 
31
31
  from ..models import * # noqa: F403
@@ -21,7 +21,7 @@ For more information on using the Geoscience Object API, see the [Geoscience Obj
21
21
 
22
22
 
23
23
  This code is generated from the OpenAPI specification for Geoscience Object API.
24
- API version: 1.21.0
24
+ API version: 1.26.0
25
25
  """
26
26
 
27
27
  from evo.common.connector import APIConnector
@@ -61,9 +61,9 @@ class MetadataApi:
61
61
 
62
62
  Update metadata for a geoscience object version. If a version is not specified, the latest version of the object will be used. Setting the metadata property to `null` will remove the metadata from the object version.
63
63
 
64
- :param object_id:
64
+ :param object_id: UUID of a geoscience object.
65
65
  Format: `uuid`
66
- Example: `'object_id_example'`
66
+ Example: `'355fa5a6-f37d-11ed-93c1-00155d19a71b'`
67
67
  :param org_id: The customer's organisation ID
68
68
  Format: `uuid`
69
69
  Example: `'b208a6c9-6881-4b97-b02d-acb5d81299bb'`
@@ -21,7 +21,7 @@ For more information on using the Geoscience Object API, see the [Geoscience Obj
21
21
 
22
22
 
23
23
  This code is generated from the OpenAPI specification for Geoscience Object API.
24
- API version: 1.21.0
24
+ API version: 1.26.0
25
25
  """
26
26
 
27
27
  from evo.common.connector import APIConnector
@@ -125,9 +125,9 @@ class ObjectsApi:
125
125
 
126
126
  Delete a geoscience object by UUID. Deleting an object to this endpoint will soft delete the existing object with a corresponding UUID. Note that the value of the `uuid` field in the object must match the value in the URL path.
127
127
 
128
- :param object_id:
128
+ :param object_id: UUID of a geoscience object.
129
129
  Format: `uuid`
130
- Example: `'object_id_example'`
130
+ Example: `'355fa5a6-f37d-11ed-93c1-00155d19a71b'`
131
131
  :param org_id: The customer's organisation ID
132
132
  Format: `uuid`
133
133
  Example: `'b208a6c9-6881-4b97-b02d-acb5d81299bb'`
@@ -446,9 +446,9 @@ class ObjectsApi:
446
446
 
447
447
  List specific versions of a Geoscience Object. The response will include all the versions specified in `version_ids` field of the request body. If one or more of the version ids are not found for the geoscience object a 404 error will be returned.
448
448
 
449
- :param object_id:
449
+ :param object_id: UUID of a geoscience object.
450
450
  Format: `uuid`
451
- Example: `'object_id_example'`
451
+ Example: `'355fa5a6-f37d-11ed-93c1-00155d19a71b'`
452
452
  :param org_id: The customer's organisation ID
453
453
  Format: `uuid`
454
454
  Example: `'b208a6c9-6881-4b97-b02d-acb5d81299bb'`
@@ -545,7 +545,7 @@ class ObjectsApi:
545
545
  :param deleted: (optional) When true, only objects that have been deleted will be returned
546
546
  Example: `True`
547
547
  :param order_by: (optional) A comma separated list of fields to order by, where the default sort order is ascending. To specify the sort order, prefix the field name with either `asc:` or `desc:` for ascending or descending respectively. Field names can either be arbitrary, representing a field nested inside the data, or one of the following known sort fields: `author`, `created_at`, `created_by`, `deleted_at`, `modified_at`, `modified_by`, `object_name`
548
- Example: `'order_by=name,desc:created_by,asc:object.a.b.c'`
548
+ Example: `'object_name,desc:created_by,asc:object.a.b.c'`
549
549
  :param author: (optional) (deprecated, use `created_by`) The profile ID that you want to filter by
550
550
  Example: `['00000000-0000-0000-0000-000000000000']`
551
551
  :param created_by: (optional) The UUID of the user that created an object
@@ -556,7 +556,7 @@ class ObjectsApi:
556
556
  Example: `['00000000-0000-0000-0000-000000000000']`
557
557
  :param modified_at: (optional) A date or dates (max 2) to filter objects by. Dates may contain operator prefixes, in the form `<operator>:<datetime>`. The following operators are available (`lt`=less than, `lte`=less than or equal to, `gt`=greater than, `gte`=greater than or equal to). If you omit the operator, then it is assumed the operator is 'equal to'. In this case you may only supply one date. The dates must also be in a valid ISO 8601 format. Dates may include a UTC offset. If the offset is omitted, the timezone is assumed to be UTC.
558
558
  Example: `['gte:2023-03-10T22:56:53Z']`
559
- :param object_name: (optional) The name of the object to filter on. For backwards compatibility, when no operators are supplied, this will perform a case sensitive prefix match of the object file name. The query `object_name=gold` will match an object with the name `goldcolumns.json`. Providing an operator will query over the entire path to and including the file name.
559
+ :param object_name: (optional) The name of the object to filter on. For backwards compatibility, when no operators are supplied, this will perform a case sensitive prefix match of the object file name. The query `object_name=gold` will match an object with the name `goldcolumns.json`. Providing an operator will query over the file name.
560
560
  Example: `['object.json']`
561
561
  :param schema_id: (optional) The type of schema you want to filter by.
562
562
  Example: `['/objects/variogram/0.1.0/variogram.schema.json']`
@@ -662,7 +662,6 @@ class ObjectsApi:
662
662
  offset: int | None = None,
663
663
  limit: int | None = None,
664
664
  deleted: bool | None = None,
665
- permitted_workspaces_only: bool | None = None,
666
665
  order_by: str | None = None,
667
666
  created_by: list[str] | None = None,
668
667
  created_at: list[str] | None = None,
@@ -689,10 +688,8 @@ class ObjectsApi:
689
688
  Example: `5000`
690
689
  :param deleted: (optional) When true, only objects that have been deleted will be returned
691
690
  Example: `True`
692
- :param permitted_workspaces_only: (optional) Only return objects in workspaces the user is permitted to access.
693
- Example: `True`
694
691
  :param order_by: (optional) A comma separated list of fields to order by, where the default sort order is ascending. To specify the sort order, prefix the field name with either `asc:` or `desc:` for ascending or descending respectively. Field names can either be arbitrary, representing a field nested inside the data, or one of the following known sort fields: `created_at`, `created_by`, `modified_at`, `modified_by`, `object_name`, `deleted_at`
695
- Example: `'order_by=name,desc:created_by,asc:object.a.b.c'`
692
+ Example: `'object_name,desc:created_by,asc:object.a.b.c'`
696
693
  :param created_by: (optional) The UUID of the user that created an object
697
694
  Example: `['00000000-0000-0000-0000-000000000000']`
698
695
  :param created_at: (optional) A date or dates (max 2) to filter objects by. Dates may contain operator prefixes, in the form `<operator>:<datetime>`. The following operators are available (`lt`=less than, `lte`=less than or equal to, `gt`=greater than, `gte`=greater than or equal to). If you omit the operator, then it is assumed the operator is 'equal to'. In this case you may only supply one date. The dates must also be in a valid ISO 8601 format. Dates may include a UTC offset. If the offset is omitted, the timezone is assumed to be UTC.
@@ -701,7 +698,7 @@ class ObjectsApi:
701
698
  Example: `['00000000-0000-0000-0000-000000000000']`
702
699
  :param modified_at: (optional) A date or dates (max 2) to filter objects by. Dates may contain operator prefixes, in the form `<operator>:<datetime>`. The following operators are available (`lt`=less than, `lte`=less than or equal to, `gt`=greater than, `gte`=greater than or equal to). If you omit the operator, then it is assumed the operator is 'equal to'. In this case you may only supply one date. The dates must also be in a valid ISO 8601 format. Dates may include a UTC offset. If the offset is omitted, the timezone is assumed to be UTC.
703
700
  Example: `['gte:2023-03-10T22:56:53Z']`
704
- :param object_name: (optional) The name of the object to filter on. For backwards compatibility, when no operators are supplied, this will perform a case sensitive prefix match of the object file name. The query `object_name=gold` will match an object with the name `goldcolumns.json`. Providing an operator will query over the entire path to and including the file name.
701
+ :param object_name: (optional) The name of the object to filter on. For backwards compatibility, when no operators are supplied, this will perform a case sensitive prefix match of the object file name. The query `object_name=gold` will match an object with the name `goldcolumns.json`. Providing an operator will query over the file name.
705
702
  Example: `['object.json']`
706
703
  :param schema_id: (optional) The type of schema you want to filter by.
707
704
  Example: `['/objects/variogram/0.1.0/variogram.schema.json']`
@@ -741,8 +738,6 @@ class ObjectsApi:
741
738
  _query_params["limit"] = limit
742
739
  if deleted is not None:
743
740
  _query_params["deleted"] = deleted
744
- if permitted_workspaces_only is not None:
745
- _query_params["permitted_workspaces_only"] = permitted_workspaces_only
746
741
  if order_by is not None:
747
742
  _query_params["order_by"] = order_by
748
743
  if created_by is not None:
@@ -799,6 +794,81 @@ class ObjectsApi:
799
794
  request_timeout=request_timeout,
800
795
  )
801
796
 
797
+ async def move_object_by_id(
798
+ self,
799
+ object_id: str,
800
+ org_id: str,
801
+ workspace_id: str,
802
+ move_object_request: MoveObjectRequest, # noqa: F405
803
+ additional_headers: dict[str, str] | None = None,
804
+ request_timeout: int | float | tuple[int | float, int | float] | None = None,
805
+ ) -> MoveObjectResponse: # noqa: F405
806
+ """Move or rename a geoscience object
807
+
808
+ Move and/or rename an object without creating a new version. Omitted or null fields are unchanged. An empty JSON object or an unchanged destination returns 204 without changing modification metadata. The object must exist and must not be deleted. Provide just `name` to only rename the object. Provide just `folder_path` and/or `folder_id` to only move the object. Providing both `folder_path` and `folder_id` allows for extra validation of the target folder. Providing either or both folder fields and name field allows for simultaneous move and rename. A real change updates modified_at and modified_by and returns the object, without a versions array.
809
+
810
+ :param object_id: UUID of a geoscience object.
811
+ Format: `uuid`
812
+ Example: `'355fa5a6-f37d-11ed-93c1-00155d19a71b'`
813
+ :param org_id: The customer's organisation ID
814
+ Format: `uuid`
815
+ Example: `'b208a6c9-6881-4b97-b02d-acb5d81299bb'`
816
+ :param workspace_id:
817
+ Format: `uuid`
818
+ Example: `'032806a8-dcd7-11ed-8d5c-00155d8f28b5'`
819
+ :param move_object_request:
820
+ Example: `endpoints.MoveObjectRequest()`
821
+ :param additional_headers: (optional) Additional headers to send with the request.
822
+ :param request_timeout: (optional) Timeout setting for this request. If one number is provided, it will be the
823
+ total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.
824
+
825
+ :return: Returns the result object.
826
+
827
+ :raise evo.common.exceptions.BadRequestException: If the server responds with HTTP status 400.
828
+ :raise evo.common.exceptions.UnauthorizedException: If the server responds with HTTP status 401.
829
+ :raise evo.common.exceptions.ForbiddenException: If the server responds with HTTP status 403.
830
+ :raise evo.common.exceptions.NotFoundException: If the server responds with HTTP status 404.
831
+ :raise evo.common.exceptions.BaseTypedError: If the server responds with any other HTTP status between
832
+ 400 and 599, and the body of the response contains a descriptive `type` parameter.
833
+ :raise evo.common.exceptions.EvoAPIException: If the server responds with any other HTTP status between 400
834
+ and 599, and the body of the response does not contain a `type` parameter.
835
+ :raise evo.common.exceptions.UnknownResponseError: For other HTTP status codes with no corresponding response
836
+ type in `response_types_map`.
837
+ """
838
+ # Prepare the path parameters.
839
+ _path_params = {
840
+ "object_id": object_id,
841
+ "org_id": org_id,
842
+ "workspace_id": workspace_id,
843
+ }
844
+
845
+ # Prepare the header parameters.
846
+ _header_params = {
847
+ "Content-Type": "application/json",
848
+ "Accept": "application/json",
849
+ } | get_header_metadata(__name__)
850
+ if additional_headers is not None:
851
+ _header_params.update(additional_headers)
852
+
853
+ # Define the collection formats.
854
+ _collection_formats = {}
855
+
856
+ _response_types_map = {
857
+ "200": MoveObjectResponse, # noqa: F405
858
+ "204": EmptyResponse,
859
+ }
860
+
861
+ return await self.connector.call_api(
862
+ method=RequestMethod.PATCH,
863
+ resource_path="/geoscience-object/orgs/{org_id}/workspaces/{workspace_id}/objects/{object_id}",
864
+ path_params=_path_params,
865
+ header_params=_header_params,
866
+ body=move_object_request,
867
+ collection_formats=_collection_formats,
868
+ response_types_map=_response_types_map,
869
+ request_timeout=request_timeout,
870
+ )
871
+
802
872
  async def post_objects(
803
873
  self,
804
874
  org_id: str,
@@ -811,7 +881,7 @@ class ObjectsApi:
811
881
  ) -> PostObjectResponse: # noqa: F405
812
882
  """Create a geoscience object
813
883
 
814
- Create or update a geoscience object. Upload a geoscience object based on the schema element. Geoscience objects can be stored hierarchically, by providing the path to the object, including the object name, in the request URL. A detailed list of the available object schemas can be found in Seequent's [evo-schemas](https://github.com/seequentevo/evo-schemas) repository. The submitted properties will be validated against the specified schema properties. To create a new object, upload it to a unique path with the UUID field set to `null`. The response will contain a reflection of the uploaded object with a newly assigned object ID. This can be used for future requests to update the object. If a version of the geoscience object already exists at the specified path a new version will be created. To move or rename an existing object, simply upload a new version of it (with the same UUID) to a new, unique path or file name. Note that every upload of an object is considered a new version, even if no changes have been made. If required, the object should be compressed, currently gzip compression is supported. Set header `Content-Encoding: gzip` if the content is compressed and `Accept-Encoding: gzip` to receive compressed content.
884
+ Create or update a geoscience object. Upload a geoscience object based on the schema element. Geoscience objects can be stored hierarchically, by providing the path to the object, including the object name, in the request URL. A detailed list of the available object schemas can be found in Seequent's [evo-schemas](https://github.com/seequentevo/evo-schemas) repository. The submitted properties will be validated against the specified schema properties. To create a new object, upload it to a unique path with the UUID field set to `null`. The response will contain a reflection of the uploaded object with a newly assigned object ID. This can be used for future requests to update the object. If a version of the geoscience object already exists at the specified path a new version will be created. To move or rename an existing object, simply upload a new version of it (with the same UUID) to a new, unique path or file name. Note that every upload of an object is considered a new version, even if no changes have been made. If required, the object should be compressed, currently gzip compression is supported. Set header `Content-Encoding: gzip` if the content is compressed and `Accept-Encoding: gzip` to receive compressed content.
815
885
 
816
886
  :param org_id: The customer's organisation ID
817
887
  Format: `uuid`
@@ -21,11 +21,11 @@ For more information on using the Geoscience Object API, see the [Geoscience Obj
21
21
 
22
22
 
23
23
  This code is generated from the OpenAPI specification for Geoscience Object API.
24
- API version: 1.21.0
24
+ API version: 1.26.0
25
25
  """
26
26
 
27
27
  from evo.common.connector import APIConnector
28
- from evo.common.data import RequestMethod
28
+ from evo.common.data import EmptyResponse, RequestMethod # noqa: F401
29
29
  from evo.common.utils import get_header_metadata
30
30
 
31
31
  from ..models import * # noqa: F403
@@ -21,6 +21,7 @@ from uuid import UUID
21
21
 
22
22
  from pydantic import (
23
23
  Field,
24
+ RootModel,
24
25
  StrictBool,
25
26
  StrictFloat,
26
27
  StrictInt,
@@ -30,6 +31,23 @@ from pydantic import (
30
31
  from .._model_config import CustomBaseModel
31
32
 
32
33
 
34
+ class CoordinateItem(RootModel[list[StrictFloat]]):
35
+ root: Annotated[list[StrictFloat], Field(max_length=2, min_length=2, title="GeoJSON Point")]
36
+ """
37
+ A WGS84 coordinate pair [longitude, latitude]. The longitude must come before the latitude, in order to be considered a valid GeoJSON Point
38
+ """
39
+
40
+
41
+ class Coordinate(RootModel[list[CoordinateItem]]):
42
+ root: Annotated[
43
+ list[CoordinateItem],
44
+ Field(max_length=5, min_length=5, title="GeoJSON LinearRing"),
45
+ ]
46
+ """
47
+ A list of GeoJSON points defining a closed linear ring. In order for the ring to be closed, the last point must be the same as the first point. Only a rectangle is supported, so the ring must be defined by 5 points.
48
+ """
49
+
50
+
33
51
  class DataDownloadUrl(CustomBaseModel):
34
52
  download_url: Annotated[StrictStr | None, Field(title="Download Url")] = None
35
53
  id: Annotated[UUID, Field(title="Id")]
@@ -100,6 +118,39 @@ class MetadataUpdateBody(CustomBaseModel):
100
118
  stage_id: Annotated[UUID | None, Field(title="Stage Id")] = None
101
119
 
102
120
 
121
+ class MoveObjectRequest(CustomBaseModel):
122
+ """
123
+ Optional destination fields; omitted or null values leave that field unchanged.
124
+ """
125
+
126
+ folder_id: Annotated[
127
+ UUID | None,
128
+ Field(examples=["442daf92-4fde-4c0a-986e-cd231db22eb7"], title="Folder Id"),
129
+ ] = None
130
+ """
131
+ Optional ID of an existing folder to move this object to.
132
+ The indicated folder must not be deleted and in the same workspace as the object being moved.
133
+ Can optionally be combined with `folder_path` for extra validation of the target folder.
134
+ Omit both `folder_id` and `folder_path` to keep the current folder.
135
+ """
136
+ folder_path: Annotated[StrictStr | None, Field(examples=["/my/folder/path"], title="Folder Path")] = None
137
+ """
138
+ Optional path to a folder to move this object to. Must start with a '/'.
139
+ Must not end with a '/' (unless the target is the root folder).
140
+ Does not contain the name of the object itself.
141
+ Folder names are 1-100 UTF-8 characters with a total max folder_path length of 1520 characters.
142
+ Will create all intermediate folders if they do not exist.
143
+ If `folder_id` is also provided then `folder_path` must match the path of the folder specified by `folder_id`.
144
+ Omit both `folder_id` and `folder_path` to keep the current folder.
145
+ """
146
+ name: Annotated[StrictStr | None, Field(examples=["grid_collection.json"], title="Name")] = None
147
+ """
148
+ Optional new name for the object. Names are 1-256 characters, must end in .json,
149
+ and cannot contain path separators or double dots, start with a dot, or start/end with whitespace.
150
+ Omit to keep the current name.
151
+ """
152
+
153
+
103
154
  class ObjectResponseLinks(CustomBaseModel):
104
155
  data: Annotated[list[DataDownloadUrl], Field(title="Data")]
105
156
  download: Annotated[StrictStr, Field(title="Download")]
@@ -160,12 +211,7 @@ class BoundingBox(CustomBaseModel):
160
211
  """
161
212
 
162
213
  coordinates: Annotated[
163
- list[
164
- Annotated[
165
- list[Annotated[list[StrictFloat], Field(max_length=2, min_length=2, title="GeoJSON Point")]],
166
- Field(max_length=5, min_length=5, title="GeoJSON LinearRing"),
167
- ]
168
- ],
214
+ list[Coordinate],
169
215
  Field(max_length=1, min_length=1, title="GeoJSON Polygon Coordinates"),
170
216
  ]
171
217
  """
@@ -193,10 +239,14 @@ class GetObjectResponse(CustomBaseModel):
193
239
  deleted_at: Annotated[datetime | None, Field(title="Deleted At")] = None
194
240
  deleted_by: User | None = None
195
241
  etag: Annotated[StrictStr, Field(title="Etag")]
242
+ folder_id: Annotated[UUID | None, Field(title="Folder Id")] = None
196
243
  geojson_bounding_box: BoundingBox | None = None
197
244
  geojson_bounding_box_from_workspace_crs: Annotated[
198
- StrictBool | None, Field(title="Geojson Bounding Box From Workspace Crs")
199
- ] = None
245
+ StrictBool, Field(title="Geojson Bounding Box From Workspace Crs")
246
+ ]
247
+ """
248
+ True if the bounding box was calculated using the workspace CRS, else False.
249
+ """
200
250
  links: ObjectResponseLinks
201
251
  modified_at: Annotated[datetime, Field(title="Modified At")]
202
252
  modified_by: User | None = None
@@ -222,10 +272,14 @@ class ListedObject(CustomBaseModel):
222
272
  deleted_at: Annotated[datetime | None, Field(title="Deleted At")] = None
223
273
  deleted_by: User | None = None
224
274
  etag: Annotated[StrictStr, Field(title="Etag")]
275
+ folder_id: Annotated[UUID | None, Field(title="Folder Id")] = None
225
276
  geojson_bounding_box: BoundingBox | None = None
226
277
  geojson_bounding_box_from_workspace_crs: Annotated[
227
- StrictBool | None, Field(title="Geojson Bounding Box From Workspace Crs")
228
- ] = None
278
+ StrictBool, Field(title="Geojson Bounding Box From Workspace Crs")
279
+ ]
280
+ """
281
+ True if the bounding box was calculated using the workspace CRS, else False.
282
+ """
229
283
  links: ListedObjectLinks
230
284
  modified_at: Annotated[datetime, Field(title="Modified At")]
231
285
  modified_by: User | None = None
@@ -240,16 +294,48 @@ class ListedObject(CustomBaseModel):
240
294
  version_id: Annotated[StrictStr, Field(title="Version Id")]
241
295
 
242
296
 
297
+ class MoveObjectResponse(CustomBaseModel):
298
+ created_at: Annotated[datetime, Field(title="Created At")]
299
+ created_by: User | None = None
300
+ deleted_at: Annotated[datetime | None, Field(title="Deleted At")] = None
301
+ deleted_by: User | None = None
302
+ etag: Annotated[StrictStr, Field(title="Etag")]
303
+ folder_id: Annotated[UUID | None, Field(title="Folder Id")] = None
304
+ geojson_bounding_box: BoundingBox | None = None
305
+ geojson_bounding_box_from_workspace_crs: Annotated[
306
+ StrictBool, Field(title="Geojson Bounding Box From Workspace Crs")
307
+ ]
308
+ """
309
+ True if the bounding box was calculated using the workspace CRS, else False.
310
+ """
311
+ links: ObjectResponseLinks
312
+ modified_at: Annotated[datetime, Field(title="Modified At")]
313
+ modified_by: User | None = None
314
+ object: GeoscienceObject
315
+ object_id: Annotated[UUID, Field(title="Object Id")]
316
+ object_path: Annotated[StrictStr | None, Field(title="Object Path")] = None
317
+ stage: StageResponse | None = None
318
+ version_id: Annotated[StrictStr, Field(title="Version Id")]
319
+
320
+
243
321
  class OrgListedObject(CustomBaseModel):
244
322
  created_at: Annotated[datetime, Field(title="Created At")]
245
323
  created_by: User | None = None
246
324
  deleted_at: Annotated[datetime | None, Field(title="Deleted At")] = None
247
325
  deleted_by: User | None = None
326
+ folder_id: Annotated[UUID | None, Field(title="Folder Id")] = None
248
327
  geojson_bounding_box: BoundingBox | None = None
328
+ geojson_bounding_box_from_workspace_crs: Annotated[
329
+ StrictBool, Field(title="Geojson Bounding Box From Workspace Crs")
330
+ ]
331
+ """
332
+ True if the bounding box was calculated using the workspace CRS, else False.
333
+ """
249
334
  modified_at: Annotated[datetime, Field(title="Modified At")]
250
335
  modified_by: User | None = None
251
336
  name: Annotated[StrictStr, Field(title="Name")]
252
337
  object_id: Annotated[UUID, Field(title="Object Id")]
338
+ path: Annotated[StrictStr, Field(title="Path")]
253
339
  schema_: Annotated[StrictStr, Field(alias="schema", title="Schema")]
254
340
  stage: StageResponse | None = None
255
341
  workspace_access: RoleEnum | None = None
@@ -263,10 +349,14 @@ class PostObjectResponse(CustomBaseModel):
263
349
  deleted_at: Annotated[datetime | None, Field(title="Deleted At")] = None
264
350
  deleted_by: User | None = None
265
351
  etag: Annotated[StrictStr, Field(title="Etag")]
352
+ folder_id: Annotated[UUID | None, Field(title="Folder Id")] = None
266
353
  geojson_bounding_box: BoundingBox | None = None
267
354
  geojson_bounding_box_from_workspace_crs: Annotated[
268
- StrictBool | None, Field(title="Geojson Bounding Box From Workspace Crs")
269
- ] = None
355
+ StrictBool, Field(title="Geojson Bounding Box From Workspace Crs")
356
+ ]
357
+ """
358
+ True if the bounding box was calculated using the workspace CRS, else False.
359
+ """
270
360
  links: ObjectResponseLinks
271
361
  modified_at: Annotated[datetime, Field(title="Modified At")]
272
362
  modified_by: User | None = None
@@ -28,6 +28,7 @@ from evo.common.utils import NoFeedback
28
28
 
29
29
  from ..exceptions import SchemaValidationError, TableFormatError
30
30
  from ..utils import ArrowTableFormat, KnownTableFormat, TableInfo
31
+ from ..utils.tables import table_to_dataframe
31
32
 
32
33
  try:
33
34
  import pandas as pd
@@ -140,9 +141,13 @@ class ParquetLoader:
140
141
  # Optional support for pandas dataframes
141
142
 
142
143
  def load_as_dataframe(self) -> pd.DataFrame:
143
- """Load the Parquet data as a Pandas DataFrame."""
144
+ """Load the Parquet data as a Pandas DataFrame.
145
+
146
+ Column dtypes are derived from the Geoscience Object column types, never from pandas metadata in the file.
147
+ Integer and boolean columns use pandas nullable dtypes (e.g. `Int64`, `boolean`).
148
+ """
144
149
  table = self.load_as_table()
145
- return table.to_pandas()
150
+ return table_to_dataframe(table)
146
151
 
147
152
  if _NP_AVAILABLE:
148
153
  # Optional support for numpy arrays
@@ -141,6 +141,8 @@ try:
141
141
  ReportColumnSpec,
142
142
  ReportResult,
143
143
  ReportSpecificationData,
144
+ SpatialRelation,
145
+ VolumeFilter,
144
146
  )
145
147
 
146
148
  __all__ += [
@@ -152,6 +154,8 @@ try:
152
154
  "ReportColumnSpec",
153
155
  "ReportResult",
154
156
  "ReportSpecificationData",
157
+ "SpatialRelation",
158
+ "VolumeFilter",
155
159
  ]
156
160
  except ImportError:
157
161
  pass
@@ -353,6 +353,7 @@ class BlockModel(BaseSpatialObject):
353
353
  self,
354
354
  data: ReportSpecificationData,
355
355
  fb: IFeedback = NoFeedback,
356
+ preview: bool = False,
356
357
  ) -> Report:
357
358
  """Create a new report specification for this block model.
358
359
 
@@ -362,6 +363,8 @@ class BlockModel(BaseSpatialObject):
362
363
 
363
364
  :param data: The report specification data.
364
365
  :param fb: Optional feedback interface for progress reporting.
366
+ :param preview: Opt in to preview API features (required when ``data.volume_filter`` is set).
367
+ The returned report keeps this setting for subsequent calls.
365
368
  :return: A Report instance representing the created report.
366
369
 
367
370
  Example::
@@ -378,13 +381,15 @@ class BlockModel(BaseSpatialObject):
378
381
  >>> report # Pretty-prints with BlockSync link
379
382
  """
380
383
  typed_bm = await self._get_or_create_typed_block_model()
381
- return await typed_bm.create_report(data, fb=fb)
384
+ return await typed_bm.create_report(data, fb=fb, preview=preview)
382
385
 
383
- async def list_reports(self, fb: IFeedback = NoFeedback) -> list[Report]:
386
+ async def list_reports(self, fb: IFeedback = NoFeedback, preview: bool = False) -> list[Report]:
384
387
  """List all report specifications for this block model.
385
388
 
386
389
  :param fb: Optional feedback interface for progress reporting.
390
+ :param preview: Opt in to preview API features (e.g. reports with volume filters).
391
+ The returned reports keep this setting for subsequent calls.
387
392
  :return: List of Report instances.
388
393
  """
389
394
  typed_bm = await self._get_or_create_typed_block_model()
390
- return await typed_bm.list_reports(fb=fb)
395
+ return await typed_bm.list_reports(fb=fb, preview=preview)
@@ -23,9 +23,8 @@ except ImportError:
23
23
  DataFrame = None # type: ignore
24
24
 
25
25
  from .data import ObjectDataClient
26
- from .downhole import expand_hole_index, hole_chunks_from_ids
27
26
  from .table_formats import all_known_formats, get_known_format
28
- from .tables import ArrowTableFormat, BaseTableFormat, KnownTableFormat
27
+ from .tables import ArrowTableFormat, BaseTableFormat, ColumnFormat, KnownTableFormat
29
28
  from .types import ArrayTableInfo, AttributeInfo, CategoryInfo, LookupTableInfo, TableInfo
30
29
 
31
30
  # We _used_ to export Table and DataFrame from this package as custom protocols, but we are using the actual
@@ -39,12 +38,19 @@ __all__ = [
39
38
  "AttributeInfo",
40
39
  "BaseTableFormat",
41
40
  "CategoryInfo",
41
+ "ColumnFormat",
42
42
  "KnownTableFormat",
43
43
  "LookupTableInfo",
44
44
  "ObjectDataClient",
45
45
  "TableInfo",
46
46
  "all_known_formats",
47
- "expand_hole_index",
48
47
  "get_known_format",
49
- "hole_chunks_from_ids",
50
48
  ]
49
+
50
+ if DataFrame is not None:
51
+ from .downhole import expand_hole_index, hole_chunks_from_ids
52
+
53
+ __all__ += [
54
+ "expand_hole_index",
55
+ "hole_chunks_from_ids",
56
+ ]
@@ -26,7 +26,7 @@ from evo.common.utils import NoFeedback, PartialFeedback, split_feedback
26
26
  from ..exceptions import TableFormatError
27
27
  from ..io import _CACHE_SCOPE, ObjectDataDownload, ObjectDataUpload
28
28
  from .table_formats import INTEGER_ARRAY_1_INT32, INTEGER_ARRAY_MD_INT32, LOOKUP_TABLE_INT32
29
- from .tables import KnownTableFormat
29
+ from .tables import ArrowTableFormat, KnownTableFormat, table_to_dataframe
30
30
  from .types import ArrayTableInfo, CategoryInfo, LookupTableInfo
31
31
 
32
32
  try:
@@ -69,27 +69,19 @@ def _iter_refs(target: Any, _key: str | None = None) -> Iterator[str]:
69
69
  yield str(value)
70
70
 
71
71
 
72
- def _get_schema_from_dataframe(dataframe: "pd.DataFrame") -> pa.Schema:
73
- """Get a normalized pyarrow schema from a pandas dataframe.
72
+ def _table_from_dataframe(dataframe: "pd.DataFrame") -> pa.Table:
73
+ """Convert a pandas dataframe to a pyarrow table for upload.
74
74
 
75
- This hook centralizes dataframe-to-Arrow schema adjustments before the
76
- dataframe is converted to a table. It currently performs these conversions:
77
- - large_string -> string
78
- - dictionary<*, large_string> -> dictionary<*, string>
75
+ The dataframe index is not part of any Geoscience Object table format, so it is never stored. Pandas metadata is
76
+ removed, so readers rely only on the Geoscience Object schema.
79
77
 
80
- :param dataframe: The pandas dataframe to get the schema from.
81
- :return: A pyarrow schema with any configured type conversions applied.
78
+ :param dataframe: The pandas dataframe to convert.
79
+ :return: A pyarrow table with the normalized schema from `ArrowTableFormat.from_pandas`.
82
80
  """
83
- schema = pa.Schema.from_pandas(dataframe)
84
- fields = []
85
- for field in schema:
86
- if pa.types.is_large_string(field.type):
87
- fields.append(field.with_type(pa.string()))
88
- elif pa.types.is_dictionary(field.type) and pa.types.is_large_string(field.type.value_type):
89
- fields.append(field.with_type(pa.dictionary(field.type.index_type, pa.string())))
90
- else:
91
- fields.append(field)
92
- return pa.schema(fields)
81
+ table_format = ArrowTableFormat.from_pandas(dataframe)
82
+ return pa.Table.from_pandas(
83
+ dataframe, schema=table_format.pa_schema, preserve_index=False
84
+ ).replace_schema_metadata()
93
85
 
94
86
 
95
87
  class ObjectDataClient:
@@ -226,7 +218,8 @@ class ObjectDataClient:
226
218
  both the value and lookup tables.
227
219
 
228
220
  The table columns must be string columns, but can be dictionary encoded. If they are dictionary encoded, this
229
- method takes advantage of that, when building the value and lookup tables.
221
+ method takes advantage of that, when building the value and lookup tables. Large strings are converted to
222
+ strings.
230
223
 
231
224
  :param table: The table to be uploaded.
232
225
  :param fb: A feedback object for tracking upload progress.
@@ -241,11 +234,13 @@ class ObjectDataClient:
241
234
  columns_chunk_range = []
242
235
  for column in table.itercolumns():
243
236
  column = column.dictionary_encode()
244
- if not pa.types.is_string(column.type.value_type):
237
+ value_type = column.type.value_type
238
+ if not (pa.types.is_string(value_type) or pa.types.is_large_string(value_type)):
245
239
  raise TableFormatError("Category columns must be of type string")
246
- if not pa.types.is_int32(column.type.index_type):
247
- # Currently, we only support int32 indices
248
- column = pc.cast(column, pa.dictionary(pa.int32(), column.type.value_type))
240
+ # Currently, we only support int32 indices and string values
241
+ category_type = pa.dictionary(pa.int32(), pa.string())
242
+ if column.type != category_type:
243
+ column = pc.cast(column, category_type)
249
244
  start_chunk = len(all_chunks)
250
245
  if isinstance(column, pa.ChunkedArray):
251
246
  all_chunks.extend(column.chunks)
@@ -426,8 +421,7 @@ class ObjectDataClient:
426
421
  no table formats are specified, raised when the table does not match any known format.
427
422
  :raises StorageFileNotFoundError: If the destination does not exist or is not a directory.
428
423
  """
429
- schema = _get_schema_from_dataframe(dataframe)
430
- table = pa.Table.from_pandas(dataframe, schema)
424
+ table = _table_from_dataframe(dataframe)
431
425
  return self.save_table(table, table_format=table_format)
432
426
 
433
427
  async def upload_dataframe(
@@ -450,8 +444,7 @@ class ObjectDataClient:
450
444
  :raises TableFormatError: If the provided table does not match any of the specified formats. If
451
445
  no table formats are specified, raised when the table does not match any known format.
452
446
  """
453
- schema = _get_schema_from_dataframe(dataframe)
454
- table = pa.Table.from_pandas(dataframe, schema)
447
+ table = _table_from_dataframe(dataframe)
455
448
  table_info = await self.upload_table(table, table_format=table_format, fb=fb)
456
449
  return table_info
457
450
 
@@ -472,8 +465,8 @@ class ObjectDataClient:
472
465
  :raises TableFormatError: If the table isn't a valid category table, or if the number of categories exceeds
473
466
  what int32 type can represent.
474
467
  """
475
- schema = _get_schema_from_dataframe(dataframe)
476
- table = pa.Table.from_pandas(dataframe, schema)
468
+ # Keep dictionary encoding until the categories are split into value and lookup tables.
469
+ table = pa.Table.from_pandas(dataframe, preserve_index=False).replace_schema_metadata()
477
470
  category_info = await self.upload_category_table(table, fb=fb)
478
471
  return category_info
479
472
 
@@ -499,6 +492,6 @@ class ObjectDataClient:
499
492
  """
500
493
  table = await self.download_table(object_id, version_id, table_info, fb)
501
494
  try:
502
- return table.to_pandas()
495
+ return table_to_dataframe(table)
503
496
  except ModuleNotFoundError:
504
497
  raise RuntimeError("Unable to download dataframe because the `pandas` package is not installed")
@@ -13,6 +13,7 @@ from __future__ import annotations
13
13
 
14
14
  import hashlib
15
15
  import os
16
+ from collections.abc import Callable
16
17
  from pathlib import Path
17
18
  from tempfile import NamedTemporaryFile
18
19
  from types import EllipsisType
@@ -26,20 +27,50 @@ from evo.common.exceptions import StorageFileNotFoundError
26
27
 
27
28
  from ..exceptions import SchemaValidationError, TableFormatError
28
29
 
30
+ try:
31
+ import pandas as pd
32
+ except ImportError:
33
+ _PD_AVAILABLE = False
34
+ else:
35
+ _PD_AVAILABLE = True
36
+
29
37
  logger = evo.logging.getLogger("object.tables")
30
38
 
31
39
  __all__ = [
32
40
  "ArrowTableFormat",
33
41
  "BaseTableFormat",
42
+ "ColumnFormat",
34
43
  "KnownTableFormat",
44
+ "table_to_dataframe",
35
45
  ]
36
46
 
37
47
  # Block size to limit memory use while calculating the sha256 digest of a file.
38
48
  _DIGEST_BLOCK_SIZE = 4 * 1024 * 1024
39
49
 
40
-
41
- class _ColumnFormat:
42
- def __init__(self, format_spec: pa.DataType | str):
50
+ # Pandas dtype for every supported Geoscience Object column type. Integer and boolean columns use pandas nullable
51
+ # dtypes, so nulls do not change the dtype. `None` keeps the pyarrow default conversion: pyarrow `types_mapper` only
52
+ # accepts pandas extension dtypes, so numpy-backed `float64` and the pandas default string dtype cannot be named here.
53
+ _PANDAS_DTYPES: dict[str, str | None] = {
54
+ "float64": None,
55
+ "uint8": "UInt8",
56
+ "uint32": "UInt32",
57
+ "uint64": "UInt64",
58
+ "int32": "Int32",
59
+ "int64": "Int64",
60
+ "bool": "boolean",
61
+ "string": None,
62
+ "timestamp": "datetime64[us, UTC]",
63
+ }
64
+
65
+
66
+ class ColumnFormat:
67
+ """A Geoscience Object column type and its corresponding Arrow data type."""
68
+
69
+ def __init__(self, format_spec: pa.DataType | str) -> None:
70
+ """
71
+ :param format_spec: A Geoscience Object column type identifier or a supported Arrow data type.
72
+ :raises TypeError: If the column type is not supported.
73
+ """
43
74
  if isinstance(format_spec, str):
44
75
  self._type = self._get_data_type(format_spec)
45
76
  self._format_id = format_spec
@@ -97,12 +128,29 @@ class _ColumnFormat:
97
128
 
98
129
  @property
99
130
  def id(self) -> str:
131
+ """The Geoscience Object column type identifier."""
100
132
  return self._format_id
101
133
 
102
134
  @property
103
135
  def type(self) -> pa.DataType:
136
+ """The corresponding Arrow data type."""
104
137
  return self._type
105
138
 
139
+ @property
140
+ def pandas_dtype(self) -> pd.api.extensions.ExtensionDtype | None:
141
+ """The pandas dtype used when loading this column into a dataframe.
142
+
143
+ Integer and boolean columns use pandas nullable dtypes, so nulls do not change the dtype. Returns `None` for
144
+ `float64` and `string` columns, which use the pyarrow default conversion.
145
+
146
+ :raises ImportError: If pandas is not installed.
147
+ """
148
+ if not _PD_AVAILABLE:
149
+ raise ModuleNotFoundError("No module named 'pandas'", name="pandas")
150
+ if (dtype_name := _PANDAS_DTYPES[self._format_id]) is None:
151
+ return None
152
+ return pd.api.types.pandas_dtype(dtype_name)
153
+
106
154
 
107
155
  class BaseTableFormat:
108
156
  """Base type for comparing table formats"""
@@ -114,7 +162,7 @@ class BaseTableFormat:
114
162
  ("...") indicates a multidimensional format.
115
163
  """
116
164
  self._name = name
117
- self._columns: list[_ColumnFormat] = []
165
+ self._columns: list[ColumnFormat] = []
118
166
  self._multi_dimensional = False
119
167
  for column_type in columns:
120
168
  if column_type is Ellipsis:
@@ -122,7 +170,7 @@ class BaseTableFormat:
122
170
  elif self._multi_dimensional:
123
171
  raise AssertionError("Found new type specification after Ellipsis")
124
172
  else:
125
- self._columns.append(_ColumnFormat(format_spec=column_type))
173
+ self._columns.append(ColumnFormat(format_spec=column_type))
126
174
 
127
175
  if self._multi_dimensional and len(self._columns) != 1:
128
176
  raise AssertionError("Multidimensional formats must only have one column type")
@@ -147,6 +195,11 @@ class BaseTableFormat:
147
195
  """The number of columns in this table format"""
148
196
  return len(self._columns)
149
197
 
198
+ @property
199
+ def columns(self) -> tuple[ColumnFormat, ...]:
200
+ """Column formats in order. A multidimensional format has one entry for its repeated column type."""
201
+ return tuple(self._columns)
202
+
150
203
  @property
151
204
  def data_type(self) -> str:
152
205
  """The column data type(s) in this table format"""
@@ -156,15 +209,63 @@ class BaseTableFormat:
156
209
  class ArrowTableFormat(BaseTableFormat):
157
210
  """Specialised table format type that can be generated from a pyarrow table"""
158
211
 
212
+ _pa_schema: pa.Schema | None = None
213
+
214
+ @property
215
+ def pa_schema(self) -> pa.Schema:
216
+ """The Arrow schema supplied to `from_schema` or inferred by `from_pandas`, without any metadata.
217
+
218
+ :raises ValueError: If the format was constructed directly without a schema.
219
+ """
220
+ if self._pa_schema is None:
221
+ raise ValueError("Create the format with from_schema() or from_pandas() to access its Arrow schema")
222
+ return self._pa_schema
223
+
159
224
  @classmethod
160
225
  def from_schema(cls, pa_schema: pa.Schema) -> ArrowTableFormat:
161
226
  """Generate an ArrowTableFormat instance that represents the structure of the provided table schema.
162
227
 
163
- :param pa_schema: Table schema to generate a format representation for.
228
+ :param pa_schema: Table schema to generate a format representation for. Schema and field metadata are not kept.
164
229
 
165
230
  :return: A table format that can be used to compare against known formats.
166
231
  """
167
- return ArrowTableFormat(name=f"{cls.__name__}<{'/'.join(pa_schema.names)}>", columns=pa_schema.types)
232
+ table_format = cls(name=f"{cls.__name__}<{'/'.join(pa_schema.names)}>", columns=pa_schema.types)
233
+ table_format._pa_schema = pa.schema([field.remove_metadata() for field in pa_schema])
234
+ return table_format
235
+
236
+ @classmethod
237
+ def from_pandas(cls, dataframe: pd.DataFrame) -> ArrowTableFormat:
238
+ """Infer a table format from a pandas dataframe using the supported Geoscience Object column types.
239
+
240
+ Large strings are normalized to strings. The inferred schema excludes the dataframe index and pandas metadata.
241
+
242
+ :param dataframe: The dataframe to infer the format from.
243
+ :return: A format whose `pa_schema` can be passed to `pyarrow.Table.from_pandas`.
244
+ :raises TypeError: If a column type is not supported. Use `ObjectDataClient.upload_category_dataframe`
245
+ for categorical columns, which are split into value and lookup tables separately.
246
+ """
247
+ schema = pa.Schema.from_pandas(dataframe, preserve_index=False)
248
+ fields = [field.with_type(pa.string()) if pa.types.is_large_string(field.type) else field for field in schema]
249
+ return cls.from_schema(pa.schema(fields))
250
+
251
+ def pandas_types_mapper(self) -> Callable[[pa.DataType], pd.api.extensions.ExtensionDtype | None]:
252
+ """Get a pyarrow `types_mapper` that converts this format's columns to their `ColumnFormat.pandas_dtype`.
253
+
254
+ Pass the result to `table.replace_schema_metadata().to_pandas(types_mapper=...)` to ignore legacy metadata.
255
+
256
+ :raises ImportError: If pandas is not installed.
257
+ """
258
+ return {column.type: column.pandas_dtype for column in self._columns}.get
259
+
260
+
261
+ def table_to_dataframe(table: pa.Table) -> pd.DataFrame:
262
+ """Convert a table to a pandas dataframe using the Geoscience Object column types, ignoring pandas metadata.
263
+
264
+ :param table: The table to convert. It is expected to have been validated against a known table format.
265
+ """
266
+ types_mapper = ArrowTableFormat.from_schema(table.schema).pandas_types_mapper()
267
+ # PyArrow parses pandas metadata even with ignore_metadata=True.
268
+ return table.replace_schema_metadata().to_pandas(types_mapper=types_mapper)
168
269
 
169
270
 
170
271
  class KnownTableFormat(BaseTableFormat):
File without changes
File without changes