-
Notifications
You must be signed in to change notification settings - Fork 25
feat: metadata and __slots__ #403
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
Conversation
|
@HDembinski, I still need to add tests and make a few changes, but see what you think of this. It's roughly based on your idea in #400. Axes simulate ax = Boolean(metadata={"title": "Hello", "name": "hello"})
assert ax.title == "Hello"
assert ax.name == "hello"
ax.label = "world"
assert ax.metadata == {"title: "Hello", "name": "hello", "label": "world"}For backward compatibility, we still support non-dict metadata - it just disables the set/get via attributes. If the metadata is None, it will become a dict when you try to set it via attributes. Tab completion in IPython, etc. works. Since this is still in the C++ axes, it caries through slicing or any other axes modifying operation. If the metadata is not "nice", that is, not a string or the same name as a property, you need to use the metadata syntax to access it. Histograms actually uses What do you think? |
|
Note that with this, we can provide the same API into Hist as boost-histogram. Hist will simply provide extra meaning/checks on some metadata items like The current metadata keyword is just a way for uproot, etc. to prepopulate the metadata when it makes the histogram/axes. We could also populate metadata from |
|
We could go the other way too, I think - use the axes |
aa1dfa6 to
390e057
Compare
|
Lesson: always remember to rebase... So, here are the options as I see them:
Personally, I think I like either option 1 (simple, forward compatible) or option 2 without option 2.a best. I think option 2 is most natural for tools (Uproot, hist, etc) to attach arbitrary metadata, but still provides reasonable access to it and behave like a normal Whatever we do, we should do something externally similar for both Histogram / Axis. @HDembinski, your call. |
|
Thank you for listing all these options. I see you spend a good amount of research on this. It is not an easy choice, but after reading all that I am swayed to option 1. Funneling everything through the ".metadata" attribute has a centain appeal and then we can keep |
|
Okay, that's also the simplest/cleanest option. I'll prepare it. |
This supports .metadata being propagated through the histogram, and adds
__slots__.