Skip to content

Commit

Permalink
Adding docs for joins
Browse files Browse the repository at this point in the history
  • Loading branch information
RP-pl committed Apr 11, 2024
1 parent d531fcc commit 4914da2
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions docs/colls.rst
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,49 @@ Data manipulation
invoke(['abc', 'def', 'b'], 'find', 'b')
# ->[1, -1, 0]

.. function:: inner_join(left,right,right_column,left_column)

Returns a list of tuples of matching rows from the two tables. The tables are expected to be lists of dictionaries, and the columns are the keys in the dictionaries.

For example::

left = [{'id': 1, 'name': 'Alice'}, {'id': 2, 'name': 'Bob'}]
right = [{'id': 1, 'age': 25}, {'id': 3, 'age': 30}]
inner_join(left, right, 'id', 'id')
# -> [{'id': 1, 'name': 'Alice', 'age': 25}]

.. function:: left_join(left,right,right_column,left_column)

Returns a list of tuples of matching rows from the two tables. The tables are expected to be lists of dictionaries, and the columns are the keys in the dictionaries. If a row in the left table does not have a match in the right table, the right table columns will be omitted.

For example::

left = [{'id': 1, 'name': 'Alice'}, {'id': 2, 'name': 'Bob'}]
right = [{'id': 1, 'age': 25}, {'id': 3, 'age': 30}]
left_join(left, right, 'id', 'id')
# -> [{'id': 1, 'name': 'Alice', 'age': 25}, {'id': 2, 'name': 'Bob'}]

.. function:: right_join(left,right,right_column,left_column)

Returns a list of tuples of matching rows from the two tables. The tables are expected to be lists of dictionaries, and the columns are the keys in the dictionaries. If a row in the right table does not have a match in the left table, the left table columns will be omitted.

For example::

left = [{'id': 1, 'name': 'Alice'}, {'id': 2, 'name': 'Bob'}]
right = [{'id': 1, 'age': 25}, {'id': 3, 'age': 30}]
right_join(left, right, 'id', 'id')
# -> [{'id': 1, 'name': 'Alice', 'age': 25}, {'id': 3, 'age': 30}]

.. function:: full_join(left,right,right_column,left_column)

Returns a list of tuples of matching rows from the two tables. The tables are expected to be lists of dictionaries, and the columns are the keys in the dictionaries. If a row in the left table does not have a match in the right table, the right table columns will be omitted. If a row in any of the tables does not have a match in the other table, the columns from the other table will be omitted.

For example::

left = [{'id': 1, 'name': 'Alice'}, {'id': 2, 'name': 'Bob'}]
right = [{'id': 1, 'age': 25}, {'id': 3, 'age': 30}]
full_join(left, right, 'id', 'id')
# -> [{'id': 1, 'name': 'Alice', 'age': 25}, {'id': 2, 'name': 'Bob'}, {'id': 3, 'age': 30}]

Content tests
-------------
Expand Down

0 comments on commit 4914da2

Please sign in to comment.