diff --git a/CHANGELOG.md b/CHANGELOG.md index 2345e0f..5e9fba4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/bamboo/field.py b/bamboo/field.py index d420c82..2bde312 100644 --- a/bamboo/field.py +++ b/bamboo/field.py @@ -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__) diff --git a/setup.py b/setup.py index fbb46d6..97d99ee 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/tests/test_aggregations.py b/tests/test_aggregations.py index 4dbfb48..13b0499 100644 --- a/tests/test_aggregations.py +++ b/tests/test_aggregations.py @@ -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