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

Allow units to be defined by bytes #54

Closed
davidhassell opened this issue Jan 30, 2024 · 0 comments · Fixed by #55
Closed

Allow units to be defined by bytes #54

davidhassell opened this issue Jan 30, 2024 · 0 comments · Fixed by #55
Labels
enhancement New feature or request
Milestone

Comments

@davidhassell
Copy link
Contributor

davidhassell commented Jan 30, 2024

Currently (v3.3.6), a Units instance cannot be defined by bytes:

>>> from cfunits import Units
>>> Units('m')  # Initialize with str: OK
<Units: m>
>>> Units(b'm')  # Initialize with bytes: NOT OK
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[5], line 1
----> 1 Units(b'm')

File ~/miniconda3/lib/python3.11/site-packages/cfunits/units.py:805, in Units.__init__(self, units, calendar, formatted, names, definition, _ut_unit)
    802 ut_unit = _cached_ut_unit.get(units, None)
    803 if ut_unit is None:
    804     ut_unit = _ut_parse(
--> 805         _ut_system, _c_char_p(units.encode("utf-8")), _UT_ASCII
    806     )
    807     if not ut_unit:
    808         ut_unit = None

AttributeError: 'bytes' object has no attribute 'encode'

>>>

It would be good to fix this!

@davidhassell davidhassell added the enhancement New feature or request label Jan 30, 2024
@davidhassell davidhassell added this to the 3.3.7 milestone Jan 30, 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 a pull request may close this issue.

1 participant