Skip to content

Commit

Permalink
python3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Mangum committed Nov 12, 2019
1 parent 4f961d9 commit 18f8b7d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.54]
## [0.2.5]

### Added

- MIT License.
- Flushed-out README.md
- Python3 compatibility

### Removed

Expand Down
18 changes: 9 additions & 9 deletions bamboo/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,12 @@ def wrapper(obj, value):
return func(obj, delta)
return wrapper

__eq__ = age_to_dt(Field.__eq__.__func__)
__ne__ = age_to_dt(Field.__ne__.__func__)
__lt__ = age_to_dt(RangeMixin.__gt__.__func__)
__le__ = age_to_dt(RangeMixin.__ge__.__func__)
__gt__ = age_to_dt(RangeMixin.__lt__.__func__)
__ge__ = age_to_dt(RangeMixin.__le__.__func__)
__eq__ = age_to_dt(Field.__eq__)
__ne__ = age_to_dt(Field.__ne__)
__lt__ = age_to_dt(RangeMixin.__gt__)
__le__ = age_to_dt(RangeMixin.__ge__)
__gt__ = age_to_dt(RangeMixin.__lt__)
__ge__ = age_to_dt(RangeMixin.__le__)

@property
def age(self):
Expand All @@ -528,9 +528,9 @@ def wrapper(obj, *args, **kwargs):
return datetime.fromtimestamp(result / 1000)
return wrapper

average = _epoch_to_dt(AggregationMixin.average.__func__)
max = _epoch_to_dt(AggregationMixin.max.__func__)
min = _epoch_to_dt(AggregationMixin.min.__func__)
average = _epoch_to_dt(AggregationMixin.average)
max = _epoch_to_dt(AggregationMixin.max)
min = _epoch_to_dt(AggregationMixin.min)

def histogram(self, interval=50, min_doc_count=1):
"""Get a count of values for a field bucketed by interval.
Expand Down
11 changes: 8 additions & 3 deletions tests/test_query_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,23 +701,28 @@ def test_age_query(df):
dt = df._body['query']['range']['ns3.test_date']['lte']
expected = date.today() - timedelta(days=days)
assert dt.date() == expected
list(df.collect()) # assert no query error
matches = list(df.collect())
assert len(matches) == 3


def test_age_query_inverted(df):
days = 10
df = ~df[df.ns3.test_date.age >= days]
# test does not raise key error
df._body['query']['bool']['must_not'][0]['range']['ns3.test_date']['lte']
list(df.collect()) # assert no query error
matches = list(df.collect())
assert len(matches) == 14


def test_age_query_inverted_2(df):
days = 10
df = df[~df.ns3.test_date.age >= days]
# test does not raise key error
df._body['query']['bool']['must_not'][0]['range']['ns3.test_date']['lte']
list(df.collect()) # assert no query error
x = list(df.collect()) # assert no query error
matches = list(df.collect())
assert len(matches) == 14



def test_exists_query(df):
Expand Down

0 comments on commit 18f8b7d

Please sign in to comment.