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

[Feature Request]: a .to_dict() method #134

Closed
1 task done
JoFrhwld opened this issue Nov 10, 2023 · 2 comments
Closed
1 task done

[Feature Request]: a .to_dict() method #134

JoFrhwld opened this issue Nov 10, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@JoFrhwld
Copy link
Member

What feature would you like added?

It would be great if most objects had a cascading .to_dict() method, a lot like the .get_intervals_at_time() method. Here's a sketch of the idea

Sequence*

For Sequence objects, minimally

def to_dict(self):
  out_dict = {
    'label': self.label,
    'start': self.start,
    # if point
    # 'time': self.time,
    'end': self.end,
    'entry_class' : self.entry_class.__name__,
    'superset_class': self.superset_class.__name__,
    'subset_class': self.subset_class.__name__,
    # if ids implemented
    'id' : self.id,
    'fol_id': self.fol.id,
    'prev_id': self.prev.id,
    'subset_ids': self.subset_list_ids,
  }
  return out_dict

For Tiers

def to_dict(self):
  out_dict = {
    'name': self.name,
    'entry_class': self.entry_class.__name__,
    'superset_class': self.superset_class.__name__,
    'subset_class': self.subset_class.__name__,
    'entries' : [x.to_dict() for x in self.sequence_list],
    # if ids implemented
    'id' : self.id
  }
  return out_dict

For TierGroups

def to_dict(self):
  out_dict = {
    'tiers': [x.to_dict for x in self.tiers]
    # if ids implemented
    'id': self.id
  }
  return out_dict

For TextGrids

def to_dict(self):
  out_dict = {
    'tier_groups': [x.to_dict for x in self.tier_groups]
    # if ids implemented
    'id': self.id
  }

What would the use case be for this feature?

dictifying will probably make things like writing to a dataframe (#50) or some other output (#23), since I believe the data frame, yaml, and json packages have well defined methods for processing dicts.

Would you like to help add this feature?

Yes, and I will submit a pull request soon.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@JoFrhwld JoFrhwld added the enhancement New feature or request label Nov 10, 2023
@JoFrhwld JoFrhwld added this to the v0.5.0 milestone Nov 10, 2023
@JoFrhwld
Copy link
Member Author

Discussion in #133 about ids is relevant.

@JoFrhwld
Copy link
Member Author

Seems redundant wrt to dataframe output #148

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants