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

Support h5py-like objects #10

Open
vallsv opened this issue Apr 16, 2019 · 4 comments
Open

Support h5py-like objects #10

vallsv opened this issue Apr 16, 2019 · 4 comments

Comments

@vallsv
Copy link
Contributor

vallsv commented Apr 16, 2019

Hi,

I would like to know if you want to support h5py-like API.

For example it could be used to display data from h5pyd, exdir or our silx project.

There is maybe a convenient way to check if an object is a file, a group or a dataset. Maybe a patch to apply to h5py. Do you have any idea?

@takluyver
Copy link
Member

I'd be open to supporting other similar interfaces with a couple of significant conditions:

  • It shouldn't make it a worse tool for HDF5/h5py objects. 'Worse' in this case includes making the output vaguer or less clear to account for other libraries or formats. It also covers making it slower or depending on extra non-trivial packages.
  • It shouldn't make the code significantly more complex. I can't precisely define 'significantly' there, but I'll know it when I see it. 😉

If you think it's feasible to support other packages within those constraints, PRs welcome. I suspect it's probably feasible so long as they have a very similar set of features, but I don't know how similar they are. If not, you are of course welcome to reuse parts of the code to build similar tools for other purposes.

@vallsv
Copy link
Contributor Author

vallsv commented Apr 16, 2019

  • On silx we are using obj.h5_class() that returns the h5py class.
  • For h5pyd we have to check a specific class
  • On exdir, i don't know.

The result is not very convenient cause it enforce dependency to third party libraries.

  • A solution could be to ask h5py to add pure interface inheritance to it's objects, interface that could be reused by third party library (which enforce a dependency to from third party library to h5py).
  • Another solution could be to ask to implement an API like is_dataset, is_file, is_group for each objects. Or an h5_class returning a string (group, dataset, file).

I will check what i can do, maybe with h5pyd, to check. We have code which deal with it on https://github.com/silx-kit/silx/blob/master/silx/io/__init__.py

@takluyver
Copy link
Member

IPython's pretty-printing has a mechanism for registering classes by module name and class name, to avoid having to import them. It's a bit more work to check objects against this allowing for subclasses, but it might be something we could use here.

Here's the core of the lookup code in IPython ('deferred' in this module means deferred import, i.e. referenced by name):

https://github.com/ipython/ipython/blob/4f901de17aff2132365fc3741fc5b4b8a9a98dc6/IPython/lib/pretty.py#L409-L425

@vallsv
Copy link
Contributor Author

vallsv commented Apr 16, 2019

Here is a proposal #11. Maybe it is close to the same as what you was thinking about.

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

No branches or pull requests

2 participants