Skip to content

Metadata can appear to be set directly, but doesn't work: unfriendly to the user  #993

Closed as not planned

Description

@hyanwong

I see that it looks like I can set metadata properties after creating them, but it doesn't actually update the metadata. I think it should either work, or we should raise an error if possible:

tables = tskit.TableCollection(1)
tables.metadata_schema = tskit.MetadataSchema({"codec":"json"})
tables.metadata = {'foo': {}}
tables.metadata['foo']['bar']=20
ts = tables.tree_sequence()
print(ts.metadata['foo']) # doesn't return 20

Activity

  1. jeromekelleher commented on Nov 13, 2020

    @jeromekelleher
    Member

    Thoughts @benjeffery?

  2. benjeffery commented on Nov 13, 2020

    @benjeffery
    Member

    Tough one this as supporting the assignment (recursively) is not that simple, possible though I assume. We could return a frozendict, but would need a nice error message. I'll look into supporting the assignment, if it gets too hairy (for example should `del tc.metadata['foo']['bar'] work?) I'll try freezing.

  3. added
    enhancement
    Python API
    on Nov 13, 2020
  4. added this to the Python upcoming milestone on Nov 13, 2020
  5. jeromekelleher commented on Nov 13, 2020

    @jeromekelleher
    Member

    I'd say a frozendict would be a good first step - actual assigmnent will be hairy and would need some more low-level infrastructure for setting values in rows.

  6. benjeffery commented on Nov 13, 2020

    @benjeffery
    Member

    Ah, yes. I'd only considered the ts-level case.

  7. hyanwong commented on Nov 13, 2020

    @hyanwong
    MemberAuthor

    Making it read-only would be fine, IMO.

  8. petrelharp commented on Apr 14, 2025

    @petrelharp
    Contributor

    FWIW here's a situation where (I'm not sure but I suspect) things were hard to figure out for a user because it seems like you can just change metadata but it doesn't do anything: https://groups.google.com/g/slim-discuss/c/N2v0fyiYOoQ/m/pHZ9h5v0CAAJ

    A natural thing for this user to try would have been

    ts.metadata['SLiM']['separate_sexes'] = True
    # or perhaps
    tables.metadata['SLiM']['separate_sexes'] = True
    

    but those just silently do nothing.

  9. jeromekelleher commented on Apr 14, 2025

    @jeromekelleher
    Member

    Retuning a frozendict is an easy thing to do for 1.0 I think @benjeffery ?

  10. benjeffery commented on Jun 6, 2025

    @benjeffery
    Member

    Closing for #3156

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Python APIenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions