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

Add new dunder methods and attributes #27

Merged
merged 15 commits into from
Sep 18, 2024
Merged

Add new dunder methods and attributes #27

merged 15 commits into from
Sep 18, 2024

Conversation

Adamtaranto
Copy link
Collaborator

New dunder methods for more Pythonic interaction:

  • Make KmerCountTable iterable, returns (hash,count) tuples.
  • Add __setitem__, Set values using the indexing syntax obj[key] = value
  • Add __getitem__, Query an object to using the indexing syntax obj[key]
  • Add len() method, returns number of keys in KmerCountTable.

New attributes:

  • .version, returns oxli version that object was created with (will use later when serialising objects)
  • .consumed, returns total number of bases consumed using either count() or consume()
  • .sum_counts, returns sum total of all counts in table.

Note: Have added "toml" package as a conditional dependency for testing .version.
It is in pyproject.toml under optional dependencies. Will be installed if installing oxli from repo via pip install -e .[test]

Closes #20

@Adamtaranto Adamtaranto added the enhancement New feature or request label Sep 14, 2024
@Adamtaranto Adamtaranto requested a review from ctb September 15, 2024 00:38
Copy link
Contributor

@ctb ctb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! A few suggestions here: #34

Is there a reason to use the external toml library rather than the builtin Python toml library, tomllib?

* Bump anyhow from 1.0.87 to 1.0.89 (#33)

Bumps [anyhow](https://github.com/dtolnay/anyhow) from 1.0.87 to 1.0.89.
- [Release notes](https://github.com/dtolnay/anyhow/releases)
- [Commits](dtolnay/anyhow@1.0.87...1.0.89)

---
updated-dependencies:
- dependency-name: anyhow
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump pyo3 from 0.22.2 to 0.22.3 (#32)

Bumps [pyo3](https://github.com/pyo3/pyo3) from 0.22.2 to 0.22.3.
- [Release notes](https://github.com/pyo3/pyo3/releases)
- [Changelog](https://github.com/PyO3/pyo3/blob/v0.22.3/CHANGELOG.md)
- [Commits](PyO3/pyo3@v0.22.2...v0.22.3)

---
updated-dependencies:
- dependency-name: pyo3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* pass thru errors; remove clone

* cargo fmt

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@Adamtaranto
Copy link
Collaborator Author

Was using toml library because I didn't know about tomllib. Will look into it.

@Adamtaranto
Copy link
Collaborator Author

@ctb Looks like tomllib was introduced in Python 3.11.

Do we want 3.11 to be the min version required for this package? or keep the external toml import?

I'm going to leave it for now and merge this branch. Can update later.

@Adamtaranto Adamtaranto merged commit 373bef3 into main Sep 18, 2024
13 checks passed
@Adamtaranto Adamtaranto deleted the dev_pymethods branch September 18, 2024 02:22
@ctb ctb mentioned this pull request Sep 23, 2024
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

Successfully merging this pull request may close these issues.

Add __len__ and __iter__ methods
2 participants