-
Notifications
You must be signed in to change notification settings - Fork 16
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
Make array
slot default false
#189
Conversation
Yes, it doesn't quite work for the reasons you state. We'd have to make the range of This isn't the first time we've run into things like this. From a pythonic POV it's frustrating not to be able to distinguish Nones, unset objects, or empty objects. One way to think about it is making the metamodel work for the broadest range of target frameworks - e.g. we want to allow people to store schemas in a relational database. |
What strategies have worked in the past for this? i'll follow your lead, maybe i should have raised this as an issue rather than a PR... |
In this particular case I don’t think it’s so bad for the schema author to
provide a slot assignment that forces an array nature such as minimum
cardinality: 1. This is perhaps odd, since zeroD arrays are prohibited it
would be semantically vapid. But I think this is more explicitl that say a
comment or other piece of metadata
…On Tue, Mar 5, 2024 at 12:46 PM Jonny Saunders ***@***.***> wrote:
What strategies have worked in the past for this? i'll follow your lead,
maybe i should have raised this as an issue rather than a PR...
—
Reply to this email directly, view it on GitHub
<#189 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAMMOLEG6BL5WB5HA6XR2TYWYVJFAVCNFSM6AAAAABEGOKVSSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZZGYYDOOBTGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Actually wait this works perfectly: sneakers-the-rat/linkml-runtime@26d2081 what we need isn't a change in the metamodel per se, but greater access to the literal representation of the underlying schema. we already have this place in the metamodel where we have a difference in meaning between I wrote that into the So this: classes:
TypedUnset:
attributes:
array:
range: integer
array:
NonArrayUnset:
attributes:
nonarray:
range: integer works like this sv = SchemaView('schema.yaml')
nonarray = nonarray = sv.get_class('NonArrayUnset').attributes['nonarray']
isarray = sv.get_class('TypedUnset').attributes['array'] >>> nonarray.array is None
True
>>> isarray.array is None
True
>>> sv.is_unset(nonarray, 'array')
True
>>> sv.is_unset(isarray, 'array')
False ezpz |
the special casing i think comes from the fact that MyClass:
attributes:
my_array:
range:
array:
range: integer which is a little more awkward but doesn't involve parsing None from unset. it's not too late to do that, and it might be the right call, but i don't have strong feelings there. In that case i guess we'd have to special case that array: {range} can't itself be an array, but that's a more hidden special case |
In my opinion, classes:
MyClass:
attributes:
my_array:
array: {} and classes:
MyClass:
attributes:
my_array:
array:
minimum_number_dimensions: 1 are a bit ugly but not so bad. I think it would not be so common that someone would want to define an any shaped array with no information about it. The one use case I have seen in NWB is a "scratch" dataset where a user can store whatever array they want, and it is up to the user to keep track of what it represents. But if we can differentiate between None and unset in code using @sneakers-the-rat 's example above, even better! |
I think of the metamodel and the resulting schemas as an interface - they are the public contract that the standard makes to the rest of the generators, transformers, etc. So to me the syntax should be designed with authorship in mind, and to make clear expectations of usage and behavior, and then we should do what we can behind the scenes to make that work, so I think the ability to differentiate between "set as None" and "unset" to be able to give a predictable, coherent interface is a challenge worth taking :). The above fix is actually "truer" to the underlying YAML representation - things being interpreted as |
it turns out this change is a great deal more difficult bc the metaclasses are already assumed to be 1:1 with the JSON/YAML for the purposes of dumping/loading by the dumpers, and the jsonasobj2 package is pretty mysterious with how to set instance-private attributes, so seems like we might need to pay some tech debt on this to implement first. edit: i got a version that works within linkml_runtime but on testing with the rest of linkml it looks like there are hundreds of places where eg. different generators iterate over |
From @cmungall : some representations, e.g., JSON-LD, cannot distinguish between unset and set to None/null, so it is not ideal to assign different meanings to those. @linkml/ndarray-wg decided that |
Problem:
the way to specify an
Any
shaped array is to do this:which rocks. The problem is that is equivalent to this from the POV of the python dataclasses:
so to make an any shaped array one has to, in practice, do something that is
False
-y but notNone
like:Similarly to the semantic difference between
None
andFalse
inmax_number_dimensions
, this PR makes the default value for thearray
slotFalse
, making it distinguishable toNone
and preserving semantics.The alternative of keeping the default
None
and making any shaped arrays beFalse
is desirable from a metamodel consistency POV, but counterintuitive - "what do you meanarray: False
means the most general array definition possible." Arguably, this is still consistent with metamodel intuition, because the default - as in "when one doesn't specify an array at all" - still means "No array," and specifyingarray: None
is an affirmative signal that we want anarray
withNone
restrictions on its shape.edit: actually now that i'm thinking about this, this also probably wouldn't work, so let's just say this issue is the "we need to figure out how to differentiate between
array: None
andarray
not being present on a class definition" PRcc @cmungall @rly