Skip to content

Commit

Permalink
119 fix aliases declaration in pipeline methods (#120)
Browse files Browse the repository at this point in the history
* fixed aliases issue in pipeline methods.

* sync docstrings in pipeline methods and stages classes.
  • Loading branch information
OlivierLegrand committed Apr 23, 2024
1 parent 23b08fa commit 733c372
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
39 changes: 24 additions & 15 deletions src/monggregate/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ def bucket(self, *, boundaries:list, by:Any=None, group_by:Any=None, default:Any
self.stages.append(
Bucket(
by = by or group_by,
#group_by = group_by or by,
boundaries = boundaries,
default = default,
output = output
Expand Down Expand Up @@ -372,7 +371,6 @@ def bucket_auto(self, *, by:Any=None, group_by:Any=None, buckets:int, output:dic
self.stages.append(
BucketAuto(
by = by or group_by,
#group_by = group_by,
buckets = buckets,
output = output,
granularity = granularity
Expand Down Expand Up @@ -438,9 +436,9 @@ def explode(self, \

self.stages.append(
Unwind(
path=path,
path_to_array=path_to_array or path,
include_array_index=include_array_index,
always=always
always=always or preserve_null_and_empty_arrays
)
)
return self
Expand All @@ -453,7 +451,7 @@ def group(self, *, by:Any|None=None, _id:Any|None=None, query:dict={})->Self:
Arguments:
------------------------
- by, str | list[str] | set[str] | dict | None : field or group of fields to group by
- by (_id), str | list[str] | set[str] | dict | None : field or group of fields to group by
- query, dict | None : Computed aggregated values (per group)
Online MongoDB documentation:
Expand All @@ -475,7 +473,7 @@ def group(self, *, by:Any|None=None, _id:Any|None=None, query:dict={})->Self:

self.stages.append(
Group(
by=by,
by=by or _id,
query=query
)
)
Expand Down Expand Up @@ -568,9 +566,9 @@ def lookup(self, *, \
Lookup(
right = right,
on = on,
left_on = left_on,
right_on = right_on,
name =name
left_on = left_on or local_field,
right_on = right_on or foreign_field,
name = name
)
)
return self
Expand Down Expand Up @@ -713,7 +711,10 @@ def match(self, query:dict={}, expression:Any=None, **kwargs:Any)->Self:

query = query | kwargs
self.stages.append(
Match(query=query, expression=expression)
Match(
query=query,
expression=expression
)
)
return self

Expand Down Expand Up @@ -797,7 +798,7 @@ def replace_root(self, path:str|None=None, path_to_new_root:str|None=None, *,doc
-------------------------------------
- statement, dict : the statement generated during instantiation after parsing the other arguments
- path_to_new_root, str|None : the path to the embedded document to be promoted
- path_to_new_root (path), str|None : the path to the embedded document to be promoted
- document, dict|None : document being created and to be set as the new root or expression
Online MongoDB documentation:
Expand All @@ -814,7 +815,10 @@ def replace_root(self, path:str|None=None, path_to_new_root:str|None=None, *,doc
"""

self.stages.append(
ReplaceRoot(path=path, document=document)
ReplaceRoot(
path=path or path_to_new_root,
document=document
)
)
return self

Expand All @@ -826,7 +830,7 @@ def replace_with(self, path:str|None=None, path_to_new_root:str|None=None, *,doc
-------------------------------------
- statement, dict : the statement generated during instantiation after parsing the other arguments
- path_to_new_root, str|None : the path to the embedded document to be promoted
- path_to_new_root (path), str|None : the path to the embedded document to be promoted
- document, dict|None : document being created and to be set as the new root or expression
Online MongoDB documentation:
Expand All @@ -843,7 +847,10 @@ def replace_with(self, path:str|None=None, path_to_new_root:str|None=None, *,doc
"""

self.stages.append(
ReplaceRoot(path=path, document=document)
ReplaceRoot(
path=path or path_to_new_root,
document=document
)
)
return self

Expand Down Expand Up @@ -1376,7 +1383,9 @@ def union_with(self, collection:str, coll:str, pipeline:list[dict]|None=None)->S
"""

self.stages.append(
UnionWith(collection=collection, pipeline=pipeline)
UnionWith(
collection=collection or coll,
pipeline=pipeline)
)

return self
Expand Down
2 changes: 1 addition & 1 deletion src/monggregate/stages/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Group(Stage):
Attributes:
-----------
- by, str | list[str] | set[str] | dict | None : field or group of fields to group by
- by (_id), str | list[str] | set[str] | dict | None : field or group of fields to group by
- query, dict | None : Computed aggregated values (per group)
Online MongoDB documentation:
Expand Down
2 changes: 1 addition & 1 deletion src/monggregate/stages/replace_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ReplaceRoot(Stage):
-----------
- statement, dict : the statement generated during instantiation after parsing the other arguments
- path_to_new_root, str|None : the path to the embedded document to be promoted
- path_to_new_root (path), str|None : the path to the embedded document to be promoted
- document, dict|None : document being created and to be set as the new root or expression
Online MongoDB documentation:
Expand Down

0 comments on commit 733c372

Please sign in to comment.