-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feature/new api for model database #89
base: main
Are you sure you want to change the base?
Conversation
…ideration in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a very nice API.
Two comments:
- Please make sure that the tests can run
- Consider adding mypy to CI to verify that the type hints are correct and stays correct.
class Database: | ||
"""Represents a MIKE+ model database.""" | ||
|
||
def __init__(self, model_path: str | Path, *, auto_open: bool = True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is it useful to not open the database automatically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only if you wanted to delay making the connection for some reason. I somehow feel it might be useful for testing or some future use case, but you're right ... I can't think of a strong need for it based on how the code exists now.
Returns: | ||
List of scenario names | ||
""" | ||
return list(self._scenario_manager.GetScenarios()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This operation (and related) will fail if self._scenario_manager
is None, i.e. if the database is not opened.
As reported by mypy.
error: Item "None" of "Any | None" has no attribute "GetScenarios" [union-attr]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can certainly clean this up. I'd prefer to wait until the overall PR looks okay in design, then go back to fix these up.
Might need to ignore or remove a lot of the type hints related to pythonnet objects. I think this would require stub files for them which could be a lot of work to generate. I like having them cause it facilitates mapping it to C# code. Maybe some practical typing file for these that let us still use them as hints but ignore them?
Brief comment on the tests: they do run and pass, just not on CI. This can (partially) be fixed, although still needs to skip licensed tests which have issues I can't resolve in this PR. |
if geometry: | ||
if isinstance(geometry, str): | ||
geometry = DotNetConverter.to_dotnet_geometry(geometry) | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens here? geometry is not None, but it is not being used🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's used a few lines below by:
_, inserted_muid = net_table.InsertByCommand(
muid,
geometry,
net_values,
)
The geometry stuff hasn't been fully tested enough. There's also a need to differentiate between standard tables and geometry tables, something I hope to incorporate, but maybe as a different PR since this one is quite big already.
class UpdateQuery(BaseQuery[List[str]]): | ||
"""Query class for UPDATE operations.""" | ||
|
||
def __init__(self, table: BaseTable, values: dict[str, any]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you meant "typing.Any" instead of "any" (output from mypy)
@ryan-kipawa Should it always be from mikeplus.database import Database or from mikeplus import Database could be preferred? Additionally, would it make sense to have something similar like |
if projection_string and srid != -1: | ||
raise ValueError("Projection string and SRID cannot be specified together.") | ||
|
||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make the following script https://github.com/DHI/mikepluspy/blob/main/test_utils/database_creators.py. redundant?
"""Represents a MIKE+ model database.""" | ||
|
||
def __init__(self, model_path: str | Path, *, auto_open: bool = True): | ||
"""Initialize a new Database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should settle for Google docstring style instead of NumPy?
self.open() | ||
|
||
@classmethod | ||
def create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to have an overwrite flag?
A new fluent-like API is introduced in this PR for working with the MIKE+ database.
Main changes:
I think this structure will also allow for future extension in an easy way, since it loosely follows the MIKE+ design.
Closes:
#90
#35
#44
#27
#17
Here's a brief comparison of the old vs new API:
Opening database
Old API
New API
Querying Data
Old API
New API
Inserting Data
Old API
New API
Deleting Data
Old API
New API