Skip to content

Commit

Permalink
fix: Use the correct parent table if scope is not set, closes #61
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jun 29, 2022
1 parent 7debc42 commit a7c0936
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
28 changes: 20 additions & 8 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,30 @@ Changelog
Changed
~~~~~~~

- :func:`~ocdskingfishercolab.save_dataframe_to_sheet` and :func:`~ocdskingfishercolab.save_dataframe_to_spreadsheet` do nothing if the data frame is empty.
- :func:`~ocdskingfishercolab.calculate_coverage`: Rename keyword arguments from ``sql`` to ``print_sql`` and ``sql_only`` to ``return_sql``.
- :func:`~ocdskingfishercolab.calculate_coverage`: Simplify the query if ``"ALL "`` is prefixed to a field that is not within an array.
- :func:`~ocdskingfishercolab.calculate_coverage`: Raise an error if no ``fields`` are provided.
- :func:`~ocdskingfishercolab.save_dataframe_to_sheet` and :func:`~ocdskingfishercolab.save_dataframe_to_spreadsheet` do nothing if the data frame is empty. :commit:`9b83348`
- :func:`~ocdskingfishercolab.calculate_coverage`: Rename keyword arguments from ``sql`` to ``print_sql`` and ``sql_only`` to ``return_sql``. :commit:`d706145`
- :func:`~ocdskingfishercolab.calculate_coverage`: Simplify the query if ``"ALL "`` is prefixed to a field that is not within an array. :commit:`869a9d0`
- :func:`~ocdskingfishercolab.calculate_coverage`: Raise an error if no ``fields`` are provided. :commit:`8896336`

Fixed
~~~~~

- :func:`~ocdskingfishercolab.calculate_coverage`: Construct correct conditions and warnings if a field is within nested arrays.
- :func:`~ocdskingfishercolab.calculate_coverage`: Use the ``relatedprocesses_summary`` table for fields starting with ``relatedProcesses/``, where appropriate.
- :func:`~ocdskingfishercolab.calculate_coverage`: Prefix ``all_`` to the column if ``"ALL "`` is prefixed to the field, to avoid duplicate columns.
- :func:`~ocdskingfishercolab.calculate_coverage`: No longer warn about ``address`` fields.
- :func:`~ocdskingfishercolab.calculate_coverage`: Use the correct parent table if ``scope`` is not set. Previously, Kingfisher Colab would not use:

- ``award_documents``
- ``award_items``
- ``award_suppliers``
- ``contract_documents``
- ``contract_items``
- ``contract_milestones``
- ``contract_implementation_documents``
- ``contract_implementation_milestones``
- ``contract_implementation_transactions``

- :func:`~ocdskingfishercolab.calculate_coverage`: Construct correct conditions and warnings if a field is within nested arrays. :commit:`3dced1a`
- :func:`~ocdskingfishercolab.calculate_coverage`: Use the ``relatedprocesses_summary`` table for fields starting with ``relatedProcesses/``, where appropriate. :commit:`9e6cdb7`
- :func:`~ocdskingfishercolab.calculate_coverage`: Prefix ``all_`` to the column if ``"ALL "`` is prefixed to the field, to avoid duplicate columns. :commit:`e9427b2`
- :func:`~ocdskingfishercolab.calculate_coverage`: No longer warn about ``address`` fields. :commit:`e2b8d72`

0.3.8 (2022-04-27)
------------------
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
}

extlinks = {
"commit": ("https://github.com/open-contracting/kingfisher-colab/commit/%s", "%s"),
"ipython-sql": (
"https://github.com/catherinedevlin/ipython-sql/blob/b24ac6e9410416eafde86ae22fd8d6f34acbe05d/%s", None),
}
11 changes: 10 additions & 1 deletion ocdskingfishercolab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,24 @@ def calculate_coverage(fields, scope=None, print_sql=True, return_sql=False):
:rtype: pandas.DataFrame or sql.run.ResultSet
"""

head_replacements = {
"awards": "award",
"contracts": "contract",
}

def get_table_and_pointer(tables, pointer):
parts = pointer.split("/")
table = "release_summary"

# Abbreviate absolute pointers to relative pointers if the pointer is on the scope table.
# For example: "awards/date" to "date" if the scope is "awards_summary."
for i in range(len(parts), 0, -1):
head = parts[0]
# Kingfisher Summarize uses the singular prefixes "award_" and "contract_".
if i > 1:
head = head_replacements.get(head, head)
# Kingfisher Summarize tables are lowercase.
candidate = f"{'_'.join(parts[:i])}_summary".lower()
candidate = f"{'_'.join([head] + parts[1:i])}_summary".lower()
if candidate in tables:
parts = parts[i:]
table = candidate
Expand Down
4 changes: 2 additions & 2 deletions tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ def test_calculate_coverage_join_release_summary(db, tmpdir):
('awards/date', 'date', 'awards_summary'),
('tender/documents/format', 'format', 'tender_documents_summary'),
('relatedProcesses/relationship', 'relationship', 'relatedprocesses_summary'),
# See https://github.com/open-contracting/kingfisher-colab/issues/61
('awards/items/quantity', 'items/quantity', 'awards_summary'),
('awards/items/quantity', 'quantity', 'award_items_summary'),
('contracts/implementation/documents/format', 'format', 'contract_implementation_documents_summary'),
])
def test_calculate_coverage_default_scope(field, pointer, table, db, tmpdir):
sql = calculate_coverage([field], return_sql=True)
Expand Down

0 comments on commit a7c0936

Please sign in to comment.