Skip to content

fix #454 : display dtype of array when calling info() #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/source/changes/version_0_26.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,18 @@ Miscellaneous improvements

* allowed passing an axis to `set_labels` as 'labels' argument (closes :issue:`408`).

* added data type (dtype) to array.info (closes :issue:`454`):

>>> arr = ndtest((2, 2), dtype=float)
>>> arr
a\b b0 b1
a0 0.0 1.0
a1 2.0 3.0
>>> arr.info
2 x 2
a [2]: 'a0' 'a1'
b [2]: 'b0' 'b1'
dtype: float64

Fixes
-----
Expand Down
6 changes: 4 additions & 2 deletions larray/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -3211,17 +3211,19 @@ def info(self):
2 x 2
nat [2]: 'BE' 'FO'
sex [2]: 'M' 'F'
dtype: float64
>>> mat1 = LArray(np.ones((2, 2)), [nat, sex], 'test matrix')
>>> mat1.info
test matrix
2 x 2
nat [2]: 'BE' 'FO'
sex [2]: 'M' 'F'
dtype: float64
"""
if self.title:
return ReprString(self.title + '\n' + self.axes.info)
return ReprString(self.title + '\n' + self.axes.info + '\ndtype: ' + self.dtype.name)
else:
return self.axes.info
return ReprString(self.axes.info + '\ndtype: ' + self.dtype.name)

def ratio(self, *axes):
"""Returns an array with all values divided by the sum of values along given axes.
Expand Down
3 changes: 3 additions & 0 deletions larray/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,15 @@ def items(self):
... print("{}: {}".format(k, v.info))
arr2: 4
a [4]: 'a0' 'a1' 'a2' 'a3'
dtype: int64
arr1: 2 x 2
a [2]: 'a0' 'a1'
b [2]: 'b0' 'b1'
dtype: int64
arr3: 3 x 2
a [3]: 'a0' 'a1' 'a2'
b [2]: 'b0' 'b1'
dtype: int64
"""
return self._objects.items()

Expand Down
3 changes: 2 additions & 1 deletion larray/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def test_info(self):
age [116]: 0 1 2 ... 113 114 115
geo [44]: 'A11' 'A12' 'A13' ... 'A92' 'A93' 'A21'
sex [2]: 'M' 'F'
lipro [15]: 'P01' 'P02' 'P03' ... 'P13' 'P14' 'P15'"""
lipro [15]: 'P01' 'P02' 'P03' ... 'P13' 'P14' 'P15'
dtype: float64"""
self.assertEqual(self.larray.info, expected)

def test_str(self):
Expand Down