Skip to content

Commit

Permalink
fix exception where aggregating on datetime with no documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Mangum authored and potatochip committed Oct 15, 2019
1 parent 960f05c commit 79a56cf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.4]

### Fixed

- Bug where aggregating a datetime field when there are no matching documents.

## [0.2.3]

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion bamboo/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@ def _epoch_to_dt(func):
@wraps(func)
def wrapper(obj, *args, **kwargs):
result = func(obj, *args, **kwargs)
return datetime.fromtimestamp(result / 1000)
if result:
return datetime.fromtimestamp(result / 1000)
return wrapper

average = _epoch_to_dt(AggregationMixin.average.__func__)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='bamboo',
version='0.2.3',
version='0.2.4',
author='Aaron Mangum',
author_email='aaron.mangum@juvo.com',
url='https://github.com/juvoinc/bamboo',
Expand Down
7 changes: 7 additions & 0 deletions tests/test_aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,10 @@ def test_date_stats(df):
'max_as_string': '2019-07-15T11:35:55.713', 'avg_as_string': '2019-07-05T23:41:58.571',
'avg': 1562370118571.0
}


def test_date_agg_on_no_matches(df):
df = df[df.attr2 > 10]
assert df.count() == 0
avg = df.ns3.test_date.average()
assert avg == None

0 comments on commit 79a56cf

Please sign in to comment.