Skip to content

Commit e6cc2a6

Browse files
committed
FIX: fixed some plots not showing in the console
expressions like "arr[anything].plot(arg=anything)" were mistakenly considered as inplace updates
1 parent 641f091 commit e6cc2a6

File tree

3 files changed

+46
-42
lines changed

3 files changed

+46
-42
lines changed
+4-36
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,9 @@
11
.. py:currentmodule:: larray_editor
22

3-
Syntax changes
4-
^^^^^^^^^^^^^^
5-
6-
* renamed ``MappingEditor.old_method_name()`` to :py:obj:`MappingEditor.new_method_name()` (closes :editor_issue:`1`).
7-
8-
* renamed ``old_argument_name`` argument of :py:obj:`MappingEditor.method_name()` to ``new_argument_name``.
9-
10-
11-
Backward incompatible changes
12-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13-
14-
* other backward incompatible changes
15-
16-
17-
New features
18-
^^^^^^^^^^^^
19-
20-
* added a feature (see the :ref:`miscellaneous section <misc_editor>` for details).
21-
22-
* added another feature in the editor (closes :editor_issue:`1`).
23-
24-
.. note::
25-
26-
- It works for foo bar !
27-
- It does not work for foo baz !
28-
29-
30-
.. _misc_editor:
31-
32-
Miscellaneous improvements
33-
^^^^^^^^^^^^^^^^^^^^^^^^^^
34-
35-
* improved something.
36-
37-
383
Fixes
394
^^^^^
405

41-
* fixed something (closes :editor_issue:`1`).
6+
* fixed some console plots (again) because a "fix" in the partially done
7+
0.34.5 release introduced other problems. Sadly, these new problems were
8+
discovered after the release process for 0.34.5 was started, hence the
9+
partial release.

larray_editor/editor.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,13 @@
7676

7777
REOPEN_LAST_FILE = object()
7878

79-
assignment_pattern = re.compile(r'[^\[\]]+[^=]=[^=].+')
80-
setitem_pattern = re.compile(r'(\w+)(\.i|\.iflat|\.points|\.ipoints)?\[.+\][^=]*=[^=].+')
81-
history_vars_pattern = re.compile(r'_i?\d+')
79+
ASSIGNMENT_PATTERN = re.compile(r'[^\[\]]+[^=]=[^=].+')
80+
SUBSET_UPDATE_PATTERN = re.compile(r'(\w+)'
81+
r'(\.i|\.iflat|\.points|\.ipoints)?'
82+
r'\[.+\]\s*'
83+
r'([-+*/%&|^><]|//|\*\*|>>|<<)?'
84+
r'=\s*[^=].*')
85+
HISTORY_VARS_PATTERN = re.compile(r'_i?\d+')
8286
# XXX: add all scalars except strings (from numpy or plain Python)?
8387
# (long) strings are not handled correctly so should NOT be in this list
8488
# tuple, list
@@ -668,7 +672,7 @@ def delete_current_item(self):
668672
def line_edit_update(self):
669673
import larray as la
670674
last_input = self.eval_box.text()
671-
if assignment_pattern.match(last_input):
675+
if ASSIGNMENT_PATTERN.match(last_input):
672676
context = self.data._objects.copy()
673677
exec(last_input, la.__dict__, context)
674678
varname = self.update_mapping(context)
@@ -690,13 +694,13 @@ def ipython_cell_executed(self):
690694
ip_keys = {'In', 'Out', '_', '__', '___', '__builtin__', '_dh', '_ih', '_oh', '_sh', '_i', '_ii', '_iii',
691695
'exit', 'get_ipython', 'quit'}
692696
# '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__',
693-
clean_ns = {k: v for k, v in user_ns.items() if k not in ip_keys and not history_vars_pattern.match(k)}
697+
clean_ns = {k: v for k, v in user_ns.items() if k not in ip_keys and not HISTORY_VARS_PATTERN.match(k)}
694698

695699
# user_ns['_i'] is not updated yet (refers to the -2 item)
696700
# 'In' and '_ih' point to the same object (but '_ih' is supposed to be the non-overridden one)
697701
cur_input_num = len(user_ns['_ih']) - 1
698702
last_input = user_ns['_ih'][-1]
699-
setitem_match = setitem_pattern.match(last_input)
703+
setitem_match = SUBSET_UPDATE_PATTERN.match(last_input)
700704
if setitem_match:
701705
varname = setitem_match.group(1)
702706
# setitem to (i)python special variables do not concern us
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from larray_editor.editor import SUBSET_UPDATE_PATTERN
2+
3+
4+
def test_pattern():
5+
assert SUBSET_UPDATE_PATTERN.match('arr1[1] = 2')
6+
assert SUBSET_UPDATE_PATTERN.match('arr1[1]= 2')
7+
assert SUBSET_UPDATE_PATTERN.match('arr1[1]=2')
8+
assert SUBSET_UPDATE_PATTERN.match("arr1['a'] = arr2")
9+
assert SUBSET_UPDATE_PATTERN.match("arr1[func(mapping['a'])] = arr2")
10+
assert SUBSET_UPDATE_PATTERN.match("arr1.i[0, 0] = arr2")
11+
assert SUBSET_UPDATE_PATTERN.match("arr1.iflat[0, 0] = arr2")
12+
assert SUBSET_UPDATE_PATTERN.match("arr1.points[0, 0] = arr2")
13+
assert SUBSET_UPDATE_PATTERN.match("arr1.ipoints[0, 0] = arr2")
14+
assert SUBSET_UPDATE_PATTERN.match("arr1[0] += arr2")
15+
assert SUBSET_UPDATE_PATTERN.match("arr1[0] -= arr2")
16+
assert SUBSET_UPDATE_PATTERN.match("arr1[0] *= arr2")
17+
assert SUBSET_UPDATE_PATTERN.match("arr1[0] /= arr2")
18+
assert SUBSET_UPDATE_PATTERN.match("arr1[0] %= arr2")
19+
assert SUBSET_UPDATE_PATTERN.match("arr1[0] //= arr2")
20+
assert SUBSET_UPDATE_PATTERN.match("arr1[0] **= arr2")
21+
assert SUBSET_UPDATE_PATTERN.match("arr1[0] &= arr2")
22+
assert SUBSET_UPDATE_PATTERN.match("arr1[0] |= arr2")
23+
assert SUBSET_UPDATE_PATTERN.match("arr1[0] ^= arr2")
24+
assert SUBSET_UPDATE_PATTERN.match("arr1[0] >>= arr2")
25+
assert SUBSET_UPDATE_PATTERN.match("arr1[0] <<= arr2")
26+
assert SUBSET_UPDATE_PATTERN.match("arr1[0]") is None
27+
assert SUBSET_UPDATE_PATTERN.match("arr1.method()") is None
28+
assert SUBSET_UPDATE_PATTERN.match("arr1[0].method()") is None
29+
assert SUBSET_UPDATE_PATTERN.match("arr1[0].method(arg=thing)") is None
30+
assert SUBSET_UPDATE_PATTERN.match("arr1[0].method(arg==thing)") is None
31+
# this test fails but I don't think it is possible to fix it with regex
32+
# assert SUBSET_UPDATE_PATTERN.match("arr1[func('[]=0')].method()") is None

0 commit comments

Comments
 (0)