diff options
author | Mark Wiebe <mwiebe@enthought.com> | 2011-06-07 13:21:12 -0500 |
---|---|---|
committer | Mark Wiebe <mwiebe@enthought.com> | 2011-06-07 13:21:12 -0500 |
commit | a8274369fcbc3332067a8555782cb40cc4684c83 (patch) | |
tree | 00bf53d4e3951cd9e9588edf9876925482dea2e0 /numpy/lib | |
parent | fd9ef72daaa66803fd3109502fb584bbda6f407c (diff) | |
parent | 283b2e712bd52e6661f2dc338eb14caae2f5a8da (diff) | |
download | numpy-a8274369fcbc3332067a8555782cb40cc4684c83.tar.gz |
Merge branch 'datetime-fixes'
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/tests/test_type_check.py | 8 | ||||
-rw-r--r-- | numpy/lib/type_check.py | 46 |
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) |