Skip to content

BUG: repr of generic datetime crashes #11752

Open

Description

@eric-wieser

Reproducing code example:

import numpy as np
dt = np.dtype([('b', np.datetime64)])
arr = np.zeros(1, dt)
repr(arr)

Error message:

  File "C:\Program Files\Python 3.5\lib\site-packages\IPython\core\formatters.py", line 693, in __call__
    printer.pretty(obj)
  File "C:\Program Files\Python 3.5\lib\site-packages\IPython\lib\pretty.py", line 380, in pretty
    return _default_pprint(obj, self, cycle)
  File "C:\Program Files\Python 3.5\lib\site-packages\IPython\lib\pretty.py", line 495, in _default_pprint
    _repr_pprint(obj, p, cycle)
  File "C:\Program Files\Python 3.5\lib\site-packages\IPython\lib\pretty.py", line 693, in _repr_pprint
    output = repr(obj)
  File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\arrayprint.py", line 1433, in array_repr
    ', ', prefix, suffix=suffix)
  File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\arrayprint.py", line 670, in array2string
    return _array2string(a, options, separator, prefix)
  File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\arrayprint.py", line 460, in wrapper
    return f(self, *args, **kwargs)
  File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\arrayprint.py", line 486, in _array2string
    format_function = _get_format_function(data, **options)
  File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\arrayprint.py", line 433, in _get_format_function
    return StructuredVoidFormat.from_data(data, **options)
  File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\arrayprint.py", line 1270, in from_data
    format_function = _get_format_function(data[field_name], **options)
  File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\arrayprint.py", line 428, in _get_format_function
    return formatdict['datetime']()
  File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\arrayprint.py", line 365, in <lambda>
    'datetime': lambda: DatetimeFormat(data, legacy=legacy),
  File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\arrayprint.py", line 1222, in __init__
    super(DatetimeFormat, self).__init__(x)
  File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\arrayprint.py", line 1183, in __init__
    max_str_len = max(len(self._format_non_nat(np.max(non_nat))),
  File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\arrayprint.py", line 1233, in _format_non_nat
    casting=self.casting)
ValueError: Cannot convert a NumPy datetime value other than NaT with generic units

Numpy/Python version information:

4a0c307

Activity

  1. eric-wieser commented on Aug 16, 2018

    @eric-wieser
    MemberAuthor

    1.13 gives

    TypeError: Invalid datetime unit "generic" in metadata
    

    So probably not a 1.14 regression

  2. tylerjereddy commented on Aug 22, 2018

    @tylerjereddy
    Contributor

    I've bisected to determine the first bad commit: 3d75c3f

    I don't have a working patch just yet though as the diff on that commit is non-trivial, and the precise error did evolve over the commit history as you've noticed.

  3. tylerjereddy commented on Aug 22, 2018

    @tylerjereddy
    Contributor

    @eric-wieser What do you expect the repr to be for the case you provided? Before errors were raised it was [(None,)], which maybe isn't what you'd like to see.

  4. eric-wieser commented on Aug 26, 2018

    @eric-wieser
    MemberAuthor

    "structured arrays" are a red herring here - the same result is obtained from:

    repr(np.zeros(2, np.datetime64))
    
  5. changed the title [-]BUG: repr of structured array containing generic datetime crashes[/-] [+]BUG: repr of generic datetime crashes[/+] on Aug 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions