Skip to content
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
3 changes: 1 addition & 2 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ Modifying/Selecting
Axis.rename
Axis.extend
Axis.insert
Axis.replace
Axis.apply
Axis.set_labels
Axis.union
Axis.intersection
Axis.difference
Expand Down
14 changes: 14 additions & 0 deletions doc/source/changes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Change log
##########

Version 0.36
============

In development.

CORE
----
.. include:: ./changes/version_0_36.rst.inc

EDITOR
------
.. include:: ./changes/editor/version_0_36.rst.inc


Version 0.35
============

Expand Down
80 changes: 80 additions & 0 deletions doc/source/changes/version_0_36.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
.. py:currentmodule:: larray


Syntax changes
^^^^^^^^^^^^^^

* ``Axis.apply()`` and ``Axis.replace()`` are deprecated in favor of
:py:obj:`Axis.set_labels()`.

* renamed ``Array.old_method_name()`` to :py:obj:`Array.new_method_name()` (closes :issue:`1`).

* renamed ``old_argument_name`` argument of :py:obj:`Array.method_name()` to ``new_argument_name``.


Backward incompatible changes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* other backward incompatible changes


New features
^^^^^^^^^^^^

* added a feature (see the :ref:`miscellaneous section <misc>` for details). It works on :ref:`api-axis` and
:ref:`api-group` objects.

Here is an example of the new feature:

>>> arr = ndtest((2, 3))
>>> arr
a\b b0 b1 b2
a0 0 1 2
a1 3 4 5

And it can also be used like this:

>>> arr = ndtest("a=a0..a2")
>>> arr
a a0 a1 a2
0 1 2

* added another feature in the editor (closes :editor_issue:`1`).

.. note::

- It works for foo bar !
- It does not work for foo baz !


.. _misc:

Miscellaneous improvements
^^^^^^^^^^^^^^^^^^^^^^^^^^

* :py:obj:`Array.set_labels()` and :py:obj:`Axis.set_labels()` (formerly
``Axis.replace()`` and ``Axis.apply()``) now accepts slices, Groups or
selection strings as the labels to change, and callable and
"creation strings" as the new labels. This makes it easier to change
only a subset of labels or to change several labels in the same way
(closes :issue:`906`).

>>> arr = ndtest((2, 3))
>>> arr
a\b b0 b1 b2
a0 0 1 2
a1 3 4 5
>>> arr.set_labels({'b1:': str.upper, 'a1': 'A-ONE'})
a\b b0 B1 B2
a0 0 1 2
A-ONE 3 4 5
>>> arr.set_labels('b1:', 'B1..B2')
a\b b0 B1 B2
a0 0 1 2
a1 3 4 5


Fixes
^^^^^

* fixed something (closes :issue:`1`).
2 changes: 1 addition & 1 deletion larray/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.35'
__version__ = '0.36-dev'


from larray.core.axis import Axis, AxisCollection, X
Expand Down
38 changes: 21 additions & 17 deletions larray/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def concat(arrays, axis=0, dtype=None):

# switch to object dtype if labels are of incompatible types, so that we do not implicitly convert numeric types to
# strings (numpy should not do this in the first place but that is another story). This can happen for example when
# we want to add a "total" tick to a numeric axis (eg age).
# we want to add a "total" label to a numeric axis (eg age).
combined_axis = Axis(concatenate_ndarrays(arrays_labels), name)

# combine all axes (using labels from any side if any)
Expand Down Expand Up @@ -2147,7 +2147,7 @@ def sort_values(self, key=None, axis=None, ascending=True) -> 'Array':
# 1 2 0, axis='nat')
# which sorts the *data* correctly, but the labels on the nat axis are not sorted
# (because the __getitem__ in that case reuse the key axis as-is -- like it should).
# Both use cases have value, but I think reordering the ticks should be the default.
# Both use cases have value, but I think reordering the labels should be the default.
# Now, I am unsure where to change this. Probably in IGroupMaker.__getitem__,
# but then how do I get the "not reordering labels" behavior that I have now?
# FWIW, using .data, I get IGroup([1, 2, 0], axis='nat'), which works.
Expand Down Expand Up @@ -2684,19 +2684,19 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam
# get list of labels for each axis (except the last one if wide=True)
labels = [ensure_no_numpy_type(axis.labels) for axis in axes]

# creates vertical lines (ticks is a list of list)
# creates vertical lines (labels is a list of list)
if self.ndim == 1 and wide:
if dump_axes_names is True:
# There is no vertical axis, so the axis name should not have
# any "tick" below it and we add an empty "tick".
ticks = [['']]
# any "label" below it and we add an empty "label".
labels = [['']]
else:
# There is no vertical axis but no axis name either
ticks = [[]]
labels = [[]]
elif light:
ticks = light_product(*labels)
labels = light_product(*labels)
else:
ticks = Product(labels)
labels = Product(labels)

# computes the first line
other_colnames = ensure_no_numpy_type(self.axes[-1].labels) if wide else [value_name]
Expand All @@ -2706,14 +2706,14 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam
if maxlines != -1 and height > maxlines:
# replace middle lines of the table by '...'.
# We show only the first and last edgeitems lines.
res2d.extend([list(tick) + dataline
for tick, dataline in zip(ticks[:edgeitems], ensure_no_numpy_type(data[:edgeitems]))])
res2d.extend([list(label) + dataline
for label, dataline in zip(labels[:edgeitems], ensure_no_numpy_type(data[:edgeitems]))])
res2d.append(["..."] * (self.ndim - 1 + width))
res2d.extend([list(tick) + dataline
for tick, dataline in zip(ticks[-edgeitems:], ensure_no_numpy_type(data[-edgeitems:]))])
res2d.extend([list(label) + dataline
for label, dataline in zip(labels[-edgeitems:], ensure_no_numpy_type(data[-edgeitems:]))])
else:
# all other lines (labels of N-1 first axes + data)
res2d.extend([list(tick) + ensure_no_numpy_type(dataline) for tick, dataline in zip(ticks, data)])
res2d.extend([list(label) + ensure_no_numpy_type(dataline) for label, dataline in zip(labels, data)])

if na_repr != 'as_is':
res2d = [[na_repr if value != value else value
Expand Down Expand Up @@ -7513,7 +7513,6 @@ def __array__(self, dtype=None, copy=None):

__array_priority__ = 100

# TODO: this should be a thin wrapper around a method in AxisCollection
def set_labels(self, axis=None, labels=None, inplace=False, **kwargs) -> 'Array':
r"""Replace the labels of one or several axes of the array.

Expand Down Expand Up @@ -7611,13 +7610,18 @@ def set_labels(self, axis=None, labels=None, inplace=False, **kwargs) -> 'Array'
nat\sex Men F
Belgian 0 1
FO 2 3

>>> a.set_labels({'M:F': str.lower, 'BE': 'Belgian', 'FO': 'Foreigner'})
nat\sex m f
Belgian 0 1
Foreigner 2 3
"""
axes = self.axes.set_labels(axis, labels, **kwargs)
new_axes = self.axes.set_labels(axis, labels, **kwargs)
if inplace:
self.axes = axes
self.axes = new_axes
return self
else:
return Array(self.data, axes)
return Array(self.data, new_axes)

def astype(self, dtype, order='K', casting='unsafe', subok=True, copy=True) -> 'Array':
return Array(self.data.astype(dtype, order, casting, subok, copy), self.axes)
Expand Down
Loading