|
106 | 106 | # potential projects using it)
|
107 | 107 |
|
108 | 108 | # ? make pywin32 optional?
|
109 |
| -# ? improve Labeler I don't know how though :) |
110 | 109 | # ? implement dict-like behavior for LArray.axes (to be able to do stuff like
|
111 | 110 | # la.axes['sex'].labels
|
112 | 111 | #
|
@@ -165,7 +164,7 @@ def to_label(e):
|
165 | 164 |
|
166 | 165 | def to_labels(s):
|
167 | 166 | """
|
168 |
| - converts a string to a list of values, useable in Axis |
| 167 | + converts a string to a list of values, usable in Axis |
169 | 168 | """
|
170 | 169 | if isinstance(s, (list, tuple)):
|
171 | 170 | return [to_label(e) for e in s]
|
@@ -349,8 +348,8 @@ def subaxis(self, key, name=None):
|
349 | 348 | key is an integer-based key (slice and fancy indexing are supported)
|
350 | 349 | returns an Axis for a sub-array
|
351 | 350 | """
|
352 |
| - if (isinstance(key, slice) |
353 |
| - and key.start is None and key.stop is None and key.step is None): |
| 351 | + if (isinstance(key, slice) and |
| 352 | + key.start is None and key.stop is None and key.step is None): |
354 | 353 | return self
|
355 | 354 | # we must NOT modify the axis name, even though this creates a new axis
|
356 | 355 | # that is independent from the original one because the original
|
@@ -470,33 +469,6 @@ def __repr__(self):
|
470 | 469 | return "%s[%s]" % (self.axis.name, self.name)
|
471 | 470 |
|
472 | 471 |
|
473 |
| -class Labeler(object): |
474 |
| - def __init__(self): |
475 |
| - self.count = 0 |
476 |
| - |
477 |
| - def get(self, group): |
478 |
| - #XXX: add support for slices here? |
479 |
| - if isinstance(group, ValueGroup): |
480 |
| - return group |
481 |
| - elif np.isscalar(group): |
482 |
| - return group |
483 |
| - elif isinstance(group, slice): |
484 |
| - return slice_to_str(group) |
485 |
| - elif len(group) == 1: |
486 |
| - return group[0] |
487 |
| - else: |
488 |
| - concat = '+'.join(str(v) for v in group) |
489 |
| - if len(concat) < 40: |
490 |
| - return concat |
491 |
| - else: |
492 |
| - #XXX: use "first_value, ..., last_value"? |
493 |
| - #XXX: or "first_value..last_value"? |
494 |
| - #XXX: or "first_value:last_value" if the range is contiguous |
495 |
| - # in the axis (we would need access to the axis then) |
496 |
| - self.count += 1 |
497 |
| - return "group_{}".format(self.count) |
498 |
| - |
499 |
| - |
500 | 472 | class LArray(np.ndarray):
|
501 | 473 | def __new__(cls, data, axes=None):
|
502 | 474 | obj = np.asarray(data).view(cls)
|
@@ -773,27 +745,20 @@ def _group_aggregate(self, op, kwargs, commutative=False):
|
773 | 745 | # it is easier to kill the axis after the fact
|
774 | 746 | killaxis = True
|
775 | 747 | else:
|
776 |
| - labeler = Labeler() |
777 |
| - group_labels = [labeler.get(group) for group in groups] |
778 |
| - |
779 |
| - # I don't think it is a good idea to modify the axis name (eg |
780 |
| - # append "_agg" or "*") even though this creates a new axis |
781 |
| - # that is independent from the original one because the original |
782 |
| - # name is probably what users will want to use to filter |
783 |
| - # the label is the list of values |
784 |
| - |
785 |
| - # make sure each group is a ValueGroup |
786 |
| - # ///create ValueGroups for each group/// |
787 |
| - # and use that as the axis ticks |
788 |
| - #XXX: reusing the same ValueGroup instead of |
789 |
| - vgs = tuple(agg_axis.group(g) |
790 |
| - if (not isinstance(g, ValueGroup) or |
791 |
| - g.axis is not agg_axis) |
792 |
| - else g |
793 |
| - for g in groups) |
794 |
| - assert all(vg.axis is agg_axis for vg in vgs) |
795 |
| - res_axes[agg_axis_idx] = Axis(agg_axis.name, vgs) |
796 |
| - #_labels) |
| 748 | + # make sure each group is a ValueGroup and use that as the axis |
| 749 | + # ticks |
| 750 | + ticks = tuple(agg_axis.group(g) |
| 751 | + if (not isinstance(g, ValueGroup) or |
| 752 | + g.axis is not agg_axis) |
| 753 | + else g |
| 754 | + for g in groups) |
| 755 | + assert all(vg.axis is agg_axis for vg in ticks) |
| 756 | + |
| 757 | + # We do NOT modify the axis name (eg append "_agg" or "*") even |
| 758 | + # though this creates a new axis that is independent from the |
| 759 | + # original one because the original name is what users will |
| 760 | + # want to use to access that axis (eg in .filter kwargs) |
| 761 | + res_axes[agg_axis_idx] = Axis(agg_axis.name, ticks) |
797 | 762 | killaxis = False
|
798 | 763 |
|
799 | 764 | res_shape[agg_axis_idx] = len(groups)
|
|
0 commit comments