Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to print Series/DataFrame with column of void dtype throws exception #13447

Closed
aldanor opened this issue Jun 15, 2016 · 3 comments
Closed
Labels
Dtype Conversions Unexpected or buggy dtype conversions Usage Question

Comments

@aldanor
Copy link
Contributor

aldanor commented Jun 15, 2016

Trying to print anything containing a V* (void) type throws in isnull:

>>> import numpy as np
>>> import pandas as pd
>>> arr = np.array([b'foo'], dtype='V')
>>> arr
array([[102 111 111]],
      dtype='|V3')
>>> s = pd.Series(arr)
>>> s[0]
[102 111 111]
>>> s
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could 
not be safely coerced to any supported types according to the casting rule ''safe''

From the looks of it, pandas.core.common._isnull_ndarraylike (and maybe some other methods?) should take care of this, e.g. return an array filled with False.

Here's the relevant part of the traceback:

pandas/formats/format.py in _format_strings(self)
   2057             vals = vals._values
   2058
-> 2059         is_float = lib.map_infer(vals, com.is_float) & notnull(vals)
   2060         leading_space = is_float.any()
   2061

pandas/core/common.py in notnull(obj)
    248     pandas.isnull : boolean inverse of pandas.notnull
    249     """
--> 250     res = isnull(obj)
    251     if lib.isscalar(res):
    252         return not res

pandas/core/common.py in isnull(obj)
     89     pandas.notnull: boolean inverse of pandas.isnull
     90     """
---> 91     return _isnull(obj)
     92
     93

pandas/core/common.py in _isnull_new(obj)
     99         raise NotImplementedError("isnull is not defined for MultiIndex")
    100     elif isinstance(obj, (gt.ABCSeries, np.ndarray, pd.Index)):
--> 101         return _isnull_ndarraylike(obj)
    102     elif isinstance(obj, gt.ABCGeneric):
    103         return obj._constructor(obj._data.isnull(func=isnull))

pandas/core/common.py in _isnull_ndarraylike(obj)
    190         result = values.view('i8') == tslib.iNaT
    191     else:
--> 192         result = np.isnan(values)
    193
    194     # box

TypeError: ufunc 'isnan' not supported for the input types, and the inputs could 
not be safely coerced to any supported types according to the casting rule ''safe''
@jreback
Copy link
Contributor

jreback commented Jun 15, 2016

void is not a valid dtype to pandas, use object if you really really want this.

@jreback jreback closed this as completed Jun 15, 2016
@jreback jreback added Dtype Conversions Unexpected or buggy dtype conversions Usage Question labels Jun 15, 2016
@aldanor
Copy link
Contributor Author

aldanor commented Jun 15, 2016

@jreback Just wondering why is is not a valid dtype? It denotes a scalar fixed-size binary blob, which object is not (more like a heterogenous collection of whatever).

There are cases where it's hard to find an alternative -- e.g., long fixed-size identifiers that may contain internal nulls, these you just store as V* so numpy doesn't mess with zero-termination. Also off top of my head, h5py maps H5PY_OPAQUE to np.void, both for reading and writing.

If this is really not meant to be ever supported, maybe Series should cast void to object for consistency purposes then? Just checked, that's what DataFrame / Index currently do.

@jreback
Copy link
Contributor

jreback commented Jun 15, 2016

@aldanor its has never been supported. you can should just cast to object. I suppose you can put some checks in to do this conversion. If you want to put up a PR for that great.

We don't support h5py directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Usage Question
Projects
None yet
Development

No branches or pull requests

2 participants