Tuesday, 7 May 2019

Unittest equality of empty record arrays

I noticed the following unittest.TestCase assertion failing and am wondering how to correctly compare empty recarrays:

fails:

self.assertEqual(
    np.array(
        [],
        dtype=[
            ('time', 'datetime64[ns]'),
            ('end_time', int)
        ]
    ).view(np.recarray),
    np.array(
        [],
        dtype=[
            ('time', 'datetime64[ns]'),
            ('end_time', int)
        ]
    ).view(np.recarray)
)

passes:

self.assertEqual(
    np.array(
        [(1,1)],
        dtype=[
            ('time', 'datetime64[ns]'),
            ('end_time', int)
        ]
    ).view(np.recarray),
    np.array(
        [(1,1)],
        dtype=[
            ('time', 'datetime64[ns]'),
            ('end_time', int)
        ]
    ).view(np.recarray)
)

Is this a bug or am I doing something wrong here?



from Unittest equality of empty record arrays

No comments:

Post a Comment