Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions numpy/core/arrayprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,7 @@ def _get_format_function(data, **options):
if issubclass(dtypeobj, _nt.bool_):
return formatdict['bool']()
elif issubclass(dtypeobj, _nt.integer):
if issubclass(dtypeobj, _nt.timedelta64):
return formatdict['timedelta']()
else:
return formatdict['int']()
return formatdict['int']()
elif issubclass(dtypeobj, _nt.floating):
if issubclass(dtypeobj, _nt.longfloat):
return formatdict['longfloat']()
Expand All @@ -423,8 +420,11 @@ def _get_format_function(data, **options):
return formatdict['complexfloat']()
elif issubclass(dtypeobj, (_nt.unicode_, _nt.string_)):
return formatdict['numpystr']()
elif issubclass(dtypeobj, _nt.datetime64):
return formatdict['datetime']()
elif issubclass(dtypeobj, _nt.timebase):
if issubclass(dtypeobj, _nt.datetime64):
return formatdict['datetime']()
else:
return formatdict['timedelta']()
elif issubclass(dtypeobj, _nt.object_):
return formatdict['object']()
elif issubclass(dtypeobj, _nt.void):
Expand Down
3 changes: 3 additions & 0 deletions numpy/core/code_generators/cversions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@
# Version 12 (NumPy 1.14) Added PyArray_ResolveWritebackIfCopy,
# PyArray_SetWritebackIfCopyBase and deprecated PyArray_SetUpdateIfCopyBase.
0x0000000c = a1bc756c5782853ec2e3616cf66869d8

# Version 13 (NumPy 1.15) Added PyTimeunitArrType_Type.
0x0000000d = 39caf1e6584c75022d260952d3b8520f
2 changes: 2 additions & 0 deletions numpy/core/code_generators/numpy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
'PyHalfArrType_Type': (217,),
'NpyIter_Type': (218,),
# End 1.6 API
'PyTimebaseArrType_Type': (304,),
# End 1.15 API
}

#define NPY_NUMUSERTYPES (*(int *)PyArray_API[6])
Expand Down
1 change: 1 addition & 0 deletions numpy/core/include/numpy/numpyconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
#define NPY_1_12_API_VERSION 0x00000008
#define NPY_1_13_API_VERSION 0x00000008
#define NPY_1_14_API_VERSION 0x00000008
#define NPY_1_15_API_VERSION 0x00000008

#endif
3 changes: 2 additions & 1 deletion numpy/core/setup_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
# 0x0000000a - 1.12.x
# 0x0000000b - 1.13.x
# 0x0000000c - 1.14.x
C_API_VERSION = 0x0000000c
# 0x0000000d - 1.15.x
C_API_VERSION = 0x0000000d

class MismatchCAPIWarning(Warning):
pass
Expand Down
1 change: 1 addition & 0 deletions numpy/core/src/multiarray/arraytypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -4938,6 +4938,7 @@ set_typeinfo(PyObject *dict)
SETTYPE(ComplexFloating);
SETTYPE(Flexible);
SETTYPE(Character);
SETTYPE(Timebase);

#undef SETTYPE

Expand Down
7 changes: 3 additions & 4 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4594,10 +4594,9 @@ setup_scalartypes(PyObject *NPY_UNUSED(dict))
SINGLE_INHERIT(LongLong, SignedInteger);
#endif

/* Datetime doesn't fit in any category */
SINGLE_INHERIT(Datetime, Generic);
/* Timedelta is an integer with an associated unit */
SINGLE_INHERIT(Timedelta, SignedInteger);
SINGLE_INHERIT(Timebase, Generic);
SINGLE_INHERIT(Datetime, Timebase);
SINGLE_INHERIT(Timedelta, Timebase);

/*
fprintf(stderr,
Expand Down
6 changes: 3 additions & 3 deletions numpy/core/src/multiarray/scalartypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ NPY_NO_EXPORT PyTypeObject PyTimeIntegerArrType_Type;

/**begin repeat
* #name = number, integer, signedinteger, unsignedinteger, inexact,
* floating, complexfloating, flexible, character#
* floating, complexfloating, flexible, character, timebase#
* #NAME = Number, Integer, SignedInteger, UnsignedInteger, Inexact,
* Floating, ComplexFloating, Flexible, Character#
* Floating, ComplexFloating, Flexible, Character, Timebase#
*/
NPY_NO_EXPORT PyTypeObject Py@NAME@ArrType_Type = {
#if defined(NPY_PY3K)
Expand Down Expand Up @@ -4243,7 +4243,7 @@ initialize_numeric_types(void)

/**begin repeat
* #NAME= Number, Integer, SignedInteger, UnsignedInteger, Inexact,
* Floating, ComplexFloating, Flexible, Character#
* Floating, ComplexFloating, Flexible, Character, Timebase#
*/

Py@NAME@ArrType_Type.tp_flags = BASEFLAGS;
Expand Down
15 changes: 14 additions & 1 deletion numpy/core/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import datetime
from numpy.testing import (
run_module_suite, assert_, assert_equal, assert_raises,
assert_warns, dec, suppress_warnings
assert_raises_regex, assert_warns, dec, suppress_warnings
)

# Use pytz to test out various time zones if available
Expand Down Expand Up @@ -497,6 +497,19 @@ def test_dtype_comparison(self):
assert_(np.dtype('M8[2D]') != np.dtype('M8[D]'))
assert_(np.dtype('M8[D]') != np.dtype('M8[2D]'))

def test_type_hierarchy(self):
assert_equal(np.timebase.mro(), [np.timebase, np.generic, object])
assert_equal(np.datetime64.mro(),
[np.datetime64, np.timebase, np.generic, object])
assert_equal(np.timedelta64.mro(),
[np.timedelta64, np.timebase, np.generic, object])

def test_base_class(self):
assert_(issubclass(np.datetime64, np.timebase))
assert_(issubclass(np.timedelta64, np.timebase))
with assert_raises_regex(TypeError, 'cannot create'):
np.timebase()

def test_pydatetime_creation(self):
a = np.array(['1960-03-12', datetime.date(1960, 3, 12)], dtype='M8[D]')
assert_equal(a[0], a[1])
Expand Down