flytekitplugins-xarray-zarr 1.16.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ """
2
+ .. currentmodule:: flytekitplugins.xarray
3
+
4
+ This package contains things that are useful when extending Flytekit.
5
+
6
+ .. autosummary::
7
+ :template: custom.rst
8
+ :toctree: generated/
9
+
10
+ XarrayDaZarrTypeTransformer
11
+ XarrayZarrTypeTransformer
12
+ """
13
+
14
+ from .xarray_transformers import XarrayDaZarrTypeTransformer, XarrayZarrTypeTransformer
@@ -0,0 +1,102 @@
1
+ import typing
2
+
3
+ import dask.distributed as dd
4
+
5
+ import xarray as xr
6
+ from flytekit import (
7
+ Blob,
8
+ BlobMetadata,
9
+ BlobType,
10
+ FlyteContext,
11
+ Literal,
12
+ LiteralType,
13
+ Scalar,
14
+ )
15
+ from flytekit.extend import TypeEngine, TypeTransformer
16
+
17
+
18
+ class XarrayZarrTypeTransformer(TypeTransformer[xr.Dataset]):
19
+ _TYPE_INFO = BlobType(format="binary", dimensionality=BlobType.BlobDimensionality.MULTIPART)
20
+
21
+ def __init__(self) -> None:
22
+ super().__init__(name="Xarray Dataset", t=xr.Dataset)
23
+
24
+ def get_literal_type(self, t: typing.Type[xr.Dataset]) -> LiteralType:
25
+ return LiteralType(blob=self._TYPE_INFO)
26
+
27
+ def to_literal(
28
+ self,
29
+ ctx: FlyteContext,
30
+ python_val: xr.Dataset,
31
+ python_type: typing.Type[xr.Dataset],
32
+ expected: LiteralType,
33
+ ) -> Literal:
34
+ remote_dir = ctx.file_access.get_random_remote_path("data.zarr")
35
+ # Opening with the dask client will attach the client eliminating the
36
+ # need for users to connect to the client if a task tasks a xr.Dataset
37
+ # type.
38
+ with dd.Client(timeout=120):
39
+ python_val.to_zarr(remote_dir, mode="w")
40
+ return Literal(scalar=Scalar(blob=Blob(uri=remote_dir, metadata=BlobMetadata(type=self._TYPE_INFO))))
41
+
42
+ def to_python_value(
43
+ self,
44
+ ctx: FlyteContext,
45
+ lv: Literal,
46
+ expected_python_type: typing.Type[xr.Dataset],
47
+ ) -> xr.Dataset:
48
+ return xr.open_zarr(lv.scalar.blob.uri)
49
+
50
+ def to_html(
51
+ self,
52
+ ctx: FlyteContext,
53
+ python_val: xr.Dataset,
54
+ expected_python_type: LiteralType,
55
+ ) -> str:
56
+ return python_val._repr_html_()
57
+
58
+
59
+ class XarrayDaZarrTypeTransformer(TypeTransformer[xr.DataArray]):
60
+ _TYPE_INFO = BlobType(format="binary", dimensionality=BlobType.BlobDimensionality.MULTIPART)
61
+
62
+ def __init__(self) -> None:
63
+ super().__init__(name="Xarray DataArray", t=xr.DataArray)
64
+
65
+ def get_literal_type(self, t: typing.Type[xr.DataArray]) -> LiteralType:
66
+ return LiteralType(blob=self._TYPE_INFO)
67
+
68
+ def to_literal(
69
+ self,
70
+ ctx: FlyteContext,
71
+ python_val: xr.DataArray,
72
+ python_type: typing.Type[xr.DataArray],
73
+ expected: LiteralType,
74
+ ) -> Literal:
75
+ remote_dir = ctx.file_access.get_random_remote_path("data.zarr")
76
+ # Opening with the dask client will attach the client eliminating the
77
+ # need for users to connect to the client if a task tasks a xr.Dataset
78
+ # type.
79
+ with dd.Client(timeout=120):
80
+ python_val.to_zarr(remote_dir, mode="w")
81
+ return Literal(scalar=Scalar(blob=Blob(uri=remote_dir, metadata=BlobMetadata(type=self._TYPE_INFO))))
82
+
83
+ def to_python_value(
84
+ self,
85
+ ctx: FlyteContext,
86
+ lv: Literal,
87
+ expected_python_type: typing.Type[xr.DataArray],
88
+ ) -> xr.DataArray:
89
+ # xr.open_zarr always opens a dataset, so we take the first variable
90
+ return list(xr.open_zarr(lv.scalar.blob.uri).data_vars.values())[0]
91
+
92
+ def to_html(
93
+ self,
94
+ ctx: FlyteContext,
95
+ python_val: xr.DataArray,
96
+ expected_python_type: LiteralType,
97
+ ) -> str:
98
+ return python_val._repr_html_()
99
+
100
+
101
+ TypeEngine.register(XarrayZarrTypeTransformer())
102
+ TypeEngine.register(XarrayDaZarrTypeTransformer())
@@ -0,0 +1 @@
1
+ import sys, types, os;p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('flytekitplugins',));importlib = __import__('importlib.util');__import__('importlib.machinery');m = sys.modules.setdefault('flytekitplugins', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('flytekitplugins', [os.path.dirname(p)])));m = m or sys.modules.setdefault('flytekitplugins', types.ModuleType('flytekitplugins'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.4
2
+ Name: flytekitplugins-xarray-zarr
3
+ Version: 1.16.9
4
+ Summary: Xarray Zarr plugin for flytekit
5
+ Author: flyteorg
6
+ Author-email: admin@flyte.org
7
+ License: apache2
8
+ Classifier: Intended Audience :: Science/Research
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Topic :: Scientific/Engineering
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Classifier: Topic :: Software Development
16
+ Classifier: Topic :: Software Development :: Libraries
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Requires-Python: >=3.9
19
+ Requires-Dist: dask[distributed]>=2022.10.2
20
+ Requires-Dist: flytekit<2.0.0,>=1.3.0b2
21
+ Requires-Dist: xarray
22
+ Requires-Dist: zarr
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: classifier
26
+ Dynamic: license
27
+ Dynamic: requires-dist
28
+ Dynamic: requires-python
29
+ Dynamic: summary
@@ -0,0 +1,9 @@
1
+ flytekitplugins_xarray_zarr-1.16.9-py3.14-nspkg.pth,sha256=ya_zoT0ZM023a2lpUsRaqXsgDEknLucLLOWbbtFBPw4,512
2
+ flytekitplugins/xarray/__init__.py,sha256=p9pV5dDng3ujPCPISggi-YWNb2gJRWfeM_t0Onum_hA,352
3
+ flytekitplugins/xarray/xarray_transformers.py,sha256=qi04uyukJ6EMZWoBi8A_uqQsFF3izZCAHxvGEkq7eOQ,3308
4
+ flytekitplugins_xarray_zarr-1.16.9.dist-info/METADATA,sha256=YvXntLo4QfyZJXaKgEgVPX0anycAx44de7rTZPZlCOo,1009
5
+ flytekitplugins_xarray_zarr-1.16.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ flytekitplugins_xarray_zarr-1.16.9.dist-info/entry_points.txt,sha256=JJHdCPzY51JrqrBaJJYovbBKXeRYCWHIF41dtfN5G8U,51
7
+ flytekitplugins_xarray_zarr-1.16.9.dist-info/namespace_packages.txt,sha256=b2gTzXFHuV5afchaJ28HueRhYzj-8x5Ytr8n2twnAik,16
8
+ flytekitplugins_xarray_zarr-1.16.9.dist-info/top_level.txt,sha256=b2gTzXFHuV5afchaJ28HueRhYzj-8x5Ytr8n2twnAik,16
9
+ flytekitplugins_xarray_zarr-1.16.9.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [flytekit.plugins]
2
+ xarray = flytekitplugins.xarray
@@ -0,0 +1 @@
1
+ flytekitplugins