astropy/astropy — pull request #3108 by mdboom (2014-11-17 18:31:04+00:00)
Title: Bug: unit comparison with None raises TypeError

Use case: wrapping external data source (where the data source exposes data as a plain numpy ndarray) with units if they are known. Getter method returns reference to underlying data if units are not specified, and returns a Quantity object if units are specified.

Problem:
1. There is no "unspecified" unit definition
2. There is no way to check a variable/attribute/keyword argument against Python's "None" value

I worked around the problem by creating my own fundamental unit called "unspecified". However I think it would be good to include an "unspecified" unit in the library (primarily for comparison) as well as support comparison with None. Both should have the exact same meaning.

```python
import astropy.units as u

units = None

if units == None : print "No units"
No units

units = u.Pa

if units == None : print "No units"
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
----> 1 if units == None : print "No units"

C:\Users\bnordgren\AppData\Local\Enthought\Canopy\User\lib\site-packages\astropy\units\core.pyc in __eq__(self, other)
667
668 try:
--> 669 other = Unit(other, parse_strict='silent')
670 except (ValueError, UnitsError):
671 return False

C:\Users\bnordgren\AppData\Local\Enthought\Canopy\User\lib\site-packages\astropy\units\core.pyc in __call__(self, s, represents, format, namespace, doc, parse_strict)
1745
1746 elif s is None:
-> 1747 raise TypeError("None is not a valid Unit")
1748
1749 else:

TypeError: None is not a valid Unit
```