Skip to content

Commit

Permalink
Merge branch 'pull-274'
Browse files Browse the repository at this point in the history
* pull-274:
  BUG: Fix datetime 1.6 pickle compatibility test for Python 3.
  STY: Elaborate comment about cloning dtype's c_metadata
  DOC: Improve documentation comment from PR 274 comment
  ENH: Change NPY_AUXDATA_FREE macro based on PR feedback
  BUG: Output the datetime64 dtype to the pickle format from 1.6
  ENH: Change datetime64 to use c_metadata instead of metadata
  ENH: Add a NpyAuxData c_metadata to PyArray_Descr
  • Loading branch information
charris committed May 10, 2012
2 parents c869d12 + ddc944e commit bb162a2
Show file tree
Hide file tree
Showing 14 changed files with 469 additions and 589 deletions.
3 changes: 0 additions & 3 deletions numpy/core/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def _usefields(adict, align):
# a simple typestring

def _array_descr(descriptor):
from multiarray import METADATA_DTSTR
fields = descriptor.fields
if fields is None:
subdtype = descriptor.subdtype
Expand All @@ -89,8 +88,6 @@ def _array_descr(descriptor):
return descriptor.str
else:
new = descriptor.metadata.copy()
# Eliminate any key related to internal implementation
new.pop(METADATA_DTSTR, None)
if new:
return (descriptor.str, new)
else:
Expand Down
202 changes: 100 additions & 102 deletions numpy/core/include/numpy/ndarraytypes.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef NDARRAYTYPES_H
#define NDARRAYTYPES_H

/* This is auto-generated by the installer */
/* numpyconfig.h is auto-generated by the installer */
#include "numpyconfig.h"

#include "npy_common.h"
Expand Down Expand Up @@ -85,8 +85,6 @@ enum NPY_TYPES { NPY_BOOL=0,
NPY_NTYPES_ABI_COMPATIBLE=21
};

#define NPY_METADATA_DTSTR "__timeunit__"

/* basetype array priority */
#define NPY_PRIORITY 0.0

