Skip to content

Commit 0324475

Browse files
committed
fix #832 : implemented CheckedSession, CheckedParameters and ArrayConstraint classes (based on preliminary code written by gdementen)
1 parent f3921b7 commit 0324475

15 files changed

+1462
-150
lines changed

README.rst

+6
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ For plotting
129129
- `matplotlib <http://matplotlib.org/>`__:
130130
required for plotting.
131131

132+
Miscellaneous
133+
~~~~~~~~~~~~~
134+
135+
- `pydantic <https://github.com/samuelcolvin/pydantic>`__:
136+
required to use `CheckedSession`.
137+
132138
.. _start-documentation:
133139

134140
Documentation

doc/source/api.rst

+24-1
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,6 @@ Modifying
795795

796796
Session.add
797797
Session.update
798-
Session.get
799798
Session.apply
800799
Session.transpose
801800

@@ -821,6 +820,30 @@ Load/Save
821820
Session.to_hdf
822821
Session.to_pickle
823822

823+
ArrayConstraint
824+
===============
825+
826+
.. autosummary::
827+
:toctree: _generated/
828+
829+
ArrayConstraint
830+
831+
CheckedSession
832+
==============
833+
834+
.. autosummary::
835+
:toctree: _generated/
836+
837+
CheckedSession
838+
839+
CheckedParameters
840+
=================
841+
842+
.. autosummary::
843+
:toctree: _generated/
844+
845+
CheckedParameters
846+
824847
.. _api-editor:
825848

826849
Editor

doc/source/changes/version_0_33.rst.inc

+11-20
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,21 @@ New features
2020

2121
* added official support for Python 3.9 (0.32.3 already supports it even though it was not mentioned).
2222

23-
* added a feature (see the :ref:`miscellaneous section <misc>` for details). It works on :ref:`api-axis` and
24-
:ref:`api-group` objects.
23+
* added :py:obj:`CheckedSession`, :py:obj:`CheckedParameters` and :py:obj:`ArrayConstraint` objects.
2524

26-
Here is an example of the new feature:
25+
`CheckedSession` is intended to be inherited by user defined classes in which the variables of a model
26+
are declared. By declaring variables, users will speed up the development of their models using the auto-completion
27+
(the feature in which development tools like PyCharm try to predict the variable or function a user intends
28+
to enter after only a few characters have been typed). All user defined classes inheriting from `CheckedSession`
29+
will have access to the same methods as `Session` objects.
2730

28-
>>> arr = ndtest((2, 3))
29-
>>> arr
30-
a\b b0 b1 b2
31-
a0 0 1 2
32-
a1 3 4 5
31+
`CheckedParameters` is the same as `CheckedSession` but the declared variables cannot be
32+
modified after initialization.
3333

34-
And it can also be used like this:
34+
The special :py:funct:`ArrayConstraint` type represents an Array object with fixed axes and/or dtype.
35+
It is intended to be only used along with :py:class:`CheckedSession`.
3536

36-
>>> arr = ndtest("a=a0..a2")
37-
>>> arr
38-
a a0 a1 a2
39-
0 1 2
40-
41-
* added another feature in the editor (closes :editor_issue:`1`).
42-
43-
.. note::
44-
45-
- It works for foo bar !
46-
- It does not work for foo baz !
37+
Closes :issue:`832`.
4738

4839

4940
.. _misc:

environment.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ dependencies:
1212
- pytest>=3.5
1313
- flake8
1414
- pip:
15-
- pytest-flake8
15+
- pytest-flake8
16+
- pydantic==1.5

larray/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
eye, all, any, sum, prod, cumsum, cumprod, min, max, mean, ptp, var,
99
std, median, percentile, stack, zip_array_values, zip_array_items)
1010
from larray.core.session import Session, local_arrays, global_arrays, arrays
11+
from larray.core.checked import ArrayConstraint, CheckedSession, CheckedParameters
1112
from larray.core.constants import nan, inf, pi, e, euler_gamma
1213
from larray.core.metadata import Metadata
1314
from larray.core.ufuncs import wrap_elementwise_array_func, maximum, minimum, where
@@ -55,6 +56,8 @@
5556
'median', 'percentile', 'stack', 'zip_array_values', 'zip_array_items',
5657
# session
5758
'Session', 'local_arrays', 'global_arrays', 'arrays',
59+
# constrained
60+
'ArrayConstraint', 'CheckedSession', 'CheckedParameters',
5861
# constants
5962
'nan', 'inf', 'pi', 'e', 'euler_gamma',
6063
# metadata

larray/core/axis.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ def __getitem__(self, key):
839839
-----
840840
key is label-based (slice and fancy indexing are supported)
841841
"""
842-
# if isinstance(key, basestring):
842+
# if isinstance(key, str):
843843
# key = to_keys(key)
844844

845845
def isscalar(k):
@@ -862,7 +862,7 @@ def isscalar(k):
862862
and key.name in self
863863
):
864864
return LGroup(key.name, None, self)
865-
# elif isinstance(key, basestring) and key in self:
865+
# elif isinstance(key, str) and key in self:
866866
# TODO: this is an awful workaround to avoid the "processing" of string keys which exist as is in the axis
867867
# (probably because the string was used in an aggregate function to create the label)
868868
# res = LGroup(slice(None), None, self)

0 commit comments

Comments
 (0)