88class TestMissingMethods (unittest .TestCase ):
99 def setUp (self ):
1010 # Crear un DataFrame de ejemplo para usar en los tests
11- self .df = pd .DataFrame ({
12- 'A' : [1 , 2 , None , 4 , 5 ],
13- 'B' : [None , 2 , 3 , 4 , 5 ],
14- 'C' : [1 , 2 , None , None , 5 ],
15- 'D' : [1 , 2 , 3 , 4 , None ],
16- })
11+ self .df = pd .DataFrame (
12+ {
13+ "A" : [1 , 2 , None , 4 , 5 ],
14+ "B" : [None , 2 , 3 , 4 , 5 ],
15+ "C" : [1 , 2 , None , None , 5 ],
16+ "D" : [1 , 2 , 3 , 4 , None ],
17+ }
18+ )
1719 self .missing = missing (self .df )
1820
1921 # Apagar las advertencias de FutureWarning
@@ -22,19 +24,23 @@ def setUp(self):
2224 # Apagar las advertencias de DeprecationWarning
2325 warnings .filterwarnings ("ignore" , category = DeprecationWarning )
2426
27+ def test_init_with_non_dataframe (self ):
28+ with self .assertRaises (TypeError ):
29+ missing_obj = missing ("invalid_param" )
30+
2531 # Tabular functions tests
2632
2733 def test_number_missing (self ):
2834 self .assertEqual (self .missing .number_missing (), 5 )
2935
3036 def test_number_missing_by_column (self ):
31- self .assertEqual (self .missing .number_missing_by_column ()['A' ], 1 )
37+ self .assertEqual (self .missing .number_missing_by_column ()["A" ], 1 )
3238
3339 def test_number_complete (self ):
3440 self .assertEqual (self .missing .number_complete (), 15 )
3541
3642 def test_number_complete_by_column (self ):
37- self .assertEqual (self .missing .number_complete_by_column ()['A' ], 4 )
43+ self .assertEqual (self .missing .number_complete_by_column ()["A" ], 4 )
3844
3945 def test_impute_mean (self ):
4046 df_imputed = self .missing .impute_mean ()
@@ -80,11 +86,11 @@ def test_missing_case_table(self):
8086 self .assertIsInstance (table , pd .DataFrame )
8187
8288 def test_missing_variable_span (self ):
83- span = self .missing .missing_variable_span (variable = 'A' , span_every = 2 )
89+ span = self .missing .missing_variable_span (variable = "A" , span_every = 2 )
8490 self .assertIsInstance (span , pd .DataFrame )
8591
8692 def test_missing_variable_run (self ):
87- run = self .missing .missing_variable_run (variable = 'A' )
93+ run = self .missing .missing_variable_run (variable = "A" )
8894 self .assertIsInstance (run , pd .DataFrame )
8995
9096 def test_sort_variables_by_missingness (self ):
@@ -112,16 +118,18 @@ def test_missing_case_plot(self):
112118 self .assertIsNone (self .missing .missing_case_plot ())
113119
114120 def test_missing_variable_span_plot (self ):
115- self .assertIsNone (self .missing .missing_variable_span_plot (variable = 'A' , span_every = 2 ))
121+ self .assertIsNone (
122+ self .missing .missing_variable_span_plot (variable = "A" , span_every = 2 )
123+ )
116124
117125 def test_missing_upsetplot (self ):
118- plot = self .missing .missing_upsetplot (variables = ['A' , 'B' ])
126+ plot = self .missing .missing_upsetplot (variables = ["A" , "B" ])
119127 self .assertIsNotNone (plot )
120128
121129 def test_missing_upsetplot_2 (self ):
122130 plot = self .missing .missing_upsetplot ()
123131 self .assertIsNotNone (plot )
124132
125133
126- if __name__ == ' __main__' :
134+ if __name__ == " __main__" :
127135 unittest .main ()
0 commit comments