Future warning in SafeRepresenter if numpy ndarray is yamled.

Issue #64 closed
created an issue

Code to reproduce:

import numpy
import ruamel.yaml as yaml

def ndarray_representer(dumper, data):
    return dumper.represent_list(data.tolist())
yaml.add_representer(numpy.ndarray, ndarray_representer)
yaml.dump({"test": numpy.zeros(4)})

usr/lib64/python3.4/site-packages/yaml/representer.py:135: FutureWarning: comparison to None will result in an elementwise object comparison in the future. if data in [None, ()]:

Looking at representer.py:

class SafeRepresenter(BaseRepresenter): 
    def ignore_aliases(self, data): 
        if data in [None, ()]: 
            return True

a fix could be

if data is None or data is (): 
    return True

Comments (6)

  1. Log in to comment