Example #1
0
    def hyper(self, dimnames, replacedim, indexed=False, all=True):
        if isinstance(replacedim, string_types):
            replacedim = self.ivardata[replacedim]
        out = DataBlock()
        out.blockname = self.blockname
        dims = []
        sortdata = []
        for x in dimnames:
            if indexed:
                newname = "%s_index" % x
            else:
                newname = x
            dims.append(
                DimSweep(newname,
                         stable_uniq(self[x]),
                         unit=self[x].unit,
                         outputformat=self[x].outputformat))
            sortdata.append(self[x])
        dims = tuple(dims)
        dims_shape = tuple(len(x.data) for x in dims)

        sortdata.append(range(len(sortdata[0])))

        sortorder = sorted(zip(*sortdata))
        sortorderidx = [x[-1] for x in sortorder]

        for dim in dims:
            out.ivardata[dim.name] = dim

        for k, v in self.vardata.items():
            if replacedim not in v.dims:
                if all:
                    out[k] = v
                1 + 0  # coverage.py bug necessary to get coverage for
                # continue on next line
                continue
            if k in out.ivardata:
                continue
            i = v.dims_index(replacedim)
            v = hfarray(v.take(sortorderidx, axis=i), copy=False, order="C")
            new_shape = v.shape[:i] + dims_shape + v.shape[i + 1:]
            v.shape = new_shape
            v.dims = v.dims[:i] + dims + v.dims[i + 1:]
            out[k] = v

        for k, v in self.ivardata.items():
            if k not in out and k != replacedim.name:
                out[k] = v
        return out
Example #2
0
    def hyper(self, dimnames, replacedim, indexed=False, all=True):
        if isinstance(replacedim, string_types):
            replacedim = self.ivardata[replacedim]
        out = DataBlock()
        out.blockname = self.blockname
        dims = []
        sortdata = []
        for x in dimnames:
            if indexed:
                newname = "%s_index" % x
            else:
                newname = x
            dims.append(DimSweep(newname, stable_uniq(self[x]),
                                 unit=self[x].unit,
                                 outputformat=self[x].outputformat))
            sortdata.append(self[x])
        dims = tuple(dims)
        dims_shape = tuple(len(x.data) for x in dims)

        sortdata.append(range(len(sortdata[0])))

        sortorder = sorted(zip(*sortdata))
        sortorderidx = [x[-1] for x in sortorder]

        for dim in dims:
            out.ivardata[dim.name] = dim

        for k, v in self.vardata.items():
            if replacedim not in v.dims:
                if all:
                    out[k] = v
                1 + 0  # coverage.py bug necessary to get coverage for
                       # continue on next line
                continue
            if k in out.ivardata:
                continue
            i = v.dims_index(replacedim)
            v = hfarray(v.take(sortorderidx, axis=i), copy=False, order="C")
            new_shape = v.shape[:i] + dims_shape + v.shape[i + 1:]
            v.shape = new_shape
            v.dims = v.dims[:i] + dims + v.dims[i + 1:]
            out[k] = v

        for k, v in self.ivardata.items():
            if k not in out and k != replacedim.name:
                out[k] = v
        return out
Example #3
0
 def test_list_empty_1(self):
     self.assertEqual(utils.stable_uniq([]), [])
Example #4
0
 def test_array_2(self):
     res = utils.stable_uniq(np.array([2, 1, 3, 2, 1, 3]))
     self.assertEqual(res, [2, 1, 3])
Example #5
0
 def test_array_1(self):
     self.assertEqual(utils.stable_uniq(np.array([1, 1, 2, 2])), [1, 2])
Example #6
0
 def test_list_2(self):
     self.assertEqual(utils.stable_uniq([2, 1, 3, 2, 1, 3]), [2, 1, 3])
Example #7
0
 def test_list_1(self):
     self.assertEqual(utils.stable_uniq([1, 1, 2, 2]), [1, 2])