-
Notifications
You must be signed in to change notification settings - Fork 48
Closed
Labels
New: IssueHighlight a new community raised "generic" issueHighlight a new community raised "generic" issueType: Bugcommunity
Description
🐛 Bug Report
cf_units fails to import when the LC_NUMERIC environmental variable is set to a locale that has a , instead of a . as the decimal_point character and Python sets the locale. This typically happens in documentation builds with sphinx. See pydata/xarray#4257 for an example. I have encountered the same issue when building the iris and ESMValCore documentation.
How to Reproduce
Steps to reproduce the behaviour:
- Run
export LC_NUMERIC=nl_NL.UTF-8 - View locale settings by running
locale:
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=nl_NL.UTF-8
LC_TIME=nl_NL.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=nl_NL.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=nl_NL.UTF-8
LC_NAME=nl_NL.UTF-8
LC_ADDRESS=nl_NL.UTF-8
LC_TELEPHONE=nl_NL.UTF-8
LC_MEASUREMENT=nl_NL.UTF-8
LC_IDENTIFICATION=nl_NL.UTF-8
LC_ALL=
Run the following Python code to set the locale
import locale
locale.setlocale(locale.LC_ALL, '')
import cf_units- Resulting stack trace:
Traceback (most recent call last):
File "/home/bandela/src/scitools/cf_units/cf_units/__init__.py", line 187, in <module>
_ud_system = _ud.read_xml()
^^^^^^^^^^^^^^
File "cf_units/_udunits2.pyx", line 194, in cf_units._udunits2.read_xml
return wrap_system(csystem)
File "cf_units/_udunits2.pyx", line 104, in cf_units._udunits2.wrap_system
_raise_error()
File "cf_units/_udunits2.pyx", line 184, in cf_units._udunits2._raise_error
raise UdunitsError(status, errnum)
cf_units._udunits2.UdunitsError: UT_PARSE
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/bandela/src/scitools/cf_units/cf_units/__init__.py", line 190, in <module>
_ud_system = _ud.read_xml(config.get_xml_path())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "cf_units/_udunits2.pyx", line 194, in cf_units._udunits2.read_xml
return wrap_system(csystem)
File "cf_units/_udunits2.pyx", line 104, in cf_units._udunits2.wrap_system
_raise_error()
File "cf_units/_udunits2.pyx", line 184, in cf_units._udunits2._raise_error
raise UdunitsError(status, errnum)
cf_units._udunits2.UdunitsError: UT_PARSE
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/bandela/src/scitools/cf_units/test.py", line 4, in <module>
import cf_units
File "/home/bandela/src/scitools/cf_units/cf_units/__init__.py", line 193, in <module>
raise OSError(
OSError: [UT_PARSE] Failed to open UDUNITS-2 XML unit database
Expected Behaviour
A successful import.
Environment
- OS & Version: Ubuntu 24.04 LTS
- cf-units Version: 3.2.1.dev57
Additional Context
When I comment out the suppress_warnings context manager here
Line 182 in f57a7f1
| with suppress_errors(): |
I see the following error message:
Invalid numeric prefix value ".1"
parsing aborted
File "/home/bandela/mambaforge/envs/cf-units-dev/share/udunits/udunits2-prefixes.xml", line 43, column 25
parsing aborted
File "/home/bandela/mambaforge/envs/cf-units-dev/share/udunits/udunits2.xml", line 11, column 42
Traceback (most recent call last):
File "/home/bandela/src/scitools/cf_units/test.py", line 4, in <module>
import cf_units
File "/home/bandela/src/scitools/cf_units/cf_units/__init__.py", line 187, in <module>
_ud_system = _ud.read_xml()
^^^^^^^^^^^^^^
File "cf_units/_udunits2.pyx", line 194, in cf_units._udunits2.read_xml
return wrap_system(csystem)
File "cf_units/_udunits2.pyx", line 104, in cf_units._udunits2.wrap_system
_raise_error()
File "cf_units/_udunits2.pyx", line 184, in cf_units._udunits2._raise_error
raise UdunitsError(status, errnum)
cf_units._udunits2.UdunitsError: UT_PARSE
some searching trough the udunits2 code suggests that it originates from using the strtod function in this code, which uses the decimal-point locale setting.
Metadata
Metadata
Assignees
Labels
New: IssueHighlight a new community raised "generic" issueHighlight a new community raised "generic" issueType: Bugcommunity