Esempio n. 1
0
    def test_store_filter_format_inexact_array_a(self) -> None:
        sf1 = StoreFilter(
                value_format_float_positional='{:.8f}',
                value_format_float_scientific='{:.8f}',
                value_format_complex_positional='{:.8f}',
                value_format_complex_scientific='{:.8f}',
                )

        a1 = np.array([0.83255500, 0.0000011193, 0.832555, 20])
        a2 = np.array([0.413-0.000000593j, 0.4123-0.593j, 0.832555, 20+3j])

        post1 = sf1._format_inexact_array(a1, None)
        self.assertEqual(post1.tolist(), ['0.83255500', '0.00000112', '0.83255500', '20.00000000'])

        post2 = a2.astype(object)
        post3 = sf1._format_inexact_array(a2, post2)
        self.assertEqual(id(post3), id(post2))

        self.assertEqual(post3.tolist(),
                ['0.41300000-0.00000059j', '0.41230000-0.59300000j', '0.83255500+0.00000000j', '20.00000000+3.00000000j'])

        # originate with object arrays
        a3 = np.array([0.83255500, 0.0000011193, 0.832555, 20]).astype(object)
        a4 = np.array([0.413-0.000000593j, 0.4123-0.593j, 0.832555, 20+3j]).astype(object)

        post4 = sf1._format_inexact_array(a3, None)
        self.assertEqual(post4.tolist(), ['0.83255500', '0.00000112', '0.83255500', '20.00000000'])

        post5 = a4.astype(object)
        post6 = sf1._format_inexact_array(a4, post5)
        self.assertEqual(id(post5), id(post6))

        self.assertEqual(post6.tolist(),
                ['0.41300000-0.00000059j', '0.41230000-0.59300000j', '0.83255500+0.00000000j', '20.00000000+3.00000000j'])
Esempio n. 2
0
    def test_store_filter_format_inexact_array_c(self) -> None:
        sf1 = StoreFilter(
            value_format_float_positional='{:.3f}',
            value_format_float_scientific='{:.3f}',
            value_format_complex_positional='{:.3f}',
            value_format_complex_scientific='{:.3f}',
        )

        a1 = np.array([0.83255500, None, 0.0000011193, 0.832555, 20, True],
                      dtype=object)
        a2 = np.array([
            0.413 - 0.000000593j, 0.4123 - 0.593j, 'foo', False, 100, 0.832555,
            20 + 3j
        ],
                      dtype=object)

        post1 = sf1._format_inexact_array(a1, None)
        post2 = sf1._format_inexact_array(a2, None)

        self.assertEqual(post1.tolist(),
                         ['0.833', None, '0.000', '0.833', 20, True])

        self.assertEqual(post2.tolist(), [
            '0.413-0.000j', '0.412-0.593j', 'foo', False, 100, '0.833',
            '20.000+3.000j'
        ])
Esempio n. 3
0
    def test_store_filter_format_inexact_array_b(self) -> None:
        sf1 = StoreFilter(
                value_format_float_positional='{:.2e}',
                value_format_float_scientific='{:.2e}',
                value_format_complex_positional='{:.2e}',
                value_format_complex_scientific='{:.2e}',
                )

        a1 = np.array([0.83255500, 0.0000011193, 0.832555, 20]).reshape(2, 2)
        a2 = np.array([0.413-0.000000593j, 0.4123-0.593j, 0.832555, 20+3j]).reshape(2, 2)

        post1 = sf1._format_inexact_array(a1, None)
        post2 = sf1._format_inexact_array(a2, None)

        self.assertEqual(post1.tolist(),
                [['8.33e-01', '1.12e-06'], ['8.33e-01', '2.00e+01']]
                )

        self.assertEqual(post2.tolist(),
                [['4.13e-01-5.93e-07j', '4.12e-01-5.93e-01j'],
                ['8.33e-01+0.00e+00j', '2.00e+01+3.00e+00j']])