summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorMark Wiebe <mwiebe@enthought.com>2011-05-20 15:41:27 -0500
committerMark Wiebe <mwiebe@enthought.com>2011-05-20 15:41:27 -0500
commit8727a806b34a412bce086df9288ee18cdafe365c (patch)
treeb9544eade4bf46ae2b720f727c44f9866815c9a1 /numpy/lib
parent6ab9c73290659a94b56a7127805bddd25d734901 (diff)
downloadnumpy-8727a806b34a412bce086df9288ee18cdafe365c.tar.gz
ENH: Remove 'den' datetime metadata, move datetime_data to a C function
The 'den' metadata was always 1, except during construction, so there is no reason for it to exist. The variable is kept in the struct for 1.6 ABI compatibility, however. The datetime_data function used ctypes. Moving the function to C is no more difficult, and a bit cleaner in my opinion.
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/tests/test_type_check.py8
-rw-r--r--numpy/lib/type_check.py46
2 files changed, 1 insertions, 53 deletions
diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py
index c8bc87c6e..0f8927614 100644
--- a/numpy/lib/tests/test_type_check.py
+++ b/numpy/lib/tests/test_type_check.py
@@ -382,13 +382,5 @@ class TestArrayConversion(TestCase):
assert_equal(a.__class__,ndarray)
assert_(issubdtype(a.dtype,float))
-class TestDateTimeData(object):
-
- @dec.skipif(not _HAS_CTYPE, "ctypes not available on this python installation")
- def test_basic(self):
- a = array(['1980-03-23'], dtype=datetime64)
- assert_equal(datetime_data(a.dtype), (asbytes('us'), 1, 1, 1))
-
-
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py
index 0ce851fe4..edea02b62 100644
--- a/numpy/lib/type_check.py
+++ b/numpy/lib/type_check.py
@@ -3,7 +3,7 @@
__all__ = ['iscomplexobj','isrealobj','imag','iscomplex',
'isreal','nan_to_num','real','real_if_close',
'typename','asfarray','mintypecode','asscalar',
- 'common_type', 'datetime_data']
+ 'common_type']
import numpy.core.numeric as _nx
from numpy.core.numeric import asarray, asanyarray, array, isnan, \
@@ -601,47 +601,3 @@ def common_type(*arrays):
else:
return array_type[0][precision]
-def datetime_data(dtype):
- """Return (unit, numerator, denominator, events) from a datetime dtype
- """
- try:
- import ctypes
- except ImportError:
- raise RuntimeError("Cannot access date-time internals without ctypes installed")
-
- if dtype.kind not in ['m','M']:
- raise ValueError("Not a date-time dtype")
-
- obj = dtype.metadata[METADATA_DTSTR]
- class DATETIMEMETA(ctypes.Structure):
- _fields_ = [('base', ctypes.c_int),
- ('num', ctypes.c_int),
- ('den', ctypes.c_int),
- ('events', ctypes.c_int)]
-
- import sys
- if sys.version_info[:2] >= (3, 0):
- func = ctypes.pythonapi.PyCapsule_GetPointer
- func.argtypes = [ctypes.py_object, ctypes.c_char_p]
- func.restype = ctypes.c_void_p
- result = func(ctypes.py_object(obj), ctypes.c_char_p(None))
- else:
- func = ctypes.pythonapi.PyCObject_AsVoidPtr
- func.argtypes = [ctypes.py_object]
- func.restype = ctypes.c_void_p
- result = func(ctypes.py_object(obj))
- result = ctypes.cast(ctypes.c_void_p(result), ctypes.POINTER(DATETIMEMETA))
-
- struct = result[0]
- base = struct.base
-
- # FIXME: This needs to be kept consistent with enum in ndarrayobject.h
- from numpy.core.multiarray import DATETIMEUNITS
- obj = ctypes.py_object(DATETIMEUNITS)
- if sys.version_info[:2] >= (2,7):
- result = func(obj, ctypes.c_char_p(None))
- else:
- result = func(obj)
- _unitnum2name = ctypes.cast(ctypes.c_void_p(result), ctypes.POINTER(ctypes.c_char_p))
-
- return (_unitnum2name[base], struct.num, struct.den, struct.events)