Re: [Numpy-discussion] How to use user input as equation directly

2016-10-28 Thread Ben Rowland
It is important to bear in mind where the code is being run - if this is 
something running on a researcher’s own system, they almost certainly have lots 
of other ways of messing it up. These kind of security vulnerabilities are 
normally only relevant when you are running code that came from somewhere else.

That being said, this use case sounds like it could work with the Jupyter 
notebook. If you want something that is like typing code into a .py file but 
evaluated at run time instead, why not just use an interactive Python REPL 
instead of eval(input()).

Ben

> On 27 Oct 2016, at 17:52, Benjamin Root  wrote:
> 
> "only be used by engineers/scientists for research"
> 
> Famous last words. I know plenty of scientists who would love to "do 
> research" with an exposed eval(). Full disclosure, I personally added a 
> security hole into matplotlib thinking I covered all my bases in protecting 
> an eval() statement.
> 
> Ben Root
> 
> On Thu, Oct 27, 2016 at 4:21 PM, djxvillain  > wrote:
> This will not be a public product and will only be used by other
> engineers/scientists for research.  I don't think security should be a huge
> issue, but I appreciate your input and concern for the quality of my code.
> 
> 
> 
> --
> View this message in context: 
> http://numpy-discussion.10968.n7.nabble.com/How-to-use-user-input-as-equation-directly-tp43665p43670.html
>  
> 
> Sent from the Numpy-discussion mailing list archive at Nabble.com.
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org 
> https://mail.scipy.org/mailman/listinfo/numpy-discussion 
> 
> 
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion

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


[Numpy-discussion] PR 7918 apply_along_axis()

2016-08-08 Thread Ben Rowland
Hi list,

This is both my first post to this list and first pull request for numpy so 
apologies if this is not the right list or for any other mistakes.

Here is the link to my pull request: https://github.com/numpy/numpy/pull/7918 


It is a simple modification to the numpy.apply_along_axis() function in 
numpy/lib/shape_base.py to allow it to deal better with ndarray subclasses. My 
use case is this: I have an ndarray subclass storing sets of temporal data 
which has additional metadata properties such as the time between data points. 
I frequently want to apply the same function to each time course in a set and 
apply_along_axis() is a compact and efficient way to do this. However there are 
two behaviours that I require which are not provided by the current numpy 
master:
1) apply_along_axis returns the same subclass as it was called upon, so that I 
don’t lose all the metadata that it went in with.
2) fund1d calls inside apply_along_axis should receive 1d slices of the same 
subclass as the supplied whole array, so that they can make use of the metadata 
in performing their function.

To achieve these two behaviours requires modifying only three lines of code:
1) At the start of the function, the input is converted to a bare ndarray by 
the function numpy.asarray(), I replace this with the subclass friendly 
numpy.asanyarray()
2) Depending on whether func1d returns a scalar or a vector there are two 
different code paths constructing and returning the output array. In each case 
I call __array_wrap__ on the input array, passing the output array to allow it 
to be updated with all the metadata of the original array.

I have also implemented two new tests for this functionality. The first is very 
simple and merely calls apply_along_axis on a numpy.matrix class and checks 
that the result is also a numpy.matrix. The second is slightly more involved as 
it requires defining a MinimalSubclass class which adds a data member to the 
bare ndarray, then a function which returns that member. apply_along_axis() is 
then called passing in an instance of the subclass and the function to show 
that the slices passed to func1d preserve the data member.

I would welcome any comment or constructive criticism.

Ben Rowland___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion