Skip to content

Commit

Permalink
Fix typos and other code review suggestions
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Scheidgen <markus1978@users.noreply.github.com>
Co-authored-by: Johan Bergsma <JPBergsma@users.noreply.github.com>
  • Loading branch information
3 people committed May 19, 2021
1 parent 1b8220d commit 94bf368
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions optimade/filtertransformers/base_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Quantity:
Attributes:
name: The name of the quantity as used in the filter expressions.
backend_field: The name of the field for this quanity in elastic search, will be
backend_field: The name of the field for this quantity in the backend database, will be
`name` by default.
length_quantity: Another (typically integer) [`Quantity`][optimade.filtertransformers.base_transformer.Quantity]
that can be queried as the length of this quantity, e.g. `elements` and `nelements`. Backends
Expand Down Expand Up @@ -67,7 +67,7 @@ class BaseTransformer(abc.ABC, Transformer):
"=": None,
}

# map from operators to their syntactic (NOT logical) inverse to handle
# map from operators to their syntactic (as opposed to logical) inverse to handle
# equivalence between cases like "A > 3" and "3 < A".
_reversed_operator_map = {
">": "<",
Expand Down Expand Up @@ -292,7 +292,7 @@ def expression(self, arg):
def expression_clause(self, arg):
"""expression_clause: expression_phrase ( AND expression_phrase )*"""

def expression_phrase(self, args):
def expression_phrase(self, arg):
"""expression_phrase: [ NOT ] ( comparison | "(" expression ")" )"""

def property_first_comparison(self, arg):
Expand Down
2 changes: 1 addition & 1 deletion optimade/filtertransformers/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _query_op(
return Q(query_type, **{field: value})

if op == "!=":
# != queries must also include an existence/v check
# != queries must also include an existence check
# Note that for MongoDB, `$exists` will include null-valued fields,
# where as in ES `exists` excludes them.
# pylint: disable=invalid-unary-operand-type
Expand Down
2 changes: 0 additions & 2 deletions optimade/filtertransformers/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,5 +503,3 @@ def replacement(d, prop, expr):
return _cached_filter

return filter_

return filter_
11 changes: 10 additions & 1 deletion tests/filtertransformers/test_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,11 @@ def test_aliased_length_operator(self, mapper):
from optimade.filtertransformers.mongo import MongoTransformer

class MyMapper(mapper("StructureMapper")):
ALIASES = (("elements", "my_elements"), ("nelements", "nelem"))
ALIASES = (
("elements", "my_elements"),
("nelements", "nelem"),
("elements_ratios", "ratios"),
)
LENGTH_ALIASES = (
("chemsys", "nelements"),
("cartesian_site_positions", "nsites"),
Expand All @@ -529,6 +533,11 @@ class MyMapper(mapper("StructureMapper")):
assert transformer.transform(
parser.parse("cartesian_site_positions LENGTH 3")
) == {"nsites": 3}

assert transformer.transform(parser.parse("elements_ratios LENGTH 3")) == {
"ratios": {"$size": 3, "$exists": True}
}

assert transformer.transform(
parser.parse("cartesian_site_positions LENGTH >= 10")
) == {"nsites": {"$gte": 10}}
Expand Down

0 comments on commit 94bf368

Please sign in to comment.