jmespath / jmespath.py

JMESPath is a query language for JSON.
http://jmespath.org
MIT License
2.19k stars 181 forks source link

Add empty lists support for min_by() and max_by() #151

Closed lostinthefrost closed 6 years ago

lostinthefrost commented 7 years ago

The python implementations of the min_by and max_by functions raise a ValueError if the given array is empty. This is inconsistent with the python implementations of min and max which return null for an empty array. It's also inconsistent with the javascript implementations of the functions, as far as I can tell.

As a bonus, I also discovered that if the key function for max_by fails, it prints an error message saying that min_by failed.

codecov-io commented 7 years ago

Codecov Report

Merging #151 into develop will increase coverage by <.01%. The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #151      +/-   ##
===========================================
+ Coverage    97.25%   97.25%   +<.01%     
===========================================
  Files           14       14              
  Lines         1455     1459       +4     
===========================================
+ Hits          1415     1419       +4     
  Misses          40       40
Impacted Files Coverage Δ
jmespath/functions.py 99.5% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update f4c8806...373c640. Read the comment docs.

jamesls commented 6 years ago

Thanks!