TabViewer / gtabview

Simple graphical tabular data viewer
MIT License
33 stars 3 forks source link

NumPy matrix view #14

Closed s-celles closed 9 years ago

s-celles commented 9 years ago

Hello Yuri,

There is a problem with NumPy arrays

m = np.matrix([[2,3],[1,2]])
view(m)

raises

//anaconda/lib/python3.4/site-packages/gtabview-0.1-py3.4.egg/gtabview/__init__.py:116: RuntimeWarning: cannot visualize the supplied data type: <class 'numpy.matrixlib.defmatrix.matrix'>

Here is a screenshot of Spyder displaying this matrix capture d ecran 2015-07-25 a 09 36 10

I think you should use duck typing and have a fallback mode to Numpy Arrays and if view function raises an error, display this message.

In [26]: lst = [[2,3],[1,2]]

In [27]: a = np.array(lst)

In [28]: a[0][0]
Out[28]: 2

In [29]: a[0, 0]
Out[29]: 2

In [30]: m = np.matrix(lst)

In [31]: m[0][0] # !!!!
Out[31]: matrix([[2, 3]])

In [32]: m[0, 0]
Out[32]: 2

In [33]: lst[0][0]
Out[33]: 2

In [34]: lst[0, 0] # !!!!
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-34-7897f61aa865> in <module>()
----> 1 lst[0, 0]

TypeError: list indices must be integers, not tuple

Kind regards

wavexx commented 9 years ago

This, at least, should be fixed now.

wavexx commented 9 years ago

I think this deserves a new release. I also added the ability to transpose the view.

If you could give it a quick test, I'll release 0.2

s-celles commented 9 years ago

If you add tests (see my comments https://github.com/wavexx/gtabview/issues/9) it will be much easier to give it a try (even if tests are not automated)

I noticed a problem with index numbering with lists

capture d ecran 2015-07-25 a 14 40 26

wavexx commented 9 years ago

On 25/07/15 14:41, scls19fr wrote:

I noticed a problem with index numbering with lists

What's the problem with it?

s-celles commented 9 years ago

First row (number 0) is 1 2 row 3 4 should be numbered "1"

lst2 = [[1, 2], [3, 4]]

There is also 2 rows and 2 columns (not 1 row(s), 2 columns)

wavexx commented 9 years ago

On 25/07/15 14:49, scls19fr wrote:

First row (number 0) is 1 2 row 3 4 should be numbered "1"

This is because for lists-of-lists (like for files), the first is assumed to be labels, as there's no way to tell.

idx_rows=0 should do what you want.

wavexx commented 9 years ago

On 25/07/15 14:52, Yuri D'Elia wrote:

On 25/07/15 14:49, scls19fr wrote:

First row (number 0) is 1 2 row 3 4 should be numbered "1"

This is because for lists-of-lists (like for files), the first is assumed to be labels, as there's no way to tell.

idx_rows=0 should do what you want.

And by that, I mean hdr_rows.

s-celles commented 9 years ago

Shouldn't we consider that by default there is no header (for lists) ?

wavexx commented 9 years ago

On 25/07/15 14:54, scls19fr wrote:

Shouldn't we consider that by default there is no header ?

I'm not sure (in either direction). Sometimes I find it convenient, sometimes not.

s-celles commented 9 years ago

Spyder variables editor display for lists is not very nice

capture d ecran 2015-07-25 a 14 56 21

but it is not misleading

because yes... that's quite misleading !

wavexx commented 9 years ago

True, especially at the beginning. Should the header be enabled only when loading from a file then?

s-celles commented 9 years ago

Yes I think it's a good idea.

wavexx commented 9 years ago

On 25/07/15 15:21, scls19fr wrote:

Yes I think it's a good idea.

Done.