Skip to content

Add NDArray trait type#1

Closed
maedoc wants to merge 8 commits intoipython:masterfrom
maedoc:ndarray
Closed

Add NDArray trait type#1
maedoc wants to merge 8 commits intoipython:masterfrom
maedoc:ndarray

Conversation

@maedoc
Copy link

@maedoc maedoc commented Jan 2, 2014

This adds an NDArray trait type that validates on shape and dtype constraints.

@maedoc
Copy link
Author

maedoc commented Jan 2, 2014

FWIW the tests pass on py 27 but importing numpy fails with an ImportError for multiarray on py 33. If anyone knows how to make that work on Travis, I suspect the tests would pass on py 33 as well.

@Carreau
Copy link
Member

Carreau commented Jan 3, 2014

Will look into that with more detail, see also comment on other PR #2 that maybe we want to have ipython/ipython#4659 totally integrated into IPython before pushing this repo forward.

One problem I might see with this as it is, is that it makes traitlets requiring numpy, and I'm not sure it is a good idea. We can probably conditional loading that make NDArray availlable IIF numpy is availlable, but I would like to find a better solution.

@maedoc
Copy link
Author

maedoc commented Jan 3, 2014

The actual module could test that the class name matches instead of the
instance check, yes? (Isn't that already supported?) The tests still would
require numpy. Would that be satisfactory?
On Jan 3, 2014 9:31 AM, "Matthias Bussonnier" notifications@github.com
wrote:

Will look into that with more detail, see also comment on other PR #2https://github.com/ipython/traitlets/pull/2that maybe we want to have
ipython/ipython#4659 https://github.com/ipython/ipython/pull/4659totally integrated into IPython before pushing this repo forward.

One problem I might see with this as it is, is that it makes traitlets
requiring numpy, and I'm not sure it is a good idea. We can probably
conditional loading that make NDArray availlable IIF numpy is availlable,
but I would like to find a better solution.


Reply to this email directly or view it on GitHubhttps://github.com//pull/1#issuecomment-31510653
.

@maedoc
Copy link
Author

maedoc commented Jan 3, 2014

Is ipython/ipython#4659 waiting on something in particular?

@takluyver
Copy link
Member

I agree that traitlets shouldn't require numpy, but if you have to import it as from traitlets.ndarray import NDArray, I'm fine with that importing numpy - an ImportError seems like a clearer failure mode than trying to do anything clever.

The Python 3 testing is a problem with Travis - you're installing python3-numpy from apt, but on the Ubuntu version Travis uses, that's a package for Python 3.2. There are instructions to use Miniconda on Travis here: https://gist.github.com/dan-blanchard/7045057

As an aside: if anyone has the resources to set up a building/testing service based on conda envs instead of virtualenvs, so we don't need that kind of hack, I think the SciPy ecosystem would be very grateful.

@Carreau
Copy link
Member

Carreau commented Jan 3, 2014

Is ipython/ipython#4659 waiting on something in particular?

Mainly that I got time to polish it, that is to say move the docs and do cross refs and that we agree on what should be exposed in traitlets where.

Basically I don't really like the fact that you can import Config object directly from traitlets and things like that.

from traitlets.ndarray import NDArray, I'm fine with that importing numpy - an ImportError seems like a clearer failure mode than trying to do anything clever.

I haven't read the code yet, so if it is like that I'm find with it too.

@maedoc
Copy link
Author

maedoc commented Jan 3, 2014

I didn't touch the traitlets.__init__ module on purpose, so any user code only requires numpy if the traitlets.ndarray module is explicitly imported. I also prefer the obvious ImportError this will generate as code using the NDArray class presumably will depend, independently of traitlets, on numpy.

[edited for clarity]

@rossant
Copy link

rossant commented Jan 13, 2015

@maedoc just wondering what's the status of this?
Is it conceivable to have a ndarray trait notify content changes like:

class A(HasTraits):
    arr = NDArray(...)

a = A()
a.arr = np.array(...)  # ==> notify
a.arr[0] = 1  # ==> notify
a.arr += 1  # ==> notify
...

@Carreau
Copy link
Member

Carreau commented Jan 13, 2015

We will restart Traitlets from scratch after 3.0, (spliting it again from IPython)

Once this is done, the more the merrier.

@rossant
Copy link

rossant commented Jan 13, 2015

OK. Any idea of the timeframe? What's wrong with the current implementation?

@Carreau
Copy link
Member

Carreau commented Jan 13, 2015

OK. Any idea of the timeframe?

A few month.

What's wrong with the current implementation?

Nothing, this just copy and past of old IPython version, which has evolved too much with widgets.
I basically spent a week creating this package with a wrongly set mutex. So the backend reply to me that transaction could not be applied, and I need to reperfom it.

I just need to find a week to say :

"""
Don't F%^& dare touching `Traitlets` code for a week
"""

and re-do the work, then release mutex. It's doable in 2 days if I don't move the documentation now, and I don't try to move the Config part at the same time. Probably a day with cafein, but think one more day to review.

@maedoc
Copy link
Author

maedoc commented Jan 13, 2015

@rossant I seem to have lost this repo, but a.arr = r_[] could notify while a.arr += 1 would require an ndarray subclass, as any reference to a.arr results in the ndarray and not the trait's data descriptor arr (whic is the thing wrapping access to the ndarray).

@minrk minrk force-pushed the master branch 5 times, most recently from d163288 to bfa557f Compare April 8, 2015 23:33
@minrk minrk closed this Apr 17, 2015
Carreau pushed a commit that referenced this pull request Jun 10, 2015
Fix typo s/applicatinos/applications/ in setup.py
ellisonbg pushed a commit that referenced this pull request Sep 12, 2015
@minrk minrk modified the milestone: no action Nov 9, 2015
@maedoc
Copy link
Author

maedoc commented Jun 10, 2016

@minrk why no action?

@Carreau
Copy link
Member

Carreau commented Jun 14, 2016

I think that because most of that is in numtraits package in @astrofrog/numtraits.

@ellisonbg
Copy link
Member

I thought we were going to put these types of things here:

https://github.com/jupyter-incubator/traittypes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants