Skip to content

Commit

Permalink
fix py2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
yymao committed Aug 24, 2017
1 parent 6502c5b commit 5b9906f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions easyquery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
Copyright (c) 2015-2017 Yao-Yuan Mao (yymao)
http://opensource.org/licenses/MIT
"""

if not hasattr(list, 'copy'):
from builtins import list
import numpy as np
import numexpr as ne

Expand Down Expand Up @@ -120,13 +121,13 @@ def _combine_queries(self, other, operator, out=None):
out._operands = self._operands + other._operands

elif self._operator == operator and other._operator != operator:
out._operands = self._operands + [other]
out._operands = self._operands + list((other,))

elif self._operator != operator and other._operator == operator:
out._operands = [self] + other._operands
out._operands = list((self,)) + other._operands

else:
out._operands = [self, other]
out._operands = list((self, other))

return out

Expand Down Expand Up @@ -278,8 +279,9 @@ def copy(self):
return out


_Query_Class = Query

def filter(table, *queries, query_class=Query):
def filter(table, *queries):
"""
A convenient function to filter `table` with `queries`.
Equivalent to Query(*queries).filter(table)
Expand All @@ -294,10 +296,10 @@ def filter(table, *queries, query_class=Query):
-------
table : filtered table
"""
return query_class(*queries).filter(table)
return _Query_Class(*queries).filter(table)


def count(table, *queries, query_class=Query):
def count(table, *queries):
"""
A convenient function to count the number of entries in `table`
that satisfy `queries`.
Expand All @@ -313,10 +315,10 @@ def count(table, *queries, query_class=Query):
-------
count : int
"""
return query_class(*queries).count(table)
return _Query_Class(*queries).count(table)


def mask(table, *queries, query_class=Query):
def mask(table, *queries):
"""
A convenient function to create a mask (a boolean array) for `table`
given `queries`.
Expand All @@ -332,4 +334,4 @@ def mask(table, *queries, query_class=Query):
-------
mask : numpy bool array
"""
return query_class(*queries).mask(table)
return _Query_Class(*queries).mask(table)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name='easyquery',
version='0.1.0',
version='0.1.1',
description='Create easy-to-use Query objects that can apply on NumPy structured arrays, astropy Table, and Pandas DataFrame.',
url='https://github.com/yymao/easyquery',
author='Yao-Yuan Mao',
Expand Down

0 comments on commit 5b9906f

Please sign in to comment.