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

More informative repr's #817

Merged
merged 4 commits into from
Nov 21, 2023
Merged

More informative repr's #817

merged 4 commits into from
Nov 21, 2023

Conversation

Huite
Copy link
Contributor

@Huite Huite commented Nov 21, 2023

  • Show dataframe for TableModel
  • For NodeModel: only show not-None entries
  • For Model: show only NodeModel with any data

Fixes #809

This seems better, model shows only stuff with data:

ribasim.Model(
    filepath=WindowsPath('harm/ribasim.toml'),
    starttime=datetime.datetime(2020, 1, 1, 0, 0),
    endtime=datetime.datetime(2020, 2, 1, 0, 0),
    update_timestep=datetime.timedelta(days=1),
    relative_dir=WindowsPath('.'),
    input_dir=WindowsPath('.'),
    results_dir=WindowsPath('results'),
    network=Network(filepath, node, edge),
    results=Results(basin=WindowsPath('results/basin.arrow'), flow=WindowsPath('results/flow.arrow'), control=WindowsPath('results/control.arrow'), outstate=None, compression='zstd', compression_level=6),
    solver=Solver(algorithm='QNDF', saveat=[], adaptive=True, dt=None, dtmin=None, dtmax=None, force_dtmin=False, abstol=1e-06, reltol=1e-05, maxiters=1000000000, sparse=True, autodiff=True),
    logging=Logging(verbosity='info', timing=False),
    allocation=Allocation(timestep=None, use_allocation=False, objective_type='quadratic_relative'),
    basin=Basin(profile, state, time),
    level_boundary=LevelBoundary(static),
    manning_resistance=ManningResistance(static),
    tabulated_rating_curve=TabulatedRatingCurve(static),
)

It's also closer to the Python code representation, with the parentheses and the commas.

NodeModel instances show the members with data, e.g. model.basin:

Basin(profile, state, time)

Empty NodeModel instances are omitted from the Model overview, but can be seen, e.g. model.pump shows:

Pump()

-- which nicely matches the instantiation.

TableModel repr's show the dataframe (but with the tablename prepended for clarity):

LevelBoundary / static
   node_id active  level remarks
0        1   None   7.15     

Also for the HTML repr:

image

I've removed the < > around the types. They weren't very consistent to begin with. I originally took inspiration from xarray, but xarray doesn't use the brackets very consistently either in their repr's.

* Show dataframe for TableModel
* For NodeModel: only show not-None entries
* For Model: show only NodeModel with any data
@Huite Huite requested a review from evetion November 21, 2023 15:54
@Huite Huite requested a review from Hofer-Julian November 21, 2023 16:00
Copy link
Contributor

@Hofer-Julian Hofer-Julian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@Huite Huite merged commit 0205f96 into main Nov 21, 2023
10 checks passed
@Huite Huite deleted the repr branch November 21, 2023 16:09
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.

Discuss __repr__ in ribasim Python
2 participants