mathjson-solver 1.6.1__tar.gz → 1.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mathjson-solver
3
- Version: 1.6.1
3
+ Version: 1.7.0
4
4
  Summary: Utilities for MathJSON evaluation
5
5
  Home-page: https://github.com/LongenesisLtd/mathjson-solver
6
6
  Author: Martins Mednis
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = mathjson-solver
3
- version = 1.6.1
3
+ version = 1.7.0
4
4
  author = Martins Mednis
5
5
  author_email = mrt@mednis.info
6
6
  description = Utilities for MathJSON evaluation
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="mathjson-solver",
8
- version="1.6.1",
8
+ version="1.7.0",
9
9
  author="Martins Mednis",
10
10
  author_email="mrt@mednis.info",
11
11
  description="Utilities for MathJSON evaluation",
@@ -3,6 +3,8 @@ from functools import reduce
3
3
  import math
4
4
  from copy import deepcopy
5
5
  from statistics import median
6
+ import logging
7
+ import traceback
6
8
 
7
9
 
8
10
  class MathJSONException(Exception):
@@ -123,8 +125,19 @@ def create_mathjson_solver(solver_parameters):
123
125
  for x in s[1:-1]:
124
126
  if len(x) != 2:
125
127
  raise ValueError(f"Wrong if or elif in 'If'")
126
- if f(x[0], c):
127
- return f(x[1], c)
128
+ try:
129
+ if f(x[0], c):
130
+ try:
131
+ return f(x[1], c)
132
+ except MathJSONException as e:
133
+ logging.error(
134
+ "MathJSONException: %s", traceback.format_exc()
135
+ )
136
+ continue
137
+ except MathJSONException as e:
138
+ logging.error("MathJSONException: %s", traceback.format_exc())
139
+ return f(s[-1], c) # return default value (else)
140
+
128
141
  return f(s[-1], c)
129
142
 
130
143
  def In(s):
@@ -237,6 +250,7 @@ def create_mathjson_solver(solver_parameters):
237
250
  "Float": Float,
238
251
  "Str": Str,
239
252
  "Not": Not,
253
+ "IsDefined": lambda s: s[1] in c,
240
254
  }
241
255
  if s[0] in constructs:
242
256
  try:
@@ -253,6 +267,7 @@ def create_mathjson_solver(solver_parameters):
253
267
  elif s in c:
254
268
  return f(c[s], c)
255
269
  else:
270
+ # raise KeyError(f"Parameter '{s}' is not defined")
256
271
  return s
257
272
 
258
273
  return f
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mathjson-solver
3
- Version: 1.6.1
3
+ Version: 1.7.0
4
4
  Summary: Utilities for MathJSON evaluation
5
5
  Home-page: https://github.com/LongenesisLtd/mathjson-solver
6
6
  Author: Martins Mednis
@@ -45,6 +45,10 @@ from mathjson_solver import create_solver, MathJSONException
45
45
  ({"color": "green"}, ["Switch", "color", 0, ["blue", 10], ["red", 30]], 0),
46
46
  ({"color": "green"}, ["Switch", "undefined", 0, ["blue", 10], ["red", 30]], 0),
47
47
  ({}, ["If", [["Equal", 1, 0], 10], [["Equal", 2, 2], 20], 9000], 20),
48
+ ({"a": 10, "b": 10}, ["If", [["Equal", "a", "b"], 10], 9000], 10),
49
+ ({"a": 10, "b": 20}, ["If", [["Equal", "a", "b"], 10], 9000], 9000),
50
+ ({"a": 10}, ["If", [["Equal", "a", "b"], 10], 9000], 9000),
51
+ ({"a": 10}, ["If", [["Equal", "a", ["Sum", 1, "b"]], 10], 9000], 9000),
48
52
  ({}, ["Array", 1, 2, 3, 5, 2], ["Array", 1, 2, 3, 5, 2]),
49
53
  ({}, ["Max", ["Array", 1, 2, 3, 5, 2]], 5),
50
54
  ({}, ["Max", ["Array", 1, 2, ["Sum", 2, 4, 3], 5, 2]], 9),
File without changes