Skip to content

Commit a4423d2

Browse files
committed
#112 Update README
1 parent 4089047 commit a4423d2

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,15 @@ class Image(AsDataArray):
291291
y: Coordof[YAxis] = 0
292292
```
293293

294-
### Custom DataArray and Dataset factories
294+
### Options for DataArray and Dataset creation
295+
296+
For customization, users can add a special class attribute, `__dataoptions__`, to a DataArray or Dataset class.
297+
A custom factory for DataArray or Dataset creation is only supported in the current implementation.
295298

296-
For customization, users can use a function or a class to create an initial DataArray or Dataset object by specifying a special class attribute, `__dataarray_factory__` or `__dataset_factory__`, respectively.
297299

298300
```python
299301
import xarray as xr
302+
from xarray_dataclasses import DataOptions
300303

301304

302305
class Custom(xr.DataArray):
@@ -308,19 +311,23 @@ class Custom(xr.DataArray):
308311
print("Custom method!")
309312

310313

314+
dataoptions = DataOptions(Custom)
315+
316+
311317
@dataclass
312318
class Image(AsDataArray):
313319
"""Specs for a monochromatic image."""
314320

321+
__dataoptions__ = dataoptions
322+
315323
data: Data[tuple[X, Y], float]
316324
x: Coord[X, int] = 0
317325
y: Coord[Y, int] = 0
318-
__dataarray_factory__ = Custom
319326

320327

321328
image = Image.ones([3, 3])
322-
isinstance(image, Custom) # True
323-
image.custom_method() # Custom method!
329+
isinstance(image, Custom) # True
330+
image.custom_method() # Custom method!
324331
```
325332

326333
### DataArray and Dataset creation without shorthands

0 commit comments

Comments
 (0)