2020import pandas as pd
2121import numpy as np
2222from phik import resources , bivariate
23- from phik .simulation import sim_2d_data_patefield
23+ from phik .simulation import sim_2d_data_patefield , CPP_SUPPORT
2424from phik .binning import auto_bin_data , bin_data
2525from phik .phik import phik_observed_vs_expected_from_rebinned_df , phik_from_hist2d
2626from phik .statistics import get_dependent_frequency_estimates
@@ -51,7 +51,7 @@ def test_phik_from_hist2d(self):
5151 observed = df [cols ].hist2d (interval_cols = interval_cols )
5252
5353 phik_value = phik_from_hist2d (observed )
54- self .assertAlmostEqual (phik_value , 0.7685888294891855 )
54+ self .assertAlmostEqual (phik_value , 0.7685888294891855 , places = 3 )
5555
5656 def test_phik_observed_vs_expected_from_hist2d (self ):
5757 """Test the calculation of Phi_K value from hist2d"""
@@ -67,7 +67,7 @@ def test_phik_observed_vs_expected_from_hist2d(self):
6767 expected = get_dependent_frequency_estimates (observed )
6868
6969 phik_value = phik_from_hist2d (observed = observed , expected = expected )
70- self .assertAlmostEqual (phik_value , 0.7685888294891855 )
70+ self .assertAlmostEqual (phik_value , 0.7685888294891855 , places = 3 )
7171
7272 def test_phik_matrix (self ):
7373 """Test the calculation of Phi_K"""
@@ -79,29 +79,25 @@ def test_phik_matrix(self):
7979 interval_cols = ["driver_age" , "mileage" ]
8080 phik_corr = df .phik_matrix (interval_cols = interval_cols )
8181
82- self .assertTrue (
83- np .isclose (
84- phik_corr .values [cols .index ("car_color" ), cols .index ("area" )],
85- 0.5904561614620166 ,
86- )
82+ self .assertAlmostEqual (
83+ phik_corr .values [cols .index ("car_color" ), cols .index ("area" )],
84+ 0.5904561614620166 ,
85+ places = 3 ,
8786 )
88- self .assertTrue (
89- np .isclose (
90- phik_corr .values [cols .index ("area" ), cols .index ("car_color" )],
91- 0.5904561614620166 ,
92- )
87+ self .assertAlmostEqual (
88+ phik_corr .values [cols .index ("area" ), cols .index ("car_color" )],
89+ 0.5904561614620166 ,
90+ places = 3 ,
9391 )
94- self .assertTrue (
95- np .isclose (
96- phik_corr .values [cols .index ("mileage" ), cols .index ("car_size" )],
97- 0.768588987856336 ,
98- )
92+ self .assertAlmostEqual (
93+ phik_corr .values [cols .index ("mileage" ), cols .index ("car_size" )],
94+ 0.768588987856336 ,
95+ places = 3 ,
9996 )
100- self .assertTrue (
101- np .isclose (
102- phik_corr .values [cols .index ("car_size" ), cols .index ("mileage" )],
103- 0.768588987856336 ,
104- )
97+ self .assertAlmostEqual (
98+ phik_corr .values [cols .index ("car_size" ), cols .index ("mileage" )],
99+ 0.768588987856336 ,
100+ places = 3 ,
105101 )
106102
107103 def test_phik_matrix_observed_vs_expected (self ):
@@ -154,9 +150,9 @@ def test_global_phik(self):
154150 car_size = (np .where (gk [1 ] == "car_size" ))[0 ][0 ]
155151 mileage = (np .where (gk [1 ] == "mileage" ))[0 ][0 ]
156152
157- self .assertTrue ( np . isclose ( gk [0 ][area ][0 ], 0.6057528003711345 ) )
158- self .assertTrue ( np . isclose ( gk [0 ][car_size ][0 ], 0.76858883 ) )
159- self .assertTrue ( np . isclose ( gk [0 ][mileage ][0 ], 0.768588987856336 ) )
153+ self .assertAlmostEqual ( gk [0 ][area ][0 ], 0.6057528003711345 , places = 3 )
154+ self .assertAlmostEqual ( gk [0 ][car_size ][0 ], 0.76858883 , places = 3 )
155+ self .assertAlmostEqual ( gk [0 ][mileage ][0 ], 0.768588987856336 , places = 3 )
160156
161157 def test_significance_matrix_asymptotic (self ):
162158 """Test significance calculation"""
@@ -313,6 +309,7 @@ def test_outlier_significance_matrices(self):
313309
314310 self .assertTrue (isinstance (om , dict ))
315311
312+ @pytest .mark .skipif (not CPP_SUPPORT , reason = "cpp not supported" )
316313 def test_simulation_2d_patefield (self ):
317314 """Test simulation code using patefield algorithm."""
318315 og_state = np .random .get_state ()
0 commit comments