Skip to content

Commit 196359a

Browse files
committed
Merge branch 'sanyer-develop' into develop
* sanyer-develop: add empty lists support for built-in function avg()
2 parents f7e3e69 + a18b003 commit 196359a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

jmespath/functions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ def _func_abs(self, arg):
166166

167167
@signature({'types': ['array-number']})
168168
def _func_avg(self, arg):
169-
return sum(arg) / float(len(arg))
169+
if arg:
170+
return sum(arg) / float(len(arg))
171+
else:
172+
return None
170173

171174
@signature({'types': [], 'variadic': True})
172175
def _func_not_null(self, *arguments):

tests/compliance/functions.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
"expression": "avg(strings)",
8484
"error": "invalid-type"
8585
},
86+
{
87+
"expression": "avg(empty_list)",
88+
"result": null
89+
},
8690
{
8791
"expression": "ceil(`1.2`)",
8892
"result": 2

0 commit comments

Comments
 (0)