question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: User control for argument default values

See original GitHub issue

I think it would be nice if it was possible to do:

with h5py.File(pth, "w") as f, h5py.defaults(compression="lzf", chunks=True):
    f["X"] = X
    f["Y"] = Y
    with h5py.defaults(maxshape=None):
        f["foo/Z"] = Z

Instead of

with h5py.File(pth, "w") as f:
    f.create_dataset("X", data=X, compression="lzf", chunks=True)
    f.create_dataset("Y", data=Y, compression="lzf", chunks=True)
    f.create_dataset("foo/Z", data=Z, compression="lzf", chunks=True, maxshape=None)

The second is much more verbose, and makes it much easier to forget to pass some kwargs (which inspired this 😊).

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
takluyvercommented, Dec 24, 2020

I’d prefer not to expand the use of the global config for this kind of thing. I don’t think it’s a particularly good API - but it smooths over things like how we represent types that HDF5 can’t natively store (complex & bool) and changing default settings with a deprecation cycle. I’m not convinced it’s a good idea for track_order, and I don’t think the fact that we already have some global mutable state should set a precedent that we should have more.

I’d still like to make the case for doing this with some flavour of the GroupMapWrap or DefaultSetter idea, without using any extra mutable state. @ivirshup , can you go into more detail about what was ‘weird’ when you tried this?

1reaction
tacaswellcommented, Dec 22, 2020

since that’s been very useful for modifying aspects of figures generated by code I don’t control

That is exactly the spooky action-at-a-distance @takluyver is concerned about. My concern about global state for this sort of thing is driven by being on the developer side of mpl.rcParams!

I think the order of operations here:

  1. add a ‘default_group_kwargs’ and default_ds_kwargs state to h5py._hl.group.Group object. These should propogate down to sub-groups opened / created from their parent.
  2. add a context manager to Group to set / unset defaults
  3. make the case that File should consult global state to get its initial default values

I think 1. addresses most of @ivirshup initial request using only “local” state. So long as you can pass an h5py object into the third-party code it also catches that case (which I hope is most but I know not all casse). 2. is a nice API (and light weight to implement). 3. is the action-at-a-distance that I see the case for, but do not like (would rather ask you to push on the third party code to either take a Group or at least kwargs to pass to File along with the filename to make use of 1.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

documenting default argument values · Issue #819 · r-lib ...
Is there any possibility that roxygen2 can automatically add the default values for function arguments in the .Rd files?
Read more >
Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >
Can I give a default value to parameters or optional ...
Yes, but you'll need to be using .NET 3.5 and C# 4.0 to get this functionality.
Read more >
Dynamic default values on user input controls
Need the ability to set the default value of a user input control to something dynamic. In my case, I'm creating a date...
Read more >
Creating parameter defaults in Amazon QuickSight
If there are multiple values a default field for a user entity, the single-value control for that field displays the static default instead....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found