Skip to content

(issue 832): implement CheckedSession, CheckedParameters and CheckedArray #840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ For plotting
- `matplotlib <http://matplotlib.org/>`__:
required for plotting.

Miscellaneous
~~~~~~~~~~~~~

- `pydantic <https://github.com/samuelcolvin/pydantic>`__:
required to use `CheckedSession`.

.. _start-documentation:

Documentation
Expand Down
25 changes: 24 additions & 1 deletion doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,6 @@ Modifying

Session.add
Session.update
Session.get
Session.apply
Session.transpose

Expand All @@ -821,6 +820,30 @@ Load/Save
Session.to_hdf
Session.to_pickle

CheckedArray
============

.. autosummary::
:toctree: _generated/

CheckedArray

CheckedSession
==============

.. autosummary::
:toctree: _generated/

CheckedSession

CheckedParameters
=================

.. autosummary::
:toctree: _generated/

CheckedParameters

.. _api-editor:

Editor
Expand Down
31 changes: 11 additions & 20 deletions doc/source/changes/version_0_33.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,21 @@ New features

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

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

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

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

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

>>> arr = ndtest("a=a0..a2")
>>> arr
a a0 a1 a2
0 1 2

* added another feature in the editor (closes :editor_issue:`1`).

.. note::

- It works for foo bar !
- It does not work for foo baz !
Closes :issue:`832`.


.. _misc:
Expand Down
3 changes: 2 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ dependencies:
- pytest>=3.5
- flake8
- pip:
- pytest-flake8
- pytest-flake8
- pydantic==1.5
3 changes: 3 additions & 0 deletions larray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
eye, all, any, sum, prod, cumsum, cumprod, min, max, mean, ptp, var,
std, median, percentile, stack, zip_array_values, zip_array_items)
from larray.core.session import Session, local_arrays, global_arrays, arrays
from larray.core.checked import CheckedArray, CheckedSession, CheckedParameters
from larray.core.constants import nan, inf, pi, e, euler_gamma
from larray.core.metadata import Metadata
from larray.core.ufuncs import wrap_elementwise_array_func, maximum, minimum, where
Expand Down Expand Up @@ -55,6 +56,8 @@
'median', 'percentile', 'stack', 'zip_array_values', 'zip_array_items',
# session
'Session', 'local_arrays', 'global_arrays', 'arrays',
# constrained
'CheckedArray', 'CheckedSession', 'CheckedParameters',
# constants
'nan', 'inf', 'pi', 'e', 'euler_gamma',
# metadata
Expand Down
4 changes: 2 additions & 2 deletions larray/core/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ def __getitem__(self, key):
-----
key is label-based (slice and fancy indexing are supported)
"""
# if isinstance(key, basestring):
# if isinstance(key, str):
# key = to_keys(key)

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