mercredi 26 décembre 2018

How to test the phase angle in pandas dataframe, using numpy.testing in Python3?

I have a dataframe

import numpy as np
import pandas as pd

dat1 = {
        'f': [0],
        'abs_1': [1],
        'angle_1': [-np.pi]
       }


dat2 = {
        'f': [0],
        'abs_1': [1],
        'angle_1': [np.pi]
       }

df1 = pd.DataFrame(dat1).set_index('f')
df2 = pd.DataFrame(dat2).set_index('f')

# test using np.testing
np.testing.assert_array_almost_equal(df1, df2)

According to maths, the phase angle has the period of 2*np.pi. This means:

-np.pi = -np.pi + 2*np.pi = np.pi

So df1 and df2 are the same.

Do you know how to make the test pass?

By the way, in my real application, the df1 and df2 can have many more columns, half of them are abs values and the other half are angle values.

Aucun commentaire:

Enregistrer un commentaire