question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnicodeEncodeError using astropy.units.cds

See original GitHub issue

The following two scripts fail for me at the Python 2.7.12 command line using AstroPy 1.2.1:

import astropy.units.cds
help(astropy.units.cds)

and

import astropy.coordinates
import astropy.units.cds
astropy.units.cds.enable()
astropy.coordinates.Angle("5d")

The former fails with:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/site.py", line 464, in __call__
    return pydoc.help(*args, **kwds)
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/pydoc.py", line 1794, in __call__
    self.help(request)
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/pydoc.py", line 1841, in help
    else: doc(request, 'Help on %s:')
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/pydoc.py", line 1578, in doc
    pager(render_doc(thing, title, forceload))
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/pydoc.py", line 1573, in render_doc
    return title % desc + '\n\n' + text.document(object, name)
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/pydoc.py", line 361, in document
    if inspect.ismodule(object): return self.docmodule(*args)
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/pydoc.py", line 1094, in docmodule
    for key, value in inspect.getmembers(object, inspect.isclass):
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/inspect.py", line 253, in getmembers
    value = getattr(object, key)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 2: ordinal not in range(128)

and the latter fails with:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/site-packages/astropy/coordinates/angles.py", line 111, in __new__
    angle, new_unit = util.parse_angle(angle, unit)
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/site-packages/astropy/coordinates/angle_utilities.py", line 348, in parse_angle
    return _AngleParser().parse(angle, unit, debug=debug)
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/site-packages/astropy/coordinates/angle_utilities.py", line 44, in __init__
    _AngleParser._parser, _AngleParser._lexer = self._make_parser()
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/site-packages/astropy/coordinates/angle_utilities.py", line 104, in _make_parser
    '(?:{0})'.format(x) for x in cls._get_simple_unit_names())
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/site-packages/astropy/coordinates/angle_utilities.py", line 49, in _get_simple_unit_names
    u.radian.find_equivalent_units(include_prefix_units=True))
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/site-packages/astropy/units/core.py", line 1438, in find_equivalent_units
    include_prefix_units=include_prefix_units)
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/site-packages/astropy/units/core.py", line 1263, in compose
    max_depth=max_depth, depth=0, cached_results={}))
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/site-packages/astropy/units/core.py", line 1255, in sort_results
    if str(result) != str(last_result):
  File "/Users/rowen/UW/LSST/lsstsw/miniconda/lib/python2.7/site-packages/astropy/units/core.py", line 504, in __bytes__
    return unit_format.Generic.to_string(self).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb5' in position 12: ordinal not in range(128)

See also https://groups.google.com/forum/#!topic/astropy-dev/-ebCdowI_0M

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:26 (23 by maintainers)

github_iconTop GitHub Comments

1reaction
mhvkcommented, Sep 22, 2016
0reactions
mhvkcommented, Nov 21, 2016

Closing since #5483 is merged. Thanks all for helping to track these odd issues down!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Units and Quantities (astropy.units) — Astropy v5.2
The most convenient way to create a Quantity is to multiply or divide a value by one of the built-in units. It works...
Read more >
String Representations of Units and Quantities — Astropy v5.2
You can control the way that Quantity and UnitBase objects are rendered as strings using the Python Format String Syntax (demonstrated below using...
Read more >
Base — Astropy v5.1.1
Convert a unit object to a string. Attributes Documentation. registry = {'cds': <class 'astropy.units.format.
Read more >
Source code for astropy.units.format.cds
Source code for astropy.units.format.cds. # -*- coding: utf-8 -*- # Licensed under a 3-clause BSD style license - see LICNSE.
Read more >
Source code for astropy.units.format
... in sys.modules since astropy.units.core imports this module import sys core = sys.modules['astropy.units.core'] from .base import Base # noqa from .cds ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found