evo-objects 0.9.0__tar.gz → 0.10.0__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.
- {evo_objects-0.9.0 → evo_objects-0.10.0}/PKG-INFO +12 -1
- {evo_objects-0.9.0 → evo_objects-0.10.0}/pyproject.toml +1 -1
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/client/api_client.py +7 -2
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/client/object_client.py +13 -3
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/client/parse.py +2 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/data.py +17 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/endpoints/__init__.py +3 -1
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/endpoints/api/data_api.py +3 -1
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/endpoints/api/metadata_api.py +3 -1
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/endpoints/api/objects_api.py +26 -13
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/endpoints/api/stages_api.py +3 -1
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/endpoints/models.py +32 -1
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/parquet/loader.py +7 -2
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/utils/__init__.py +10 -4
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/utils/data.py +24 -31
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/utils/tables.py +108 -7
- {evo_objects-0.9.0 → evo_objects-0.10.0}/.gitignore +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/LICENSE.md +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/__init__.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/_model_config.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/client/__init__.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/endpoints/api/__init__.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/exceptions.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/io.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/parquet/__init__.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/py.typed +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/__init__.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/_data.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/_downhole.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/_grid.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/_model.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/_prefetch.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/_utils.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/attributes.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/base.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/block_model_ref.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/downhole_collection.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/downhole_intervals.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/exceptions.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/pointset.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/regular_grid.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/regular_masked_grid.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/spatial.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/tensor_grid.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/types.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/typed/variogram.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/utils/downhole.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/src/evo/objects/utils/table_formats.py +0 -0
- {evo_objects-0.9.0 → evo_objects-0.10.0}/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.
|
|
3
|
+
Version: 0.10.0
|
|
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
|
|
@@ -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)
|
|
@@ -449,7 +449,7 @@ class ObjectAPIClient(BaseAPIClient):
|
|
|
449
449
|
:param request_timeout: Timeout setting for this request. If one number is provided, it will be the
|
|
450
450
|
total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.
|
|
451
451
|
|
|
452
|
-
:return: A
|
|
452
|
+
:return: A DownloadedObject containing the metadata and access methods for the requested geoscience object.
|
|
453
453
|
"""
|
|
454
454
|
reference = ObjectReference.new(environment=self._environment, object_path=path, version_id=version)
|
|
455
455
|
return await DownloadedObject.from_reference(
|
|
@@ -464,6 +464,7 @@ class ObjectAPIClient(BaseAPIClient):
|
|
|
464
464
|
object_id: UUID,
|
|
465
465
|
version: str | None = None,
|
|
466
466
|
request_timeout: int | float | tuple[int | float, int | float] | None = None,
|
|
467
|
+
deleted: bool = False,
|
|
467
468
|
) -> DownloadedObject:
|
|
468
469
|
"""Download a geoscience object definition (by UUID).
|
|
469
470
|
|
|
@@ -472,8 +473,11 @@ class ObjectAPIClient(BaseAPIClient):
|
|
|
472
473
|
default.
|
|
473
474
|
:param request_timeout: Timeout setting for this request. If one number is provided, it will be the
|
|
474
475
|
total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.
|
|
476
|
+
:param deleted: When true, include deleted objects, including objects in deleted folders. Active objects are
|
|
477
|
+
still returned. Use `metadata.is_deleted` to check whether the downloaded object is deleted. By default,
|
|
478
|
+
downloading a deleted object raises a `GoneException`.
|
|
475
479
|
|
|
476
|
-
:return: A
|
|
480
|
+
:return: A DownloadedObject containing the metadata and access methods for the requested geoscience object.
|
|
477
481
|
"""
|
|
478
482
|
reference = ObjectReference.new(environment=self._environment, object_id=object_id, version_id=version)
|
|
479
483
|
return await DownloadedObject.from_reference(
|
|
@@ -481,6 +485,7 @@ class ObjectAPIClient(BaseAPIClient):
|
|
|
481
485
|
reference=reference,
|
|
482
486
|
cache=self._cache,
|
|
483
487
|
request_timeout=request_timeout,
|
|
488
|
+
deleted=deleted,
|
|
484
489
|
)
|
|
485
490
|
|
|
486
491
|
async def get_latest_object_versions(
|
|
@@ -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
|
|
@@ -108,6 +109,7 @@ class DownloadedObject(IContext):
|
|
|
108
109
|
reference: ObjectReference | str,
|
|
109
110
|
cache: ICache | None = None,
|
|
110
111
|
request_timeout: int | float | tuple[int | float, int | float] | None = None,
|
|
112
|
+
deleted: bool = False,
|
|
111
113
|
) -> DownloadedObject:
|
|
112
114
|
"""Download a geoscience object from the service, given an object reference.
|
|
113
115
|
|
|
@@ -116,8 +118,11 @@ class DownloadedObject(IContext):
|
|
|
116
118
|
a reference.
|
|
117
119
|
:param cache: An optional cache to use for data downloads.
|
|
118
120
|
:param request_timeout: An optional timeout to use for API requests. See evo.common.APIConnector for details.
|
|
121
|
+
:param deleted: When true, deleted objects can also be downloaded, including objects in deleted folders.
|
|
122
|
+
Active objects are still returned. Only supported for references by object ID.
|
|
119
123
|
|
|
120
|
-
:raises ValueError: If the reference is invalid,
|
|
124
|
+
:raises ValueError: If the reference is invalid, if the connector base URL does not match the reference hub
|
|
125
|
+
URL, or if `deleted` is true for a reference by object path.
|
|
121
126
|
"""
|
|
122
127
|
ref = ObjectReference(reference) # Parse the reference if it's a string
|
|
123
128
|
|
|
@@ -140,8 +145,12 @@ class DownloadedObject(IContext):
|
|
|
140
145
|
raise ValueError("Only one of object_id or object_path should be provided")
|
|
141
146
|
|
|
142
147
|
if ref.object_id is not None:
|
|
148
|
+
if deleted:
|
|
149
|
+
request_kwargs["deleted"] = True
|
|
143
150
|
response = await api.get_object_by_id(object_id=ref.object_id, **request_kwargs)
|
|
144
151
|
elif ref.object_path is not None:
|
|
152
|
+
if deleted:
|
|
153
|
+
raise ValueError("Downloading deleted objects is only supported by object ID")
|
|
145
154
|
response = await api.get_object(objects_path=ref.object_path, **request_kwargs)
|
|
146
155
|
else:
|
|
147
156
|
raise ValueError("Either object_id or object_path must be provided")
|
|
@@ -486,10 +495,11 @@ class DownloadedObject(IContext):
|
|
|
486
495
|
nan_description structure.
|
|
487
496
|
:param column_names: An optional list of column names for the table, instead of those from the Parquet file.
|
|
488
497
|
|
|
489
|
-
:returns: A Pandas DataFrame containing the downloaded data.
|
|
498
|
+
:returns: A Pandas DataFrame containing the downloaded data. Column dtypes are derived from the
|
|
499
|
+
Geoscience Object column types; integer and boolean columns use pandas nullable dtypes.
|
|
490
500
|
"""
|
|
491
501
|
table = await self.download_table(table_info, fb=fb, nan_values=nan_values, column_names=column_names)
|
|
492
|
-
return table
|
|
502
|
+
return table_to_dataframe(table)
|
|
493
503
|
|
|
494
504
|
async def download_category_dataframe(
|
|
495
505
|
self,
|
|
@@ -178,6 +178,23 @@ class ObjectMetadata(ResourceMetadata):
|
|
|
178
178
|
stage: Stage | None
|
|
179
179
|
"""The stage of the object, if available."""
|
|
180
180
|
|
|
181
|
+
deleted_at: datetime | None = None
|
|
182
|
+
"""The date and time when the object was deleted, or None if the object is not deleted.
|
|
183
|
+
|
|
184
|
+
For an object inside a deleted folder, this is the time the folder was deleted.
|
|
185
|
+
"""
|
|
186
|
+
|
|
187
|
+
deleted_by: ServiceUser | None = None
|
|
188
|
+
"""The user who deleted the object, or None if the object is not deleted.
|
|
189
|
+
|
|
190
|
+
For an object inside a deleted folder, this is the user who deleted the folder.
|
|
191
|
+
"""
|
|
192
|
+
|
|
193
|
+
@property
|
|
194
|
+
def is_deleted(self) -> bool:
|
|
195
|
+
"""Whether the object is deleted, either individually or through deletion of its parent folder."""
|
|
196
|
+
return self.deleted_at is not None
|
|
197
|
+
|
|
181
198
|
@property
|
|
182
199
|
def path(self) -> str:
|
|
183
200
|
"""The full path of the object, formed by joining the parent and name, separated by a slash ('/')."""
|
|
@@ -17,11 +17,13 @@ The Geoscience Object API enables technological integrations at the object level
|
|
|
17
17
|
|
|
18
18
|
A Geoscience Object is a data structure that represents a concrete geological, geotechnical, or geophysical concept. Geoscience Objects can be referenced by their UUID or by a user-defined object path.
|
|
19
19
|
|
|
20
|
+
Objects are organised in workspace folders managed by the Folders API. Moving or renaming a folder changes the contained objects' paths. Deleting or restoring a folder also affects access to its contained objects.
|
|
21
|
+
|
|
20
22
|
For more information on using the Geoscience Object API, see the [Geoscience Object API overview](/docs/guides/objects), or the API references here.
|
|
21
23
|
|
|
22
24
|
|
|
23
25
|
This code is generated from the OpenAPI specification for Geoscience Object API.
|
|
24
|
-
API version: 1.26.
|
|
26
|
+
API version: 1.26.1
|
|
25
27
|
"""
|
|
26
28
|
|
|
27
29
|
# Import endpoint apis.
|
|
@@ -17,11 +17,13 @@ The Geoscience Object API enables technological integrations at the object level
|
|
|
17
17
|
|
|
18
18
|
A Geoscience Object is a data structure that represents a concrete geological, geotechnical, or geophysical concept. Geoscience Objects can be referenced by their UUID or by a user-defined object path.
|
|
19
19
|
|
|
20
|
+
Objects are organised in workspace folders managed by the Folders API. Moving or renaming a folder changes the contained objects' paths. Deleting or restoring a folder also affects access to its contained objects.
|
|
21
|
+
|
|
20
22
|
For more information on using the Geoscience Object API, see the [Geoscience Object API overview](/docs/guides/objects), or the API references here.
|
|
21
23
|
|
|
22
24
|
|
|
23
25
|
This code is generated from the OpenAPI specification for Geoscience Object API.
|
|
24
|
-
API version: 1.26.
|
|
26
|
+
API version: 1.26.1
|
|
25
27
|
"""
|
|
26
28
|
|
|
27
29
|
from evo.common.connector import APIConnector
|
|
@@ -17,11 +17,13 @@ The Geoscience Object API enables technological integrations at the object level
|
|
|
17
17
|
|
|
18
18
|
A Geoscience Object is a data structure that represents a concrete geological, geotechnical, or geophysical concept. Geoscience Objects can be referenced by their UUID or by a user-defined object path.
|
|
19
19
|
|
|
20
|
+
Objects are organised in workspace folders managed by the Folders API. Moving or renaming a folder changes the contained objects' paths. Deleting or restoring a folder also affects access to its contained objects.
|
|
21
|
+
|
|
20
22
|
For more information on using the Geoscience Object API, see the [Geoscience Object API overview](/docs/guides/objects), or the API references here.
|
|
21
23
|
|
|
22
24
|
|
|
23
25
|
This code is generated from the OpenAPI specification for Geoscience Object API.
|
|
24
|
-
API version: 1.26.
|
|
26
|
+
API version: 1.26.1
|
|
25
27
|
"""
|
|
26
28
|
|
|
27
29
|
from evo.common.connector import APIConnector
|
|
@@ -17,11 +17,13 @@ The Geoscience Object API enables technological integrations at the object level
|
|
|
17
17
|
|
|
18
18
|
A Geoscience Object is a data structure that represents a concrete geological, geotechnical, or geophysical concept. Geoscience Objects can be referenced by their UUID or by a user-defined object path.
|
|
19
19
|
|
|
20
|
+
Objects are organised in workspace folders managed by the Folders API. Moving or renaming a folder changes the contained objects' paths. Deleting or restoring a folder also affects access to its contained objects.
|
|
21
|
+
|
|
20
22
|
For more information on using the Geoscience Object API, see the [Geoscience Object API overview](/docs/guides/objects), or the API references here.
|
|
21
23
|
|
|
22
24
|
|
|
23
25
|
This code is generated from the OpenAPI specification for Geoscience Object API.
|
|
24
|
-
API version: 1.26.
|
|
26
|
+
API version: 1.26.1
|
|
25
27
|
"""
|
|
26
28
|
|
|
27
29
|
from evo.common.connector import APIConnector
|
|
@@ -57,7 +59,7 @@ class ObjectsApi:
|
|
|
57
59
|
) -> EmptyResponse:
|
|
58
60
|
"""Soft delete a geoscience object by path
|
|
59
61
|
|
|
60
|
-
Soft delete a geoscience object by path.
|
|
62
|
+
Soft delete a geoscience object by path.
|
|
61
63
|
|
|
62
64
|
:param org_id: The customer's organisation ID
|
|
63
65
|
Format: `uuid`
|
|
@@ -123,7 +125,7 @@ class ObjectsApi:
|
|
|
123
125
|
) -> EmptyResponse:
|
|
124
126
|
"""Soft delete a geoscience object
|
|
125
127
|
|
|
126
|
-
Delete a geoscience object by UUID.
|
|
128
|
+
Delete a geoscience object by UUID. An object already deleted is left unchanged. Restore an individual object using the update-by-UUID endpoint with `deleted=false`.
|
|
127
129
|
|
|
128
130
|
:param object_id: UUID of a geoscience object.
|
|
129
131
|
Format: `uuid`
|
|
@@ -193,7 +195,7 @@ class ObjectsApi:
|
|
|
193
195
|
) -> GetObjectResponse: # noqa: F405
|
|
194
196
|
"""Download a geoscience object
|
|
195
197
|
|
|
196
|
-
Download a geoscience object
|
|
198
|
+
Download a geoscience object using its current path. To retrieve a deleted object, including one in a deleted folder, use the download-by-UUID endpoint with `deleted=true`. If required, the object can be compressed, currently only gzip compression is supported. To receive a compressed payload set header `Accept-Encoding: gzip`.
|
|
197
199
|
|
|
198
200
|
:param org_id: The customer's organisation ID
|
|
199
201
|
Format: `uuid`
|
|
@@ -282,7 +284,7 @@ class ObjectsApi:
|
|
|
282
284
|
) -> GetObjectResponse: # noqa: F405
|
|
283
285
|
"""Download a geoscience object by UUID
|
|
284
286
|
|
|
285
|
-
Download a geoscience object with the provided UUID. If required, the object can be compressed, currently gzip compression is supported. To receive a compressed payload set header `Accept-Encoding: gzip`.
|
|
287
|
+
Download a geoscience object with the provided UUID. Use `deleted=true` to also retrieve deleted objects, including those in deleted folders. If required, the object can be compressed, currently only gzip compression is supported. To receive a compressed payload set header `Accept-Encoding: gzip`.
|
|
286
288
|
|
|
287
289
|
:param object_id: UUID of a geoscience object.
|
|
288
290
|
Format: `uuid`
|
|
@@ -297,7 +299,7 @@ class ObjectsApi:
|
|
|
297
299
|
Example: `'1746593470905878783'`
|
|
298
300
|
:param include_versions: (optional) Whether to return all versions of the object
|
|
299
301
|
Example: `False`
|
|
300
|
-
:param deleted: (optional) When true,
|
|
302
|
+
:param deleted: (optional) When true, also allows retrieval of an object that was deleted individually or implicitly through deletion of its parent folder. Active objects can still be returned. Defaults to false.
|
|
301
303
|
Example: `True`
|
|
302
304
|
:param if_none_match: (optional) Optional header used to check if there are any more recent versions of an object than the one specified. Returns 304 (Not Modified) if there are no newer versions.
|
|
303
305
|
Example: `'1706583776404684724'`
|
|
@@ -372,7 +374,7 @@ class ObjectsApi:
|
|
|
372
374
|
) -> list[LatestObjectVersionIdResponse]: # noqa: F405
|
|
373
375
|
"""List the latest version IDs for geoscience objects
|
|
374
376
|
|
|
375
|
-
Request to fetch the latest version IDs for a collection of geoscience objects (maximum of 500). The request body must only contain a list of UUIDs of the objects to check. The response will contain a list of objects with their UUIDs and the latest version ID. If the object from a given UUID does not exist or has been deleted, the request will be successful, but the version ID will be `null`.
|
|
377
|
+
Request to fetch the latest version IDs for a collection of geoscience objects (maximum of 500). The request body must only contain a list of UUIDs of the objects to check. The response will contain a list of objects with their UUIDs and the latest version ID. If the object from a given UUID does not exist or has been deleted, including implicitly through deletion of its parent folder, the request will be successful, but the version ID will be `null`.
|
|
376
378
|
|
|
377
379
|
:param org_id: The customer's organisation ID
|
|
378
380
|
Format: `uuid`
|
|
@@ -444,7 +446,7 @@ class ObjectsApi:
|
|
|
444
446
|
) -> ListVersionsResponse: # noqa: F405
|
|
445
447
|
"""Gets specified versions of a Geoscience Object.
|
|
446
448
|
|
|
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
|
|
449
|
+
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. Download links use the object's current path.
|
|
448
450
|
|
|
449
451
|
:param object_id: UUID of a geoscience object.
|
|
450
452
|
Format: `uuid`
|
|
@@ -513,6 +515,8 @@ class ObjectsApi:
|
|
|
513
515
|
workspace_id: str,
|
|
514
516
|
limit: int | None = None,
|
|
515
517
|
offset: int | None = None,
|
|
518
|
+
folder_id: str | None = None,
|
|
519
|
+
folder_depth: int | None = None,
|
|
516
520
|
deleted: bool | None = None,
|
|
517
521
|
order_by: str | None = None,
|
|
518
522
|
author: list[str] | None = None,
|
|
@@ -530,7 +534,7 @@ class ObjectsApi:
|
|
|
530
534
|
) -> ListObjectsResponse: # noqa: F405
|
|
531
535
|
"""List geoscience objects
|
|
532
536
|
|
|
533
|
-
|
|
537
|
+
The response will include all geoscience objects matching the given filters. The geoscience objects will be the latest versions of each object. If there are no objects matching the given filters, an empty list is returned.
|
|
534
538
|
|
|
535
539
|
:param org_id: The customer's organisation ID
|
|
536
540
|
Format: `uuid`
|
|
@@ -542,7 +546,12 @@ class ObjectsApi:
|
|
|
542
546
|
Example: `5000`
|
|
543
547
|
:param offset: (optional) Number of results to skip before returning `limit` number of results.
|
|
544
548
|
Example: `0`
|
|
545
|
-
:param
|
|
549
|
+
:param folder_id: (optional) The UUID of a folder in this workspace. Returns objects in that folder and its descendants, subject to `folder_depth` and the other filters. Omit to search the whole workspace. The folder must match the state selected by `deleted`: active by default or false, or deleted when true. An unknown folder or a mismatched deletion state returns no objects.
|
|
550
|
+
Format: `uuid`
|
|
551
|
+
Example: `'00000000-0000-0000-0000-000000000000'`
|
|
552
|
+
:param folder_depth: (optional) Maximum descendant folder levels to include beneath `folder_id`. Use `0` for objects directly in the selected folder, `1` to also include its immediate child folders, or omit for all descendant levels. Requires `folder_id`; supplying a depth alone returns 400.
|
|
553
|
+
Example: `0`
|
|
554
|
+
:param deleted: (optional) Defaults to false for active objects. When true, returns only deleted objects, including objects implicitly deleted because their parent folder was deleted.
|
|
546
555
|
Example: `True`
|
|
547
556
|
: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
557
|
Example: `'object_name,desc:created_by,asc:object.a.b.c'`
|
|
@@ -595,6 +604,10 @@ class ObjectsApi:
|
|
|
595
604
|
_query_params["limit"] = limit
|
|
596
605
|
if offset is not None:
|
|
597
606
|
_query_params["offset"] = offset
|
|
607
|
+
if folder_id is not None:
|
|
608
|
+
_query_params["folder_id"] = folder_id
|
|
609
|
+
if folder_depth is not None:
|
|
610
|
+
_query_params["folder_depth"] = folder_depth
|
|
598
611
|
if deleted is not None:
|
|
599
612
|
_query_params["deleted"] = deleted
|
|
600
613
|
if order_by is not None:
|
|
@@ -686,7 +699,7 @@ class ObjectsApi:
|
|
|
686
699
|
Example: `0`
|
|
687
700
|
:param limit: (optional) Max number of results per page.
|
|
688
701
|
Example: `5000`
|
|
689
|
-
:param deleted: (optional) When true, only objects
|
|
702
|
+
:param deleted: (optional) Defaults to false for active objects. When true, returns only deleted objects, including objects implicitly deleted because their parent folder was deleted.
|
|
690
703
|
Example: `True`
|
|
691
704
|
: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`
|
|
692
705
|
Example: `'object_name,desc:created_by,asc:object.a.b.c'`
|
|
@@ -881,7 +894,7 @@ class ObjectsApi:
|
|
|
881
894
|
) -> PostObjectResponse: # noqa: F405
|
|
882
895
|
"""Create a geoscience object
|
|
883
896
|
|
|
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.
|
|
897
|
+
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. Folders in the path that do not already exist are created automatically. An object name without parent segments places the object in the workspace root folder. 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. An existing object whose parent folder is deleted must be restored before it can be updated or moved. 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.
|
|
885
898
|
|
|
886
899
|
:param org_id: The customer's organisation ID
|
|
887
900
|
Format: `uuid`
|
|
@@ -960,7 +973,7 @@ class ObjectsApi:
|
|
|
960
973
|
) -> PostObjectResponse: # noqa: F405
|
|
961
974
|
"""Update a geoscience object
|
|
962
975
|
|
|
963
|
-
Update or restore a geoscience object by UUID.
|
|
976
|
+
Update or restore a geoscience object by UUID. Uploading an object to this endpoint will update (replace, i.e. no partial updates) 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. New objects must be uploaded by path. To restore an object that was previously deleted, send a request with the `deleted` parameter set to `false` and no message body. This operation will attempt to restore the object to its original path. Folders at the original path are recreated if missing. If the original path is occupied, Goose appends a number to the filename (for example, `object.json` becomes `object(1).json`). For an object implicitly deleted through its parent folder, a name conflict instead returns 409.
|
|
964
977
|
|
|
965
978
|
:param object_id: UUID of a geoscience object.
|
|
966
979
|
Format: `uuid`
|
|
@@ -17,11 +17,13 @@ The Geoscience Object API enables technological integrations at the object level
|
|
|
17
17
|
|
|
18
18
|
A Geoscience Object is a data structure that represents a concrete geological, geotechnical, or geophysical concept. Geoscience Objects can be referenced by their UUID or by a user-defined object path.
|
|
19
19
|
|
|
20
|
+
Objects are organised in workspace folders managed by the Folders API. Moving or renaming a folder changes the contained objects' paths. Deleting or restoring a folder also affects access to its contained objects.
|
|
21
|
+
|
|
20
22
|
For more information on using the Geoscience Object API, see the [Geoscience Object API overview](/docs/guides/objects), or the API references here.
|
|
21
23
|
|
|
22
24
|
|
|
23
25
|
This code is generated from the OpenAPI specification for Geoscience Object API.
|
|
24
|
-
API version: 1.26.
|
|
26
|
+
API version: 1.26.1
|
|
25
27
|
"""
|
|
26
28
|
|
|
27
29
|
from evo.common.connector import APIConnector
|
|
@@ -140,7 +140,8 @@ class MoveObjectRequest(CustomBaseModel):
|
|
|
140
140
|
Does not contain the name of the object itself.
|
|
141
141
|
Folder names are 1-100 UTF-8 characters with a total max folder_path length of 1520 characters.
|
|
142
142
|
Will create all intermediate folders if they do not exist.
|
|
143
|
-
If `folder_id` is also provided then `folder_path` must match
|
|
143
|
+
If `folder_id` is also provided then `folder_path` must match its path, ignoring case;
|
|
144
|
+
no folders are created in that case.
|
|
144
145
|
Omit both `folder_id` and `folder_path` to keep the current folder.
|
|
145
146
|
"""
|
|
146
147
|
name: Annotated[StrictStr | None, Field(examples=["grid_collection.json"], title="Name")] = None
|
|
@@ -240,6 +241,9 @@ class GetObjectResponse(CustomBaseModel):
|
|
|
240
241
|
deleted_by: User | None = None
|
|
241
242
|
etag: Annotated[StrictStr, Field(title="Etag")]
|
|
242
243
|
folder_id: Annotated[UUID | None, Field(title="Folder Id")] = None
|
|
244
|
+
"""
|
|
245
|
+
The UUID of the object's containing folder in this workspace. Use it with the Folder API to retrieve folder details. For objects deleted explicitly in the geoscience object service, this is the workspace's recycle-bin root ID, not the folder identified by the retained object path.
|
|
246
|
+
"""
|
|
243
247
|
geojson_bounding_box: BoundingBox | None = None
|
|
244
248
|
geojson_bounding_box_from_workspace_crs: Annotated[
|
|
245
249
|
StrictBool, Field(title="Geojson Bounding Box From Workspace Crs")
|
|
@@ -253,6 +257,9 @@ class GetObjectResponse(CustomBaseModel):
|
|
|
253
257
|
object: GeoscienceObject
|
|
254
258
|
object_id: Annotated[UUID, Field(title="Object Id")]
|
|
255
259
|
object_path: Annotated[StrictStr | None, Field(title="Object Path")] = None
|
|
260
|
+
"""
|
|
261
|
+
The object's path relative to the workspace root, including its name and without a leading '/'. For active objects, this reflects the current parent folder and object name, even for historical versions. Individually deleted objects retain their last active path for restoration.
|
|
262
|
+
"""
|
|
256
263
|
stage: StageResponse | None = None
|
|
257
264
|
version_id: Annotated[StrictStr, Field(title="Version Id")]
|
|
258
265
|
versions: Annotated[list[GeoscienceObjectVersion] | None, Field(title="Versions")] = None
|
|
@@ -273,6 +280,9 @@ class ListedObject(CustomBaseModel):
|
|
|
273
280
|
deleted_by: User | None = None
|
|
274
281
|
etag: Annotated[StrictStr, Field(title="Etag")]
|
|
275
282
|
folder_id: Annotated[UUID | None, Field(title="Folder Id")] = None
|
|
283
|
+
"""
|
|
284
|
+
The UUID of the object's containing folder in this workspace. Use it with the Folder API to retrieve folder details. For objects deleted explicitly in the geoscience object service, this is the workspace's recycle-bin root ID, not the folder identified by the retained object path.
|
|
285
|
+
"""
|
|
276
286
|
geojson_bounding_box: BoundingBox | None = None
|
|
277
287
|
geojson_bounding_box_from_workspace_crs: Annotated[
|
|
278
288
|
StrictBool, Field(title="Geojson Bounding Box From Workspace Crs")
|
|
@@ -286,6 +296,9 @@ class ListedObject(CustomBaseModel):
|
|
|
286
296
|
name: Annotated[StrictStr, Field(title="Name")]
|
|
287
297
|
object_id: Annotated[UUID, Field(title="Object Id")]
|
|
288
298
|
path: Annotated[StrictStr, Field(title="Path")]
|
|
299
|
+
"""
|
|
300
|
+
The object's containing folder path, with leading and trailing slashes, or '/' for the workspace root. The object name is returned separately in `name`. Reflects the current folder hierarchy for active objects, or the last active path for deleted objects.
|
|
301
|
+
"""
|
|
289
302
|
schema_: Annotated[StrictStr, Field(alias="schema", title="Schema")]
|
|
290
303
|
"""
|
|
291
304
|
The geoscience object schema.
|
|
@@ -301,6 +314,9 @@ class MoveObjectResponse(CustomBaseModel):
|
|
|
301
314
|
deleted_by: User | None = None
|
|
302
315
|
etag: Annotated[StrictStr, Field(title="Etag")]
|
|
303
316
|
folder_id: Annotated[UUID | None, Field(title="Folder Id")] = None
|
|
317
|
+
"""
|
|
318
|
+
The UUID of the object's containing folder in this workspace. Use it with the Folder API to retrieve folder details. For objects deleted explicitly in the geoscience object service, this is the workspace's recycle-bin root ID, not the folder identified by the retained object path.
|
|
319
|
+
"""
|
|
304
320
|
geojson_bounding_box: BoundingBox | None = None
|
|
305
321
|
geojson_bounding_box_from_workspace_crs: Annotated[
|
|
306
322
|
StrictBool, Field(title="Geojson Bounding Box From Workspace Crs")
|
|
@@ -314,6 +330,9 @@ class MoveObjectResponse(CustomBaseModel):
|
|
|
314
330
|
object: GeoscienceObject
|
|
315
331
|
object_id: Annotated[UUID, Field(title="Object Id")]
|
|
316
332
|
object_path: Annotated[StrictStr | None, Field(title="Object Path")] = None
|
|
333
|
+
"""
|
|
334
|
+
The object's path relative to the workspace root, including its name and without a leading '/'. For active objects, this reflects the current parent folder and object name, even for historical versions. Individually deleted objects retain their last active path for restoration.
|
|
335
|
+
"""
|
|
317
336
|
stage: StageResponse | None = None
|
|
318
337
|
version_id: Annotated[StrictStr, Field(title="Version Id")]
|
|
319
338
|
|
|
@@ -324,6 +343,9 @@ class OrgListedObject(CustomBaseModel):
|
|
|
324
343
|
deleted_at: Annotated[datetime | None, Field(title="Deleted At")] = None
|
|
325
344
|
deleted_by: User | None = None
|
|
326
345
|
folder_id: Annotated[UUID | None, Field(title="Folder Id")] = None
|
|
346
|
+
"""
|
|
347
|
+
The UUID of the object's containing folder in this workspace. Use it with the Folder API to retrieve folder details. For objects deleted explicitly in the geoscience object service, this is the workspace's recycle-bin root ID, not the folder identified by the retained object path.
|
|
348
|
+
"""
|
|
327
349
|
geojson_bounding_box: BoundingBox | None = None
|
|
328
350
|
geojson_bounding_box_from_workspace_crs: Annotated[
|
|
329
351
|
StrictBool, Field(title="Geojson Bounding Box From Workspace Crs")
|
|
@@ -336,6 +358,9 @@ class OrgListedObject(CustomBaseModel):
|
|
|
336
358
|
name: Annotated[StrictStr, Field(title="Name")]
|
|
337
359
|
object_id: Annotated[UUID, Field(title="Object Id")]
|
|
338
360
|
path: Annotated[StrictStr, Field(title="Path")]
|
|
361
|
+
"""
|
|
362
|
+
The object's containing folder path, with leading and trailing slashes, or '/' for the workspace root. The object name is returned separately in `name`. Reflects the current folder hierarchy for active objects, or the last active path for deleted objects.
|
|
363
|
+
"""
|
|
339
364
|
schema_: Annotated[StrictStr, Field(alias="schema", title="Schema")]
|
|
340
365
|
stage: StageResponse | None = None
|
|
341
366
|
workspace_access: RoleEnum | None = None
|
|
@@ -350,6 +375,9 @@ class PostObjectResponse(CustomBaseModel):
|
|
|
350
375
|
deleted_by: User | None = None
|
|
351
376
|
etag: Annotated[StrictStr, Field(title="Etag")]
|
|
352
377
|
folder_id: Annotated[UUID | None, Field(title="Folder Id")] = None
|
|
378
|
+
"""
|
|
379
|
+
The UUID of the object's containing folder in this workspace. Use it with the Folder API to retrieve folder details. For objects deleted explicitly in the geoscience object service, this is the workspace's recycle-bin root ID, not the folder identified by the retained object path.
|
|
380
|
+
"""
|
|
353
381
|
geojson_bounding_box: BoundingBox | None = None
|
|
354
382
|
geojson_bounding_box_from_workspace_crs: Annotated[
|
|
355
383
|
StrictBool, Field(title="Geojson Bounding Box From Workspace Crs")
|
|
@@ -363,6 +391,9 @@ class PostObjectResponse(CustomBaseModel):
|
|
|
363
391
|
object: GeoscienceObject
|
|
364
392
|
object_id: Annotated[UUID | None, Field(title="Object Id")] = None
|
|
365
393
|
object_path: Annotated[StrictStr | None, Field(title="Object Path")] = None
|
|
394
|
+
"""
|
|
395
|
+
The object's path relative to the workspace root, including its name and without a leading '/'. For active objects, this reflects the current parent folder and object name, even for historical versions. Individually deleted objects retain their last active path for restoration.
|
|
396
|
+
"""
|
|
366
397
|
stage: StageResponse | None = None
|
|
367
398
|
version_id: Annotated[StrictStr, Field(title="Version Id")]
|
|
368
399
|
|
|
@@ -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
|
|
150
|
+
return table_to_dataframe(table)
|
|
146
151
|
|
|
147
152
|
if _NP_AVAILABLE:
|
|
148
153
|
# Optional support for numpy arrays
|
|
@@ -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
|
|
73
|
-
"""
|
|
72
|
+
def _table_from_dataframe(dataframe: "pd.DataFrame") -> pa.Table:
|
|
73
|
+
"""Convert a pandas dataframe to a pyarrow table for upload.
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
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
|
|
81
|
-
:return: A pyarrow
|
|
78
|
+
:param dataframe: The pandas dataframe to convert.
|
|
79
|
+
:return: A pyarrow table with the normalized schema from `ArrowTableFormat.from_pandas`.
|
|
82
80
|
"""
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
476
|
-
table = pa.Table.from_pandas(dataframe,
|
|
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
|
|
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
|
-
|
|
42
|
-
|
|
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[
|
|
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(
|
|
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
|
-
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|