[Numpy-discussion] Proposal: add ndarray.keys() to return dtype.names

2014-09-30 Thread John Zwinck
I first proposed this on GitHub:
https://github.com/numpy/numpy/issues/5134 ; jaimefrio requested that
I bring it to this list for discussion.

My proposal is to add a keys() method to NumPy's array class ndarray.
The behavior would be to return self.dtype.names, i.e. the column
names for a structured array (and None when dtype.names is None,
which it is for pure numeric arrays without named columns).

I originally proposed to add a values() method also, but I am tabling
that for now so we needn't discuss it in this thread.

The motivation is to enhance the ability to use duck typing with NumPy
arrays, Python dicts, and other types like Pandas DataFrames, h5py
Files, and more.  It's a fairly common thing to want to get the keys
of a container, where keys is understood to be a sequence of values
one can pass to __getitem__(), and this is exactly what I'm aiming at.

Thoughts?

John Zwinck
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Proposal: add ndarray.keys() to return dtype.names

2014-09-30 Thread Eelco Hoogendoorn
Sounds fair to me. Indeed the ducktyping argument makes sense, and I have a
hard time imagining any namespace conflicts or other confusion. Should this
attribute return none for non-structured arrays, or simply be undefined?

On Tue, Sep 30, 2014 at 12:49 PM, John Zwinck jzwi...@gmail.com wrote:

 I first proposed this on GitHub:
 https://github.com/numpy/numpy/issues/5134 ; jaimefrio requested that
 I bring it to this list for discussion.

 My proposal is to add a keys() method to NumPy's array class ndarray.
 The behavior would be to return self.dtype.names, i.e. the column
 names for a structured array (and None when dtype.names is None,
 which it is for pure numeric arrays without named columns).

 I originally proposed to add a values() method also, but I am tabling
 that for now so we needn't discuss it in this thread.

 The motivation is to enhance the ability to use duck typing with NumPy
 arrays, Python dicts, and other types like Pandas DataFrames, h5py
 Files, and more.  It's a fairly common thing to want to get the keys
 of a container, where keys is understood to be a sequence of values
 one can pass to __getitem__(), and this is exactly what I'm aiming at.

 Thoughts?

 John Zwinck
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] f2py and debug mode

2014-09-30 Thread Bayard
Hello to all.
I'm aiming to wrap a Fortran program into Python. I started to work with 
f2py, and am trying to setup a debug mode where I could reach 
breakpoints in Fortran module launched by Python. I've been looking in 
the existing post, but not seeing things like that.

I'm used to work with visual studio 2012 and Intel Fortran compiler, I 
have tried to get that point doing :
1) Run f2py -m to get *.c wrapper
2) Embed it in a C Project in Visual Studio, containing also with 
fortranobject.c and fortranobject.h,
3) Create a solution which also contains my fortran files compiled as a lib
4) Generate in debug mode a dll with extension pyd (to get to that 
point name of the main function in Fortran by _main).

I compiled without any error, and reach break point in C Wrapper, but 
not in Fortran, and the fortran code seems not to be executed (whereas 
it is when compiling with f2py -c). Trying to understand f2py code, I 
noticed that f2py is not only writing c-wrapper, but compiling it in a 
specific way. Is there a way to get a debug mode in Visual Studio with 
f2py (some members of the team are used to it) ? Any alternative tool we 
should use for debugging ?

Thanks for answering
Ferdinand




---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce 
que la protection avast! Antivirus est active.
http://www.avast.com

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Proposal: add ndarray.keys() to return dtype.names

2014-09-30 Thread Benjamin Root
I am also +1. I have already used structured arrays to do keyword-based
string formatting. This makes sense as well. Would this enable keyword
argument expansion?

