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

Replace Elite and EliteBatch with dicts #397

Merged
merged 18 commits into from
Nov 3, 2023
Merged

Replace Elite and EliteBatch with dicts #397

merged 18 commits into from
Nov 3, 2023

Conversation

btjanaka
Copy link
Member

@btjanaka btjanaka commented Nov 2, 2023

Description

This PR removes the Elite and EliteBatch namedtuples from the public API; instead, we create an Elite and EliteBatch namedtuple on the fly in each archive. This allows us to support custom field names in each namedtuple in the future.

In creating this PR, I was considering whether to create a custom namedtuple for each archive (when the archive is constructed, similar to how pandas has itertuples), or to use a dict. These were the pros and cons I came up with of dicts over such namedtuples:

Pros:

  • This is clearly backwards-incompatible, so users will know something has broken. The old tuple unpacking behavior will definitely not work here, and calling the attributes also will not work.
  • Dicts are less finicky than namedtuples, in that there are no attributes to manage.
  • Dicts are already a common data structure; people already know how to get the keys etc
  • It is easier to handle retrieving just a couple of fields. In such a case, we can just add the required keys to the dict. In contrast, we would have to set some fields to None in a namedtuple
  • We no longer will have a name conflict with the index method of namedtuples

Cons:

  • The old unpacking logic will no longer work
  • Getting attributes will no longer work
  • Harder to tell which things are batch because it’s not in the name, although I think it’s usually clear from the context

TODO

  • Replace all usages
  • Double check for usage of Elite and EliteBatch

Questions

Status

  • I have read the guidelines in
    CONTRIBUTING.md
  • I have formatted my code using yapf
  • I have tested my code by running pytest
  • I have linted my code with pylint
  • I have added a one-line description of my change to the changelog in
    HISTORY.md
  • This PR is ready to go

@btjanaka btjanaka changed the title Replace Elite and EliteBatch with archive-specific namedtuples Replace Elite and EliteBatch with dicts Nov 2, 2023
@btjanaka btjanaka merged commit 22d40ce into master Nov 3, 2023
17 checks passed
@btjanaka btjanaka deleted the remove-elite branch November 3, 2023 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant