FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
zarr-python/src/zarr/testing/buffer.py at main · oldrobotdev/zarr-python · GitHub
oldrobotdev
/
zarr-python
Public
forked from
zarr-developers/zarr-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
zarr-python
/
src
/
zarr
/
testing
/
buffer.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
86 lines (65 loc) · 2.28 KB
Breadcrumbs
zarr-python
/
src
/
zarr
/
testing
/
buffer.py
Copy path
File metadata and controls
86 lines (65 loc) · 2.28 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# mypy: ignore-errors
from
__future__
import
annotations
from
typing
import
TYPE_CHECKING
,
Any
,
Literal
import
numpy
as
np
import
numpy
.
typing
as
npt
from
zarr
.
core
.
buffer
import
Buffer
,
BufferPrototype
,
cpu
from
zarr
.
storage
import
MemoryStore
if
TYPE_CHECKING
:
from
collections
.
abc
import
Iterable
from
typing
import
Self
__all__
=
[
"NDBufferUsingTestNDArrayLike"
,
"StoreExpectingTestBuffer"
,
"TestBuffer"
,
]
class
TestNDArrayLike
(
np
.
ndarray
):
"""An example of an ndarray-like class"""
__test__
=
False
class
TestBuffer
(
cpu
.
Buffer
):
"""Example of a custom Buffer that handles ArrayLike"""
__test__
=
False
class
NDBufferUsingTestNDArrayLike
(
cpu
.
NDBuffer
):
"""Example of a custom NDBuffer that handles MyNDArrayLike"""
@
classmethod
def
create
(
cls
,
*
,
shape
:
Iterable
[
int
],
dtype
:
npt
.
DTypeLike
,
order
:
Literal
[
"C"
,
"F"
]
=
"C"
,
fill_value
:
Any
|
None
=
None
,
)
->
Self
:
"""Overwrite `NDBuffer.create` to create a TestNDArrayLike instance"""
ret
=
cls
(
TestNDArrayLike
(
shape
=
shape
,
dtype
=
dtype
,
order
=
order
))
if
fill_value
is
not
None
:
ret
.
fill
(
fill_value
)
return
ret
@
classmethod
def
empty
(
cls
,
shape
:
tuple
[
int
, ...],
dtype
:
npt
.
DTypeLike
,
order
:
Literal
[
"C"
,
"F"
]
=
"C"
,
)
->
Self
:
return
super
(
cpu
.
NDBuffer
,
cls
).
empty
(
shape
=
shape
,
dtype
=
dtype
,
order
=
order
)
class
StoreExpectingTestBuffer
(
MemoryStore
):
"""Example of a custom Store that expect MyBuffer for all its non-metadata
We assume that keys containing "json" is metadata
"""
async
def
set
(
self
,
key
:
str
,
value
:
Buffer
,
byte_range
:
tuple
[
int
,
int
]
|
None
=
None
)
->
None
:
if
"json"
not
in
key
:
assert
isinstance
(
value
,
TestBuffer
)
await
super
().
set
(
key
,
value
,
byte_range
)
async
def
get
(
self
,
key
:
str
,
prototype
:
BufferPrototype
,
byte_range
:
tuple
[
int
,
int
|
None
]
|
None
=
None
,
)
->
Buffer
|
None
:
if
"json"
not
in
key
:
assert
prototype
.
buffer
is
TestBuffer
ret
=
await
super
().
get
(
key
=
key
,
prototype
=
prototype
,
byte_range
=
byte_range
)
if
ret
is
not
None
:
assert
isinstance
(
ret
,
prototype
.
buffer
)
return
ret
Back
|
FazBrowse Home
|
New Git URL