-
Notifications
You must be signed in to change notification settings - Fork 89
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
perf: improve Array initialisation performance #1700
Conversation
agoose77
commented
Sep 14, 2022
•
edited
Loading
edited
- follow up feat: raise Error for Record.__setattr__ #1699 here
Wait—are we sure that if where in dir(type(self)): is equivalent to if hasattr(type(self), where): The record fields are accessible via get-attribute (like Is this PR breaking that relationship? |
Well, this is the tricky part. This code allows the user to set existing type-declared fields, or private attributes. Otherwise, they need to be trying to set an existing field name. This seems like the right approach; we want only fields to be immutable, and we don't want fields to shadow existing Array attributes (otherwise third-party consumers of arrays might run into trouble, e.g. if the user adds a So, the specification defined here is:
So, we don't go as far as preventing records from containing private-shadowing fields (e.g. |
We were careful to make sure that it doesn't overshadow: >>> import awkward as ak
>>> array = ak._v2.Array([{"fields": 1, "field": 2}])
>>> array.fields
['fields', 'field']
>>> array.field
<Array [2] type='1 * int64'> This is in the order of tests in awkward/src/awkward/_v2/highlevel.py Lines 1098 to 1112 in b5545a8
(We're taking advantage of the difference between |
Yes, indeed. What I mean here is that we don't do any validation at any stage to prevent this, we just implement the get/set behaviour such that users can't break anything. That means in this context, setting an attribute always succeeds if it's the name of an |
9ea085d
to
c201a1e
Compare
Okay, we're in agreement about what it's supposed to do. When the dust settles, let's just make sure that all of your bullet points in #1700 (comment) are still satisfied. |
Codecov Report
Additional details and impacted files
|
So, the specification defined here is: - allow users to write to the private attributes (`_XXX`), which are prohibited by convention for external use - allow users to write to public type-level attributes (including attributes that override the `ak.Array` attributes, e.g. if a user defined their own behavior with `def fields`). Users should not do this, rather than us trying to validate things? - prevent users from writing any other fields
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.
The tests check all the cases I was worried about. Someone might want to set
record.x = 10
expecting the 10
to be broadcasted over the array, but the error message is right in saying that they have to
record["x"] = 10
It's also correct that Array and Record subclasses can override these.
So this is an approval; go ahead and merge! If I don't hear back, I'll "update branch" and "enable auto-merge (squash)", to do extra testing and give about 10 minutes to intercept, if you have something else to add. |