Skip to content

Allow users to add custom units #58#59

Open
rju wants to merge 8 commits intoNCAS-CMS:mainfrom
rju:add-special-units
Open

Allow users to add custom units #58#59
rju wants to merge 8 commits intoNCAS-CMS:mainfrom
rju:add-special-units

Conversation

@rju
Copy link
Copy Markdown

@rju rju commented Dec 18, 2025

This pull request adds the feature to add custom units programmatically. See also #58

Reiner Jung added 2 commits October 14, 2025 10:15
especially with countable amounts, like currency, cups etc. they are not
interchangable and units can be used to distinguish them.
Copy link
Copy Markdown
Contributor

@davidhassell davidhassell left a comment

Choose a reason for hiding this comment

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

Hi @rju,

Thank you! I've make some suggestions/asked some questions, but it looks good and works as far as I can tell by playing on the command line (the proper units test will tell all :)).

Would you like add yourself as a contributor at docs/source/contributing.rst?

return out.decode("utf-8")

@classmethod
def new_unit(cls, name):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doc string please!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've added documentation in my branch.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

In case this is sufficient, please resolve the conversation.

cf_test.py Outdated
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be possible to recast this a new method in cfunits.cfunits.test.UnitsTest?

The tests need be framed with self.ssertTrue, self.assertFalse, self.assertEqual, etc.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've added a test in UnitsTest checking only the custom unit feature. And removed cf_test.py

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

In case this is sufficient, please resolve the conversation.

@davidhassell davidhassell linked an issue Jan 8, 2026 that may be closed by this pull request
rju and others added 3 commits February 22, 2026 16:11
Co-authored-by: David Hassell <davidhassell@users.noreply.github.com>
Co-authored-by: David Hassell <davidhassell@users.noreply.github.com>
Added comment / documentation to new_unit
@rju
Copy link
Copy Markdown
Author

rju commented Feb 22, 2026

I hope the test is sufficient.

@rju rju requested a review from davidhassell March 16, 2026 07:19
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.

Allow users to add custom units

2 participants