def test_bad_inputs(self, *mocks): # columns and column_inds cannot be specified simultaneously with self.assertRaisesRegex( ValueError, "Can only specify either `column_names` or " "`column_inds` but not both " "simultaneously"): graphs.plot_histograms(self.profiler, column_names=['test'], column_inds=[1]) # when column_names is bad bad_columns_input = [-1, [{}, 1], {}, 3.2, [3.2]] for bad_input in bad_columns_input: with self.assertRaisesRegex( ValueError, "`column_names` must be a list integers" " or strings matching the names of " "columns in the profiler."): graphs.plot_histograms(self.profiler, column_names=bad_input) # when column_inds is bad bad_columns_inds_input = [-1, [{}, 1], {}, 3.2, [3.2], ['test']] for bad_input in bad_columns_inds_input: with self.assertRaisesRegex( ValueError, "`column_inds` must be a list of " "integers matching column indexes in " "the profiler"): graphs.plot_histograms(self.profiler, column_inds=bad_input) # test column name doesn't exist with self.assertRaisesRegex( ValueError, "Column \"a\" is not found as a profiler " "column"): graphs.plot_histograms(self.profiler, ["int", "a"])
def test_no_column_plottable(self, plot_col_mock, plt_mock): with self.assertWarnsRegex( Warning, "No plots were constructed" " because no int or float columns " "were found in columns"): fig = graphs.plot_histograms(self.profiler, ["str", "datetime"]) self.assertIsNone(fig)
def test_empty_profiler(self, plot_col_mock, plt_mock): with self.assertWarnsRegex( Warning, "No plots were constructed" " because no int or float columns " "were found in columns"): fig = graphs.plot_histograms( dp.StructuredProfiler(data=None, options=self.options)) self.assertIsNone(fig)
def test_no_columns_specified(self, plot_col_mock, plt_mock): graphsplot = graphs.plot_histograms(self.profiler) self.assertEqual(2, plot_col_mock.call_count) # grabs the first argument passed into the plot col call and validates # it is the column profiler and its name matches what we expect it to self.assertEqual("int", plot_col_mock.call_args_list[0][0][0].name) # grabs the second argument passed into the plot col call and validates # it is the column profiler and its name matches what we expect it to self.assertEqual("float", plot_col_mock.call_args_list[1][0][0].name) self.assertIsInstance(graphsplot, plt.Figure)
def test_specify_column_inds(self, plot_col_mock, plt_mock): graphsplot = graphs.plot_histograms(self.profiler, column_inds=[2]) self.assertEqual(1, plot_col_mock.call_count) self.assertEqual("float", plot_col_mock.call_args_list[0][0][0].name) self.assertIsInstance(graphsplot, plt.Figure)