Skip to content

Commit fa4e070

Browse files
committed
kill Labeler, it is useless now
1 parent f49732b commit fa4e070

File tree

1 file changed

+17
-52
lines changed

1 file changed

+17
-52
lines changed

larray.py

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
# potential projects using it)
107107

108108
# ? make pywin32 optional?
109-
# ? improve Labeler I don't know how though :)
110109
# ? implement dict-like behavior for LArray.axes (to be able to do stuff like
111110
# la.axes['sex'].labels
112111
#
@@ -165,7 +164,7 @@ def to_label(e):
165164

166165
def to_labels(s):
167166
"""
168-
converts a string to a list of values, useable in Axis
167+
converts a string to a list of values, usable in Axis
169168
"""
170169
if isinstance(s, (list, tuple)):
171170
return [to_label(e) for e in s]
@@ -349,8 +348,8 @@ def subaxis(self, key, name=None):
349348
key is an integer-based key (slice and fancy indexing are supported)
350349
returns an Axis for a sub-array
351350
"""
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):
354353
return self
355354
# we must NOT modify the axis name, even though this creates a new axis
356355
# that is independent from the original one because the original
@@ -470,33 +469,6 @@ def __repr__(self):
470469
return "%s[%s]" % (self.axis.name, self.name)
471470

472471

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-
500472
class LArray(np.ndarray):
501473
def __new__(cls, data, axes=None):
502474
obj = np.asarray(data).view(cls)
@@ -773,27 +745,20 @@ def _group_aggregate(self, op, kwargs, commutative=False):
773745
# it is easier to kill the axis after the fact
774746
killaxis = True
775747
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)
797762
killaxis = False
798763

799764
res_shape[agg_axis_idx] = len(groups)

0 commit comments

Comments
 (0)