[yt-dev] Issue #1053: add_field fails in Python 3 (yt_analysis/yt)

astrofrog issues-reply at bitbucket.org
Wed Jul 29 07:43:05 PDT 2015


New issue 1053: add_field fails in Python 3
https://bitbucket.org/yt_analysis/yt/issues/1053/add_field-fails-in-python-3

astrofrog:

The following example:

```python
import os
from yt import load

ds = load(os.path.join('DD0010', 'moving7_0010'))

def _dust_density(field, data):
    return data["density"].in_units('g/cm**3') * 0.01

ds.add_field("dust_density", function=_dust_density, units='g/cm**3')
```

fails in Python 3 with the following error:

```python
Traceback (most recent call last):
  File "derived.py", line 9, in <module>
    ds.add_field("dust_density", function=_dust_density, units='g/cm**3')
  File "/Users/tom/miniconda3/envs/production/lib/python3.4/site-packages/yt/data_objects/static_output.py", line 910, in add_field
    deps, _ = self.field_info.check_derived_fields([name])
  File "/Users/tom/miniconda3/envs/production/lib/python3.4/site-packages/yt/fields/field_info_container.py", line 343, in check_derived_fields
    self.ds.derived_field_list = list(sorted(dfl))
TypeError: unorderable types: str() < tuple()
```

This is with yt 3.2 in Python 3.4. The issue is that in Python 3, strings can no longer be compared to tuples, so the sorting fails.





More information about the yt-dev mailing list