Expand Down Expand Up @@ -215,6 +213,7 @@ typedef enum {

/* The special not-a-time (NaT) value */
#define NPY_DATETIME_NAT NPY_MIN_INT64

/*
* Upper bound on the length of a DATETIME ISO 8601 string
* YEAR: 21 (64-bit year)
Expand Down Expand Up @@ -249,20 +248,6 @@ typedef enum {
#define NPY_DATETIME_NUMUNITS (NPY_FR_GENERIC + 1)
#define NPY_DATETIME_DEFAULTUNIT NPY_FR_GENERIC

#define NPY_STR_Y "Y"
#define NPY_STR_M "M"
#define NPY_STR_W "W"
#define NPY_STR_D "D"
#define NPY_STR_h "h"
#define NPY_STR_m "m"
#define NPY_STR_s "s"
#define NPY_STR_ms "ms"
#define NPY_STR_us "us"
#define NPY_STR_ns "ns"
#define NPY_STR_ps "ps"
#define NPY_STR_fs "fs"
#define NPY_STR_as "as"

/*
* Business day conventions for mapping invalid business
* days to valid business days.
Expand Down Expand Up @@ -290,6 +275,42 @@ typedef enum {
NPY_BUSDAY_RAISE
} NPY_BUSDAY_ROLL;

/************************************************************
* NumPy Auxiliary Data for inner loops, sort functions, etc.
************************************************************/

/*
* When creating an auxiliary data struct, this should always appear
* as the first member, like this:
*
* typedef struct {
* NpyAuxData base;
* double constant;
* } constant_multiplier_aux_data;
*/
typedef struct NpyAuxData_tag NpyAuxData;

/* Function pointers for freeing or cloning auxiliary data */
typedef void (NpyAuxData_FreeFunc) (NpyAuxData *);
typedef NpyAuxData *(NpyAuxData_CloneFunc) (NpyAuxData *);

struct NpyAuxData_tag {
NpyAuxData_FreeFunc *free;
NpyAuxData_CloneFunc *clone;
/* To allow for a bit of expansion without breaking the ABI */
void *reserved[2];
};

/* Macros to use for freeing and cloning auxiliary data */
#define NPY_AUXDATA_FREE(auxdata) \
do { \
if ((auxdata) != NULL) { \
(auxdata)->free(auxdata); \
} \
} while(0)
#define NPY_AUXDATA_CLONE(auxdata) \
((auxdata)->clone(auxdata))

/*********************************************************************
* NumPy functions for dealing with masks, such as in masked iteration
*********************************************************************/
Expand Down Expand Up @@ -571,44 +592,60 @@ typedef struct {

typedef struct _PyArray_Descr {
PyObject_HEAD
PyTypeObject *typeobj; /*
* the type object representing an
* instance of this type -- should not
* be two type_numbers with the same type
* object.
*/
char kind; /* kind for this type */
char type; /* unique-character representing this type */
char byteorder; /*
* '>' (big), '<' (little), '|'
* (not-applicable), or '=' (native).
*/
char flags; /* flags describing data type */
int type_num; /* number representing this type */
int elsize; /* element size for this type */
int alignment; /* alignment needed for this type */
struct _arr_descr \
*subarray; /*
* Non-NULL if this type is
* is an array (C-contiguous)
* of some other type
*/
PyObject *fields; /* The fields dictionary for this type
* For statically defined descr this
* is always Py_None
*/

PyObject *names; /*
* An ordered tuple of field names or NULL
* if no fields are defined
*/

PyArray_ArrFuncs *f; /*
* a table of functions specific for each
* basic data descriptor
*/

PyObject *metadata; /* Metadata about this dtype */
/*
* the type object representing an
* instance of this type -- should not
* be two type_numbers with the same type
* object.
*/
PyTypeObject *typeobj;
/* kind for this type */
char kind;
/* unique-character representing this type */
char type;
/*
* '>' (big), '<' (little), '|'
* (not-applicable), or '=' (native).
*/
char byteorder;
/* flags describing data type */
char flags;
/* number representing this type */
int type_num;
/* element size (itemsize) for this type */
int elsize;
/* alignment needed for this type */
int alignment;
/*
* Non-NULL if this type is
* is an array (C-contiguous)
* of some other type
*/
struct _arr_descr *subarray;
/*
* The fields dictionary for this type
* For statically defined descr this
* is always Py_None
*/
PyObject *fields;
/*
* An ordered tuple of field names or NULL
* if no fields are defined
*/
PyObject *names;
/*
* a table of functions specific for each
* basic data descriptor
*/
PyArray_ArrFuncs *f;
/* Metadata about this dtype */
PyObject *metadata;
/*
* Metadata specific to the C implementation
* of the particular dtype. This was added
* for NumPy 1.7.0.
*/
NpyAuxData *c_metadata;
} PyArray_Descr;

typedef struct _arr_descr {
Expand Down Expand Up @@ -724,20 +761,16 @@ typedef struct {
int flags;
} PyArray_Chunk;


typedef struct {
NPY_DATETIMEUNIT base;
int num;
/*
* 'den' and 'events are unused, kept here for ABI
* compatibility with 1.6.
*
* TODO: Remove for 2.0.
*/
int den;
int events;
NPY_DATETIMEUNIT base;
int num;
} PyArray_DatetimeMetaData;

typedef struct {
NpyAuxData base;
PyArray_DatetimeMetaData meta;
} PyArray_DatetimeDTypeMetaData;

/*
* This structure contains an exploded view of a date-time value.
* NaT is represented by year == NPY_DATETIME_NAT.
Expand All @@ -747,7 +780,7 @@ typedef struct {
npy_int32 month, day, hour, min, sec, us, ps, as;
} npy_datetimestruct;

/* TO BE REMOVED - NOT USED INTERNALLY. */
/* This is not used internally. */
typedef struct {
npy_int64 day;
npy_int32 sec, us, ps, as;
Expand Down Expand Up @@ -1747,41 +1780,6 @@ PyArray_HASMASKNA(PyArrayObject *arr)
#define PyDataType_ISNOTSWAPPED(d) PyArray_ISNBO(((PyArray_Descr *)(d))->byteorder)
#define PyDataType_ISBYTESWAPPED(d) (!PyDataType_ISNOTSWAPPED(d))

/************************************************************
* NumPy Auxiliary Data for inner loops, sort functions, etc.
************************************************************/

/*
* When creating an auxiliary data struct, this should always appear
* as the first member, like this:
*
* typedef struct {
* NpyAuxData base;
* double constant;
* } constant_multiplier_aux_data;
*/
typedef struct NpyAuxData_tag NpyAuxData;

/* Function pointers for freeing or cloning auxiliary data */
typedef void (NpyAuxData_FreeFunc) (NpyAuxData *);
typedef NpyAuxData *(NpyAuxData_CloneFunc) (NpyAuxData *);

struct NpyAuxData_tag {
NpyAuxData_FreeFunc *free;
NpyAuxData_CloneFunc *clone;
/* To allow for a bit of expansion without breaking the ABI */
void *reserved[2];
};

/* Macros to use for freeing and cloning auxiliary data */
#define NPY_AUXDATA_FREE(auxdata) \
if ((auxdata) == NULL) \
; \
else \
((auxdata)->free(auxdata))
#define NPY_AUXDATA_CLONE(auxdata) \
((auxdata)->clone(auxdata))

/************************************************************
* A struct used by PyArray_CreateSortedStridePerm, new in 1.7.
************************************************************/
Expand Down
24 changes: 24 additions & 0 deletions numpy/core/include/numpy/npy_deprecated_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@
*/
#define FORTRAN_IF PyArray_FORTRAN_IF

/* Deprecated as of NumPy 1.7, datetime64 uses c_metadata instead */
#define NPY_METADATA_DTSTR "__timeunit__"

/*
* Deprecated as of NumPy 1.7.
* The reasoning:
* - These are for datetime, but there's no datetime "namespace".
* - They just turn NPY_STR_<x> into "<x>", which is just
* making something simple be indirected.
*/
#define NPY_STR_Y "Y"
#define NPY_STR_M "M"
#define NPY_STR_W "W"
#define NPY_STR_D "D"
#define NPY_STR_h "h"
#define NPY_STR_m "m"
#define NPY_STR_s "s"
#define NPY_STR_ms "ms"
#define NPY_STR_us "us"
#define NPY_STR_ns "ns"
#define NPY_STR_ps "ps"
#define NPY_STR_fs "fs"
#define NPY_STR_as "as"

/*
* The macros in old_defines.h are Deprecated as of NumPy 1.7 and will be
* removed in the next major release.
Expand Down
30 changes: 1 addition & 29 deletions numpy/core/src/multiarray/_datetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ create_datetime_dtype(int type_num, PyArray_DatetimeMetaData *meta);
NPY_NO_EXPORT PyArray_Descr *
create_datetime_dtype_with_unit(int type_num, NPY_DATETIMEUNIT unit);

/*
* This function returns the a new reference to the
* capsule with the datetime metadata.
*/
NPY_NO_EXPORT PyObject *
get_datetime_metacobj_from_dtype(PyArray_Descr *dtype);

/*
* This function returns a pointer to the DateTimeMetaData
* contained within the provided datetime dtype.
Expand Down Expand Up @@ -157,20 +150,6 @@ can_cast_timedelta64_metadata(PyArray_DatetimeMetaData *src_meta,
PyArray_DatetimeMetaData *dst_meta,
NPY_CASTING casting);

/*
* Computes the GCD of the two date-time metadata values. Raises
* an exception if there is no reasonable GCD, such as with
* years and days.
*
* Returns a capsule with the GCD metadata.
*/
NPY_NO_EXPORT PyObject *
compute_datetime_metadata_greatest_common_divisor_capsule(
PyArray_Descr *type1,
PyArray_Descr *type2,
int strict_with_nonlinear_units1,
int strict_with_nonlinear_units2);

/*
* Computes the conversion factor to convert data with 'src_meta' metadata
* into data with 'dst_meta' metadata.
Expand All @@ -184,7 +163,7 @@ get_datetime_conversion_factor(PyArray_DatetimeMetaData *src_meta,
npy_int64 *out_num, npy_int64 *out_denom);

/*
* Given an the capsule datetime metadata object,
* Given a pointer to datetime metadata,
* returns a tuple for pickling and other purposes.
*/
NPY_NO_EXPORT PyObject *
Expand All @@ -199,13 +178,6 @@ NPY_NO_EXPORT int
convert_datetime_metadata_tuple_to_datetime_metadata(PyObject *tuple,
PyArray_DatetimeMetaData *out_meta);

/*
* Given a tuple representing datetime metadata,
* returns a capsule datetime metadata object.
*/
NPY_NO_EXPORT PyObject *
convert_datetime_metadata_tuple_to_metacobj(PyObject *tuple);

/*
* Gets a tzoffset in minutes by calling the fromutc() function on
* the Python datetime.tzinfo object.
Expand Down
Loading

0 comments on commit bb162a2

Please sign in to comment.