Exemplo n.º 1
0
    def test_combined_operators(self):
        tested = self.test_obj_sorted.copy()
        tested.filter_population("a", inplace=True)
        tested.limit(3, inplace=True)
        assert tested == test_module.CircuitNodeIds(
            _circuit_ids(['a', 'a', 'a'], [0, 1, 2]))

        tested = self.test_obj_sorted.copy()
        tested = tested.filter_population("a").limit(3)
        assert tested == test_module.CircuitNodeIds(
            _circuit_ids(['a', 'a', 'a'], [0, 1, 2]))
Exemplo n.º 2
0
    def test_init(self):
        values = pd.MultiIndex.from_arrays([['a', 'a', 'b', 'a'], [0, 1, 0,
                                                                   2]])
        tested = test_module.CircuitNodeIds(values, sort_index=False)
        assert tested.index.names == ["population", "node_ids"]
        npt.assert_equal(tested.index.values, values.values)

        tested = test_module.CircuitNodeIds(values, sort_index=True)
        assert tested.index.names == ["population", "node_ids"]
        npt.assert_equal(tested.index.values, np.sort(values.values))

        with pytest.raises(BluepySnapError):
            test_module.CircuitNodeIds(1)
Exemplo n.º 3
0
 def test_sort(self):
     obj = test_module.CircuitNodeIds(_multi_index(), sort_index=False)
     expected = pd.MultiIndex.from_arrays([['a', 'a', 'a', 'b'],
                                           [0, 1, 2, 0]])
     npt.assert_equal(obj.sort().index.values, expected.values)
     obj.sort(inplace=True)
     npt.assert_equal(obj.index.values, expected.values)
Exemplo n.º 4
0
    def test_sample(self):
        with patch("numpy.random.choice", return_value=np.array([0, 3])):
            tested = self.test_obj_unsorted.sample(2, inplace=False)
            assert tested == test_module.CircuitNodeIds(
                _circuit_ids(['a', 'b'], [0, 0]))

        tested = self.test_obj_unsorted.sample(2, inplace=False)
        assert len(tested) == 2

        tested = self.test_obj_unsorted.sample(25, inplace=False)
        assert len(tested) == len(_multi_index())

        values = _multi_index()
        test_obj = test_module.CircuitNodeIds(values)
        assert len(test_obj) == 4
        test_obj.sample(1, inplace=True)
        assert len(test_obj) == 1
Exemplo n.º 5
0
    def test_equal(self):
        values = _multi_index()
        test_obj = test_module.CircuitNodeIds(values)
        other = test_module.CircuitNodeIds(values)
        assert test_obj == other

        diff_values = pd.MultiIndex.from_arrays([['a', 'a', 'b'], [0, 1, 0]])
        other = test_module.CircuitNodeIds(diff_values)
        assert test_obj != other

        # different object
        assert test_obj != 1
        # python2 complains
        assert not test_obj.__eq__(1)

        # same object
        test_obj = test_module.CircuitNodeIds(values)
        same_obj = test_obj
        assert test_obj == same_obj
Exemplo n.º 6
0
    def test_append(self):
        other = test_module.CircuitNodeIds(
            pd.MultiIndex.from_arrays([['c', 'b', 'c'], [0, 5, 1]]))
        expected = test_module.CircuitNodeIds(
            _circuit_ids(['a', 'a', 'b', 'a', 'c', 'b', 'c'],
                         [0, 1, 0, 2, 0, 5, 1]))
        assert self.test_obj_sorted.append(other, inplace=False) == expected

        other = test_module.CircuitNodeIds(
            pd.MultiIndex.from_arrays([['a'], [0]]))
        expected = test_module.CircuitNodeIds(
            _circuit_ids(['a', 'a', 'b', 'a', 'a'], [0, 1, 0, 2, 0]))
        assert self.test_obj_sorted.append(other, inplace=False) == expected

        test_obj = test_module.CircuitNodeIds(_multi_index())
        other = test_module.CircuitNodeIds(
            pd.MultiIndex.from_arrays([['c', 'b', 'c'], [0, 5, 1]]))
        test_obj.append(other, inplace=True)
        expected = test_module.CircuitNodeIds(
            _circuit_ids(['a', 'a', 'b', 'a', 'c', 'b', 'c'],
                         [0, 1, 0, 2, 0, 5, 1]))
        assert test_obj == expected
Exemplo n.º 7
0
 def setup(self):
     self.test_obj_unsorted = test_module.CircuitNodeIds(_multi_index(),
                                                         sort_index=False)
     self.test_obj_sorted = test_module.CircuitNodeIds(_multi_index())
Exemplo n.º 8
0
 def test_limit(self):
     tested = self.test_obj_sorted.limit(2, inplace=False)
     assert len(tested) == 2
     assert tested == test_module.CircuitNodeIds(
         _circuit_ids(['a', 'a'], [0, 1]))