@@ -43,38 +43,42 @@ class SparseSpace(dict):
4343 This is essentially a "groupby" operation, and indeed the case could
4444 be made that this class should be replaced by `pandas.DataFrame`.
4545
46+ The convenience method `.subspace` (aliased to `.__call__`),
47+ which makes use of `.coords_matching`,
48+ can be used to select items by their attribute values.
4649 In addition, `__getitem__` is quite flexible, allowing accessing by:
4750
48- - The actual key, a `self.Coord` object, or a standard tuple. Returns single item.
49- - A `slice` or `list`. Returns list.
50- Can be used to get single item with `dct[[idx]][0]`.
51-
52- Of course, indexing by slice or list assumes that the dict is ordered,
53- which we inherit from the builtin `dict` since Python 3.7.
54- Moreover, it is a reflection of the fact that the internals of this class
55- work by looping over items.
56-
57- Other convenience functions: `.subspace` (alias `.__call__`) and `.coords_matching`.
58-
59- Inspired by
60-
61- - https://stackoverflow.com/a/7728830
62- - https://stackoverflow.com/q/3387691
51+ - The actual key, a `self.Coord` object, or a standard tuple.<br>
52+ Returns single item.
53+ - A `slice` or `list`.<br>
54+ Returns list.<br>
55+ *PS: indexing by slice or list assumes that the dict is ordered,
56+ which we inherit from the builtin `dict` since Python 3.7.
57+ Moreover, it is a reflection of the fact that the internals of this class
58+ work by looping over items.*
6359
6460 Example:
6561 >>> dct = xpSpace(["x", "y", "z"])
6662 >>> dct[(1, 2, 3)] = "point 1"
6763 >>> dct[1, 2, 3] == dct[(1, 2, 3)] == dct[dct.Coord(1, 2, 3)] == "point 1"
6864 True
6965
66+ Notice the different ways to access *a single* `xp`.
67+ Another way, combining `.subspace` and list accessing: e.g. `dct[[0]][0]`.
68+ The reason why nothing less clunky is implemented for getting only 1 item
69+ is that Coordinates can have any value. For example `None`:
70+ >>> dct[(1, 2, None)] = "point 2"
71+
7072 This dict only has three `dims`, so this fails:
7173 >>> dct[(1, 2, 3, 4)]
7274 Traceback (most recent call last):
7375 ...
7476 KeyError: (1, 2, 3, 4)
7577
76- Individual coordinates can be anything. For example `None`:
77- >>> dct[(1, 2, None)] = "point 2"
78+ Inspired by
79+
80+ - https://stackoverflow.com/a/7728830
81+ - https://stackoverflow.com/q/3387691
7882 """
7983
8084 @property
0 commit comments