Skip to content

Commit 4014433

Browse files
committed
- fix #78 : updated LArray class to handle metadata
- fix #79 : included metadata when saving/loading an array to/from an HDF file.
1 parent 5031e29 commit 4014433

File tree

8 files changed

+277
-109
lines changed

8 files changed

+277
-109
lines changed

doc/source/api.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,16 @@ Plotting
468468

469469
LArray.plot
470470

471+
.. _api-metadata:
472+
473+
Metadata
474+
========
475+
476+
.. autosummary::
477+
:toctree: _generated/
478+
479+
Metadata
480+
471481
.. _api-IO:
472482

473483
Input/Output

doc/source/changes/version_0_29.rst.inc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,43 @@ New features
2929
>>> a02.equals(a['a1:a3'] >> 'group_a')
3030
False
3131

32+
* allowed arrays to have metadata (e.g. title, description, authors, ...).
33+
Metadata can be accessed using the syntax ``array.meta.name``.
34+
See bellow for use cases:
35+
36+
>>> # add metadata to/from an array
37+
>>> # for Python <= 3.5
38+
>>> arr = ndtest((3, 3), meta=[('title', 'array for testing'), ('author', 'John Smith')])
39+
>>> # for Python >= 3.6
40+
>>> arr = ndtest((3, 3), meta=Metadata(title='array for testing', author='John Smith'))
41+
>>> # access an item
42+
>>> arr.meta.author
43+
'John Smith'
44+
>>> # update/add an item (the item is added if not found in existing metadata)
45+
>>> arr.meta.city = 'London'
46+
>>> # delete an item
47+
>>> del arr.meta.city
48+
49+
Warnings:
50+
51+
- Currently, only the HDF (.h5) file format supports saving and loading metadata.
52+
- Metadata are not kept when actions or methods are applied on a array
53+
except for operations modifying the object in-place, such as `pop[age < 10] = 0`,
54+
and when the method `copy()` is called. Do not add metadata to an array if you know
55+
you will apply actions or methods on it before dumping it.
56+
57+
Closes :issue:`78` and :issue:`79`.
58+
59+
* deprecated attribute `title` of array objects. A title is now considered as a metadata
60+
and must be added as:
61+
62+
>>> # add title at array creation
63+
>>> arr = ndtest((3, 3), meta=[('title', 'array for testing')])
64+
65+
>>> # or after array creation
66+
>>> arr = ndtest((3, 3))
67+
>>> arr.meta.title = 'array for testing'
68+
3269

3370
.. _misc:
3471

larray/core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
from larray.core.array import *
66
from larray.core.session import *
77
from larray.core.ufuncs import *
8+
from larray.core.metadata import *

0 commit comments

Comments
 (0)