Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New DataRequest #81

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

New DataRequest #81

wants to merge 3 commits into from

Conversation

pgierz
Copy link
Member

@pgierz pgierz commented Nov 29, 2024

Rework of DataRequest

This introduces new DataRequest, DataRequestVariable, and DataRequestTable classes. The old ones are copies directly from Ruby and are not very nice to work with.

Here, we implement a generic abstract base class (ABC) for DataRequestVariable. This allows us to define how a DataRequestVariable should look like from the pymorize Python side, without caring about how the information is ultimately extracted from the JSON tables. CMIP6DataRequestVariable is the first direct implementation used for JSON tables. This has the key feature of allowing us to be flexible when new CMIP standards inevitably come out, for example with CMIP7.

A DataRequestVariable therefore must implement certain properties and methods to be correctly recognised, otherwise you get Python TypeErrors when subclassing.

TODO List

  • DataRequestVariable (and concrete CMIP6DataRequestVariable)
  • DataRequestTable (and concrete CMIP6DataRequestTable, specifically CMIP6JSONDataRequestTable -- yes, I want to build two subclass levels here, since it might happen in the future that the source of the DataRequestTable isn't a JSON file. Maybe it's a HTTP request. Maybe it's a post-it note on the coffee machine. I don't know)
  • DataRequest (maybe named DataRequestCollection?) -- some gathering of various Variables and/or Tables into a bundle.
  • Rework all the tests

Still to come

  • Integration of @siligam's FlatTable design (those parts that fit together with this)

Copilot Summary

This pull request introduces a new abstract base class DataRequestVariable and its concrete implementation CMIP6DataRequestVariable in the src/pymorize/data_request/variable.py file. Additionally, it includes a unit test for the CMIP6DataRequestVariable class in tests/unit/test_drv.py.

Key changes include:

New Class Definitions:

  • src/pymorize/data_request/variable.py:
    • Added DataRequestVariable abstract base class with various properties and methods to define a generic data request variable.
    • Added CMIP6DataRequestVariable class as a concrete implementation of DataRequestVariable for CMIP6 variables, utilizing the dataclass decorator for automatic method generation.
    • Implemented class methods for constructing instances from dictionaries and JSON files, and methods for converting instances to dictionary representations.

Unit Testing:

  • tests/unit/test_drv.py:
    • Added a test case to verify the creation of a CMIP6DataRequestVariable instance from a CMIP6 JSON table file.

This commit introduces the `DataRequestVariable` abstract base class and
its concrete implementation `CMIP6DataRequestVariable`. The new classes
use the `dataclass` decorator to automatically generate special methods
like `__init__` and `__repr__`.

The `DataRequestVariable` class outlines the necessary properties and
methods that any variable class should implement. The
`CMIP6DataRequestVariable` class is a concrete implementation for CMIP6
variables.

Additionally, this commit includes methods for constructing
`DataRequestVariable` instances from dictionaries and JSON files, as
well as converting instances to dictionary representations.

Unit tests for `CMIP6DataRequestVariable` have been added to ensure
correct functionality.
@pgierz pgierz requested a review from siligam November 29, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant