Esempio n. 1
0
    def test_arr_anns_at_index(self):
        # Get them, test for desired type and size, content
        datobj = DataObject([1, 2, 3, 4])
        arr_ann = {'anno1': [3, 4, 5, 6], 'anno2': ['ABC', 'DEF', 'GHI', 'JKL']}
        datobj.array_annotate(**arr_ann)

        # Integer as index
        ann_int = datobj.array_annotations_at_index(1)
        self.assertEqual(ann_int, {'anno1': 4, 'anno2': 'DEF'})
        # Negative integer as index
        ann_int_back = datobj.array_annotations_at_index(-2)
        self.assertEqual(ann_int_back, {'anno1': 5, 'anno2': 'GHI'})

        # Slice as index
        ann_slice = datobj.array_annotations_at_index(slice(1, 3))
        self.assert_((ann_slice['anno1'] == np.array([4, 5])).all())
        self.assert_((ann_slice['anno2'] == np.array(['DEF', 'GHI'])).all())

        # Slice from beginning to end
        ann_slice_all = datobj.array_annotations_at_index(slice(0, None))
        self.assert_((ann_slice_all['anno1'] == np.array([3, 4, 5, 6])).all())
        self.assert_((ann_slice_all['anno2'] == np.array(['ABC', 'DEF', 'GHI', 'JKL'])).all())

        # Make sure that original object is edited when editing extracted array_annotations
        ann_slice_all['anno1'][2] = 10
        self.assertEqual(datobj.array_annotations_at_index(2)['anno1'], 10)
Esempio n. 2
0
    def test_arr_anns_at_index(self):
        # Get them, test for desired type and size, content
        datobj = DataObject([1, 2, 3, 4])
        arr_ann = {
            'anno1': [3, 4, 5, 6],
            'anno2': ['ABC', 'DEF', 'GHI', 'JKL']
        }
        datobj.array_annotate(**arr_ann)

        # Integer as index
        ann_int = datobj.array_annotations_at_index(1)
        self.assertEqual(ann_int, {'anno1': 4, 'anno2': 'DEF'})
        # Negative integer as index
        ann_int_back = datobj.array_annotations_at_index(-2)
        self.assertEqual(ann_int_back, {'anno1': 5, 'anno2': 'GHI'})

        # Slice as index
        ann_slice = datobj.array_annotations_at_index(slice(1, 3))
        self.assertTrue((ann_slice['anno1'] == np.array([4, 5])).all())
        self.assertTrue((ann_slice['anno2'] == np.array(['DEF', 'GHI'])).all())

        # Slice from beginning to end
        ann_slice_all = datobj.array_annotations_at_index(slice(0, None))
        self.assertTrue((ann_slice_all['anno1'] == np.array([3, 4, 5,
                                                             6])).all())
        self.assertTrue(
            (ann_slice_all['anno2'] == np.array(['ABC', 'DEF', 'GHI',
                                                 'JKL'])).all())

        # Make sure that original object is edited when editing extracted array_annotations
        ann_slice_all['anno1'][2] = 10
        self.assertEqual(datobj.array_annotations_at_index(2)['anno1'], 10)
Esempio n. 3
0
    def test_array_annotate(self):
        # Calls _check_array_annotations, so no need to test for these Errors here
        datobj = DataObject([2, 3, 4])
        arr_ann = {'anno1': [3, 4, 5], 'anno2': ['ABC', 'DEF', 'GHI']}

        # Pass annotations
        datobj.array_annotate(**arr_ann)

        # Make sure they are correct
        self.assertTrue((datobj.array_annotations['anno1'] == np.array([3, 4, 5])).all())
        self.assertTrue(
            (datobj.array_annotations['anno2'] == np.array(['ABC', 'DEF', 'GHI'])).all())
        self.assertIsInstance(datobj.array_annotations, ArrayDict)