def to_writeable(source):
if isinstance(source, np.ndarray):<EOL><INDENT>return source<EOL><DEDENT>if source is None:<EOL><INDENT>return None<EOL><DEDENT>is_mapping = (hasattr(source, '<STR_LIT>') and hasattr(source, '<STR_LIT>') and<EOL>hasattr(source, '<STR_LIT>'))<EOL>if not is_mapping and hasattr(source, '<STR_LIT>'):<EOL><INDENT>source = dict((key, value) for key, value in source.__dict__.items()<EOL>if not key.startswith('<STR_LIT:_>'))<EOL>is_mapping = True<EOL><DEDENT>if is_mapping:<EOL><INDENT>dtype = []<EOL>values = []<EOL>for field, value in source.items():<EOL><INDENT>if (isinstance(field, string_types) and<EOL>field[<NUM_LIT:0>] not in '<STR_LIT>'):<EOL><INDENT>dtype.append((field,object))<EOL>values.append(value)<EOL><DEDENT><DEDENT>if dtype:<EOL><INDENT>return np.array([tuple(values)],dtype)<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>narr = np.asanyarray(source)<EOL>if narr.dtype.type in (np.object, np.object_) andnarr.shape == () and narr == source:<EOL><INDENT>return None<EOL><DEDENT>return narr<EOL>
Convert input object ``source`` to something we can write

    Parameters
    ----------
    source : object

    Returns
    -------
    arr : ndarray

    Examples
    --------
    >>> to_writeable(np.array([1])) # pass through ndarrays
    array([1])
    >>> expected = np.array([(1, 2)], dtype=[('a', '|O8'), ('b', '|O8')])
    >>> np.all(to_writeable({'a':1,'b':2}) == expected)
    True
    >>> np.all(to_writeable({'a':1,'b':2, '_c':3}) == expected)
    True
    >>> np.all(to_writeable({'a':1,'b':2, 100:3}) == expected)
    True
    >>> np.all(to_writeable({'a':1,'b':2, '99':3}) == expected)
    True
    >>> class klass(object): pass
    >>> c = klass
    >>> c.a = 1
    >>> c.b = 2
    >>> np.all(to_writeable({'a':1,'b':2}) == expected)
    True
    >>> to_writeable([])
    array([], dtype=float64)
    >>> to_writeable(())
    array([], dtype=float64)
    >>> to_writeable(None)

    >>> to_writeable('a string').dtype.type == np.str_
    True
    >>> to_writeable(1)
    array(1)
    >>> to_writeable([1])
    array([1])
    >>> to_writeable([1])
    array([1])
    >>> to_writeable(object()) # not convertable

    dict keys with legal characters are convertible

    >>> to_writeable({'a':1})['a']
    array([1], dtype=object)

    but not with illegal characters

    >>> to_writeable({'1':1}) is None
    True
    >>> to_writeable({'_a':1}) is None
    True