On Tue, Sep 30, 2014 at 7:29 AM, Eelco Hoogendoorn 
hoogendoorn.ee...@gmail.com wrote:

 Sounds fair to me. Indeed the ducktyping argument makes sense, and I have
 a hard time imagining any namespace conflicts or other confusion. Should
 this attribute return none for non-structured arrays, or simply be
 undefined?

 On Tue, Sep 30, 2014 at 12:49 PM, John Zwinck jzwi...@gmail.com wrote:

 I first proposed this on GitHub:
 https://github.com/numpy/numpy/issues/5134 ; jaimefrio requested that
 I bring it to this list for discussion.

 My proposal is to add a keys() method to NumPy's array class ndarray.
 The behavior would be to return self.dtype.names, i.e. the column
 names for a structured array (and None when dtype.names is None,
 which it is for pure numeric arrays without named columns).

 I originally proposed to add a values() method also, but I am tabling
 that for now so we needn't discuss it in this thread.

 The motivation is to enhance the ability to use duck typing with NumPy
 arrays, Python dicts, and other types like Pandas DataFrames, h5py
 Files, and more.  It's a fairly common thing to want to get the keys
 of a container, where keys is understood to be a sequence of values
 one can pass to __getitem__(), and this is exactly what I'm aiming at.

 Thoughts?

 John Zwinck
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion



 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Proposal: add ndarray.keys() to return dtype.names

2014-09-30 Thread Stephan Hoyer
I like this idea. But I am -1 on returning None if the array is
unstructured. I expect .keys(), if present, to always return an iterable.

In fact, this would break some of my existing code, which checks for the
existence of keys as a way to do duck typed checks for dictionary like
objects (e.g., including pandas.DataFrame):
https://github.com/xray/xray/blob/v0.3/xray/core/utils.py#L165
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Proposal: add ndarray.keys() to return dtype.names

2014-09-30 Thread Eelco Hoogendoorn
So a non-structured array should return an empty list/iterable as its keys?
That doesn't seem right to me, but perhaps you have a compelling example to
the contrary.

I mean, wouldn't we want the duck-typing to fail if it isn't a structured
array? Throwing an attributeError seems like the best thing to do, from a
duck-typing perspective.

On Tue, Sep 30, 2014 at 8:05 PM, Stephan Hoyer sho...@gmail.com wrote:

 I like this idea. But I am -1 on returning None if the array is
 unstructured. I expect .keys(), if present, to always return an iterable.

 In fact, this would break some of my existing code, which checks for the
 existence of keys as a way to do duck typed checks for dictionary like
 objects (e.g., including pandas.DataFrame):
 https://github.com/xray/xray/blob/v0.3/xray/core/utils.py#L165

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Proposal: add ndarray.keys() to return dtype.names

2014-09-30 Thread Eelco Hoogendoorn
On more careful reading of your words, I think we agree; indeed, if keys()
is present is should return an iterable; but I don't think it should be
present for non-structured arrays.

On Tue, Sep 30, 2014 at 10:21 PM, Eelco Hoogendoorn 
hoogendoorn.ee...@gmail.com wrote:

 So a non-structured array should return an empty list/iterable as its
 keys? That doesn't seem right to me, but perhaps you have a compelling
 example to the contrary.

 I mean, wouldn't we want the duck-typing to fail if it isn't a structured
 array? Throwing an attributeError seems like the best thing to do, from a
 duck-typing perspective.

 On Tue, Sep 30, 2014 at 8:05 PM, Stephan Hoyer sho...@gmail.com wrote:

 I like this idea. But I am -1 on returning None if the array is
 unstructured. I expect .keys(), if present, to always return an iterable.

 In fact, this would break some of my existing code, which checks for the
 existence of keys as a way to do duck typed checks for dictionary like
 objects (e.g., including pandas.DataFrame):
 https://github.com/xray/xray/blob/v0.3/xray/core/utils.py#L165

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion



___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Proposal: add ndarray.keys() to return dtype.names

2014-09-30 Thread Stephan Hoyer
On Tue, Sep 30, 2014 at 1:22 PM, Eelco Hoogendoorn 
hoogendoorn.ee...@gmail.com wrote:

 On more careful reading of your words, I think we agree; indeed, if keys()
 is present is should return an iterable; but I don't think it should be
 present for non-structured arrays.


Indeed, I think we do agree. The attribute can simply be missing (e.g.,
accessing it raises AttributeError) for non-structured arrays.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion