Skip to content

Commit 23a2f11

Browse files
authored
Merge pull request #22 from briangu/codex/fix-format2-bug-with-arrays-in-klongpy
Fix Format2 handling of lists
2 parents 50e2129 + 1400469 commit 23a2f11

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

klongpy/dyads.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,11 @@ def _e_dyad_format2(a, b):
401401
"""
402402
Unravel the broadcasting of a and b and apply __e_dyad_format2
403403
"""
404+
if is_list(a) and is_list(b):
405+
return kg_asarray([vec_fn2(x, y, _e_dyad_format2) for x, y in zip(to_list(a), to_list(b))])
404406
if np.isarray(a) and np.isarray(b):
405-
return np.asarray([vec_fn2(x,y,_e_dyad_format2) for x,y in zip(a,b)])
406-
return __e_dyad_format2(a,b)
407+
return np.asarray([vec_fn2(x, y, _e_dyad_format2) for x, y in zip(a, b)])
408+
return __e_dyad_format2(a, b)
407409

408410
def eval_dyad_format2(a, b):
409411
"""

klongpy/lib/help.kg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ op.db::[
3030
[" a:$b" "Form"
3131
"b=string; convert 'b' to an object of the same form (type) as 'a'"]
3232
[" $a" "Format" "convert 'a' to a string representing the value of 'a'"]
33-
[" a$b" "Format2"
34-
"a=real; Format 'b', pad with 'a' blanks or to align to x.y digits"]
33+
[" a$b" "Format2"
34+
"a=real|list; when both operands are lists, apply pairwise. Format 'b', pad with 'a' blanks or to align to x.y digits"]
3535
[" >a" "Grade-Down"
3636
"a=vector; vector of indices of elements of 'a' in ascending order"]
3737
[" <a" "Grade-Up"

tests/test_suite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ def test_format2(self):
484484
self.assert_eval_cmp('5$1.23', '"1.23 "')
485485
self.assert_eval_cmp('5$-1.23', '"-1.23"')
486486
self.assert_eval_cmp('6$-1.23', '"-1.23 "')
487+
self.assert_eval_cmp('[1]$[1]', '["1"]')
487488
self.assert_eval_cmp('(-10)$0', '" 0"')
488489
self.assert_eval_cmp('(-10)$123', '" 123"')
489490
self.assert_eval_cmp('(-10)$-123', '" -123"')

0 commit comments

Comments
 (0)