idx
int64
0
7.85k
idx_lca
int64
0
223
offset
int64
162
55k
repo
stringclasses
62 values
commit_hash
stringclasses
113 values
target_file
stringclasses
134 values
line_type_lca
stringclasses
7 values
ground_truth
stringlengths
1
46
in_completions
bool
1 class
completion_type
stringclasses
6 values
non_dunder_count_intellij
int64
0
529
non_dunder_count_jedi
int64
0
128
start_with_
bool
2 classes
first_occurrence
bool
2 classes
intellij_completions
listlengths
1
532
jedi_completions
listlengths
3
148
prefix
stringlengths
162
55k
7,666
216
4,013
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
data
true
statement
98
102
false
false
[ "data", "in_pd_df_by_series", "ref_pd_series", "test_add_df_with_series", "assertEqual", "test_add_df_with_empty_series", "test_add_df_with_series_and_with_include_index", "test_add_df_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_df_with_empty_series", "type": "function" }, { "name": "test_add_df_with_series", "type": "function" }, { "name": "test_add_df_with_series_and_with_include_index", "type": "function" }, { "name": "test_add_df_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.
7,667
216
4,018
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
build
true
function
28
30
false
false
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.
7,668
216
4,160
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
data
true
statement
97
101
false
false
[ "data", "ref_pd_series", "in_pd_df_by_series", "test_add_data_frame_with_series", "assertEqual", "test_add_data_frame_with_empty_series", "test_add_data_frame_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.
7,669
216
4,165
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
add_data_frame
true
function
28
30
false
false
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.
7,670
216
4,262
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
data
true
statement
97
101
false
false
[ "data", "test_add_data_frame_with_series", "ref_pd_series", "in_pd_df_by_series", "assertEqual", "test_add_data_frame_with_empty_series", "test_add_data_frame_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.
7,671
216
4,267
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
build
true
function
28
30
false
false
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.
7,672
216
4,355
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
data
true
statement
97
101
false
false
[ "data", "ref_pd_series", "in_pd_df_by_series", "assertEqual", "test_add_data_frame_with_empty_series", "test_add_data_frame_with_series", "test_add_data_frame_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.
7,673
216
4,360
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
add_data_frame
true
function
28
30
false
false
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.
7,674
216
4,380
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
in_pd_series_dimension
true
statement
97
101
false
false
[ "data", "ref_pd_series", "test_add_data_frame_with_empty_series", "in_pd_df_by_series", "test_add_data_frame_with_series_contains_na", "test_add_data_frame_with_series", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.
7,675
216
4,417
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
data
true
statement
97
101
false
false
[ "data", "ref_pd_series", "in_pd_df_by_series", "assertEqual", "test_add_data_frame_with_empty_series", "test_add_data_frame_with_series", "test_add_data_frame_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.
7,676
216
4,422
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
add_data_frame
true
function
28
30
false
false
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.
7,677
216
4,442
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
in_pd_series_measure
true
statement
97
101
false
false
[ "data", "ref_pd_series", "test_add_data_frame_with_empty_series", "in_pd_df_by_series", "in_pd_series_dimension", "test_add_data_frame_with_series", "test_add_data_frame_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.
7,678
216
4,507
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
ref_pd_series
true
statement
97
101
false
false
[ "data", "in_pd_df_by_series", "in_pd_series_dimension", "ref_pd_series", "ref_pd_series_with_nan", "test_add_data_frame_with_empty_series", "test_add_data_frame_with_series", "test_add_data_frame_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.
7,679
216
4,539
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
data
true
statement
97
101
false
false
[ "data", "ref_pd_series", "in_pd_df_by_series", "assertEqual", "in_pd_series_dimension", "test_add_data_frame_with_empty_series", "test_add_data_frame_with_series", "test_add_data_frame_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.
7,680
216
4,544
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
build
true
function
28
30
false
false
[ "add_data_frame", "add_df", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.
7,681
216
4,644
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
data
true
statement
97
101
false
false
[ "data", "test_add_data_frame_with_series", "ref_pd_series", "in_pd_df_by_series", "assertEqual", "test_add_data_frame_with_empty_series", "test_add_data_frame_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.
7,682
216
4,649
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
add_data_frame
true
function
28
30
false
false
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.
7,683
216
4,669
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
in_pd_series_dimension_with_nan
true
statement
97
101
false
false
[ "data", "test_add_data_frame_with_series", "ref_pd_series", "test_add_data_frame_with_empty_series", "in_pd_df_by_series", "test_add_data_frame_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.
7,684
216
4,715
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
data
true
statement
97
101
false
false
[ "data", "test_add_data_frame_with_series", "ref_pd_series", "in_pd_df_by_series", "assertEqual", "test_add_data_frame_with_empty_series", "test_add_data_frame_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.
7,685
216
4,720
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
add_data_frame
true
function
28
30
false
false
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.
7,686
216
4,740
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
in_pd_series_measure_with_nan
true
statement
97
101
false
false
[ "data", "test_add_data_frame_with_series", "ref_pd_series", "test_add_data_frame_with_empty_series", "in_pd_df_by_series", "test_add_data_frame_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.
7,687
216
4,814
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
ref_pd_series_with_nan
true
statement
97
101
false
false
[ "data", "ref_pd_series", "in_pd_df_by_series", "in_pd_series_dimension", "ref_pd_df_by_series_with_duplicated_popularity", "test_add_data_frame_with_empty_series", "test_add_data_frame_with_series", "test_add_data_frame_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.
7,688
216
4,855
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
data
true
statement
97
101
false
false
[ "data", "test_add_data_frame_with_series", "ref_pd_series", "in_pd_df_by_series", "assertEqual", "test_add_data_frame_with_empty_series", "test_add_data_frame_with_series_contains_na", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_with_empty_series", "type": "function" }, { "name": "test_add_data_frame_with_series", "type": "function" }, { "name": "test_add_data_frame_with_series_contains_na", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.
7,689
216
4,860
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
build
true
function
28
30
false
false
[ "add_data_frame", "add_df", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.
7,690
216
4,980
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
data
true
statement
96
100
false
false
[ "data", "assertEqual", "test_add_df_index_with_df", "in_pd_series_measure_with_index", "in_pd_series_dimension_with_index", "test_add_df_index_with_none", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_df_index_with_df", "type": "function" }, { "name": "test_add_df_index_with_none", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.
7,691
216
4,985
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
add_df_index
true
function
28
30
false
true
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.
7,692
216
5,094
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
data
true
statement
96
100
false
false
[ "data", "assertEqual", "test_add_df_index_with_df", "in_pd_series_measure_with_index", "in_pd_series_dimension_with_index", "test_add_df_index_with_none", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_df_index_with_df", "type": "function" }, { "name": "test_add_df_index_with_none", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.
7,693
216
5,099
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
build
true
function
28
30
false
false
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.
7,694
216
5,186
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
in_pd_df_by_series_with_index
true
statement
96
100
false
false
[ "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_df_by_series_with_duplicated_popularity", "data", "in_pd_df_by_series", "test_add_df_index_with_df", "test_add_df_index_with_none", "asset_dir", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_df_index_with_df", "type": "function" }, { "name": "test_add_df_index_with_none", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.
7,695
216
5,229
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
data
true
statement
96
100
false
false
[ "data", "assertEqual", "test_add_df_index_with_none", "in_pd_series_measure_with_index", "in_pd_series_dimension_with_index", "test_add_df_index_with_df", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_df_index_with_df", "type": "function" }, { "name": "test_add_df_index_with_none", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.
7,696
216
5,234
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
add_df_index
true
function
28
30
false
false
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.
7,697
216
5,315
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
random
ref_pd_df_by_series_only_index
true
statement
96
100
false
true
[ "data", "in_pd_series_measure_with_index", "in_pd_series_dimension_with_index", "in_pd_df_by_series_with_index", "ref_pd_series_only_index", "test_add_df_index_with_df", "test_add_df_index_with_none", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_df_index_with_df", "type": "function" }, { "name": "test_add_df_index_with_none", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.
7,698
216
5,364
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
data
true
statement
96
100
false
false
[ "data", "assertEqual", "test_add_df_index_with_none", "in_pd_df_by_series_with_index", "in_pd_series_measure_with_index", "test_add_df_index_with_df", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_df_index_with_df", "type": "function" }, { "name": "test_add_df_index_with_none", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.
7,699
216
5,369
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
build
true
function
28
30
false
false
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.
7,700
216
5,504
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
data
true
statement
96
100
false
false
[ "data", "assertEqual", "test_add_data_frame_index_with_df", "in_pd_series_measure_with_index", "in_pd_series_dimension_with_index", "test_add_data_frame_index_with_none", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_index_with_df", "type": "function" }, { "name": "test_add_data_frame_index_with_none", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.
7,701
216
5,509
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
add_data_frame_index
true
function
28
30
false
true
[ "add_data_frame", "add_df", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.
7,702
216
5,619
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
data
true
statement
96
100
false
false
[ "data", "assertEqual", "test_add_data_frame_index_with_df", "in_pd_series_measure_with_index", "in_pd_series_dimension_with_index", "test_add_data_frame_index_with_none", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_index_with_df", "type": "function" }, { "name": "test_add_data_frame_index_with_none", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.
7,703
216
5,624
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
build
true
function
28
30
false
false
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.
7,704
216
5,719
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
in_pd_df_by_series_with_index
true
statement
96
100
false
false
[ "data", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series", "test_add_data_frame_index_with_df", "test_add_data_frame_index_with_none", "asset_dir", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_index_with_df", "type": "function" }, { "name": "test_add_data_frame_index_with_none", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.
7,705
216
5,762
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
data
true
statement
96
100
false
false
[ "data", "assertEqual", "test_add_data_frame_index_with_none", "in_pd_series_measure_with_index", "in_pd_series_dimension_with_index", "test_add_data_frame_index_with_df", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_index_with_df", "type": "function" }, { "name": "test_add_data_frame_index_with_none", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.
7,706
216
5,767
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
add_data_frame_index
true
function
28
30
false
false
[ "add_data_frame", "add_df", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.
7,707
216
5,849
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
ref_pd_df_by_series_only_index
true
statement
96
100
false
false
[ "data", "in_pd_series_measure_with_index", "in_pd_series_dimension_with_index", "in_pd_df_by_series_with_index", "ref_pd_series_only_index", "test_add_data_frame_index_with_df", "test_add_data_frame_index_with_none", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_index_with_df", "type": "function" }, { "name": "test_add_data_frame_index_with_none", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.
7,708
216
5,898
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
data
true
statement
96
100
false
false
[ "data", "assertEqual", "test_add_data_frame_index_with_none", "in_pd_df_by_series_with_index", "in_pd_series_measure_with_index", "test_add_data_frame_index_with_df", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_index_with_df", "type": "function" }, { "name": "test_add_data_frame_index_with_none", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.
7,709
216
5,903
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
build
true
function
28
30
false
false
[ "add_data_frame", "add_df", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.
7,710
216
6,035
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
data
true
statement
95
99
false
false
[ "data", "in_pd_df_by_series", "ref_pd_series", "assertEqual", "in_pd_series_dimension", "test_add_df_index_with_series", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_df_index_with_series", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.
7,711
216
6,040
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
add_df_index
true
function
28
30
false
false
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.
7,712
216
6,071
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
random
in_pd_series_dimension_with_index
true
statement
95
99
false
false
[ "data", "ref_pd_series", "in_pd_series_dimension", "ref_pd_series_with_nan", "ref_pd_df_by_series_with_duplicated_popularity", "test_add_df_index_with_series", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_df_index_with_series", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.
7,713
216
6,171
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
data
true
statement
95
99
false
false
[ "data", "in_pd_df_by_series", "ref_pd_series", "assertEqual", "in_pd_series_dimension", "test_add_df_index_with_series", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_df_index_with_series", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.
7,714
216
6,176
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
add_df_index
true
function
28
30
false
false
[ "add_df", "add_data_frame", "build", "add_data_frame_index", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "dump", "filter", "from_json", "set_filter", "clear", "copy", "fromkeys", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add_data_frame", "type": "function" }, { "name": "add_data_frame_index", "type": "function" }, { "name": "add_df", "type": "function" }, { "name": "add_df_index", "type": "function" }, { "name": "add_dimension", "type": "function" }, { "name": "add_measure", "type": "function" }, { "name": "add_np_array", "type": "function" }, { "name": "add_record", "type": "function" }, { "name": "add_records", "type": "function" }, { "name": "add_series", "type": "function" }, { "name": "add_series_list", "type": "function" }, { "name": "add_spark_df", "type": "function" }, { "name": "build", "type": "function" }, { "name": "clear", "type": "function" }, { "name": "copy", "type": "function" }, { "name": "dump", "type": "function" }, { "name": "filter", "type": "function" }, { "name": "from_json", "type": "function" }, { "name": "fromkeys", "type": "function" }, { "name": "get", "type": "function" }, { "name": "items", "type": "function" }, { "name": "keys", "type": "function" }, { "name": "pop", "type": "function" }, { "name": "popitem", "type": "function" }, { "name": "set_filter", "type": "function" }, { "name": "setdefault", "type": "function" }, { "name": "update", "type": "function" }, { "name": "values", "type": "function" }, { "name": "_add_named_value", "type": "function" }, { "name": "_add_value", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__class_getitem__", "type": "function" }, { "name": "__contains__", "type": "function" }, { "name": "__delattr__", "type": "function" }, { "name": "__delitem__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__getitem__", "type": "function" }, { "name": "__hash__", "type": "statement" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__ior__", "type": "function" }, { "name": "__iter__", "type": "function" }, { "name": "__len__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__or__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__reversed__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__setitem__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.
7,715
216
6,207
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
in_pd_series_measure_with_index
true
statement
95
99
false
false
[ "data", "ref_pd_series", "in_pd_series_dimension", "ref_pd_series_with_nan", "ref_pd_df_by_series_with_duplicated_popularity", "test_add_df_index_with_series", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_df_index_with_series", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.
7,716
216
6,333
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
ref_pd_series_only_index
true
statement
95
99
false
true
[ "data", "ref_pd_series", "in_pd_df_by_series_with_index", "in_pd_series_dimension", "in_pd_df_by_series", "test_add_df_index_with_series", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_df_index_with_series", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.
7,717
216
6,376
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
data
true
statement
95
99
false
false
[ "data", "in_pd_df_by_series", "ref_pd_series", "assertEqual", "in_pd_series_dimension", "test_add_df_index_with_series", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_df_index_with_series", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.
7,719
216
6,528
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
inproject
data
true
statement
95
99
false
false
[ "data", "ref_pd_series", "in_pd_df_by_series", "assertEqual", "in_pd_series_dimension", "test_add_data_frame_index_with_series", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_index_with_series", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.
7,721
216
6,572
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
in_pd_series_dimension_with_index
true
statement
95
99
false
false
[ "data", "ref_pd_series", "in_pd_series_dimension", "ref_pd_series_with_nan", "in_pd_series_dimension_with_index", "test_add_data_frame_index_with_series", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_index_with_series", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.
7,722
216
6,665
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
data
true
statement
95
99
false
false
[ "data", "ref_pd_series", "in_pd_df_by_series", "assertEqual", "in_pd_series_dimension", "test_add_data_frame_index_with_series", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_index_with_series", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.
7,724
216
6,709
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
in_pd_series_measure_with_index
true
statement
95
99
false
false
[ "data", "ref_pd_series", "in_pd_series_dimension", "in_pd_series_measure_with_index", "in_pd_series_dimension_with_index", "test_add_data_frame_index_with_series", "asset_dir", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_index_with_series", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.
7,725
216
6,828
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
ref_pd_series_only_index
true
statement
95
99
false
false
[ "data", "ref_pd_series", "in_pd_df_by_series", "in_pd_series_dimension", "in_pd_series_measure_with_index", "test_add_data_frame_index_with_series", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_index_with_series", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.
7,726
216
6,871
vizzuhq__ipyvizzu
54b0334aa736a77f9430739c9375b16be145b3fd
tests/test_data/test_pandas.py
Unknown
data
true
statement
95
99
false
false
[ "data", "ref_pd_series", "in_pd_df_by_series", "assertEqual", "in_pd_series_dimension", "test_add_data_frame_index_with_series", "asset_dir", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "asset_dir", "type": "statement" }, { "name": "countTestCases", "type": "function" }, { "name": "data", "type": "statement" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "in_pd_df_by_series", "type": "statement" }, { "name": "in_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "in_pd_df_by_series_with_index", "type": "statement" }, { "name": "in_pd_df_by_series_with_nan", "type": "statement" }, { "name": "in_pd_series_dimension", "type": "statement" }, { "name": "in_pd_series_dimension_with_index", "type": "statement" }, { "name": "in_pd_series_dimension_with_nan", "type": "statement" }, { "name": "in_pd_series_measure", "type": "statement" }, { "name": "in_pd_series_measure_with_index", "type": "statement" }, { "name": "in_pd_series_measure_with_nan", "type": "statement" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "ref_pd_df_by_series", "type": "statement" }, { "name": "ref_pd_df_by_series_max_rows", "type": "statement" }, { "name": "ref_pd_df_by_series_only_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_duplicated_popularity", "type": "statement" }, { "name": "ref_pd_df_by_series_with_index", "type": "statement" }, { "name": "ref_pd_df_by_series_with_nan", "type": "statement" }, { "name": "ref_pd_series", "type": "statement" }, { "name": "ref_pd_series_only_index", "type": "statement" }, { "name": "ref_pd_series_with_index", "type": "statement" }, { "name": "ref_pd_series_with_nan", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "set_up_pd_df", "type": "function" }, { "name": "set_up_pd_series", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_data_frame_index_with_series", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.
7,728
218
23,296
mage-ai__mage-ai
9ed779ccaf3538efbe1f2f54dd68f61fb1c3af55
src/data_cleaner/tests/transformer_actions/test_column.py
infile
__groupby_agg_action
true
function
104
108
true
true
[ "__groupby_agg_action", "assertEqual", "assertRaises", "test_count", "test_shift_down", "test_add_column_addition", "test_add_column_addition_days", "test_add_column_constant", "test_add_column_date_trunc", "test_add_column_difference", "test_add_column_difference_days", "test_add_column_distance_between", "test_add_column_divide", "test_add_column_formatted_date", "test_add_column_if_else", "test_add_column_if_else_with_column", "test_add_column_multiply", "test_add_column_string_replace", "test_add_column_string_split", "test_add_column_substring", "test_average", "test_count_distinct", "test_count_with_filter", "test_count_with_time_window", "test_diff", "test_first_column", "test_impute", "test_last_column", "test_max", "test_median", "test_min", "test_remove_column", "test_select", "test_shift_down_with_groupby", "test_shift_up", "test_sum", "setUp", "tearDown", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "countTestCases", "type": "function" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_column_addition", "type": "function" }, { "name": "test_add_column_addition_days", "type": "function" }, { "name": "test_add_column_constant", "type": "function" }, { "name": "test_add_column_date_trunc", "type": "function" }, { "name": "test_add_column_difference", "type": "function" }, { "name": "test_add_column_difference_days", "type": "function" }, { "name": "test_add_column_distance_between", "type": "function" }, { "name": "test_add_column_divide", "type": "function" }, { "name": "test_add_column_formatted_date", "type": "function" }, { "name": "test_add_column_if_else", "type": "function" }, { "name": "test_add_column_if_else_with_column", "type": "function" }, { "name": "test_add_column_multiply", "type": "function" }, { "name": "test_add_column_string_replace", "type": "function" }, { "name": "test_add_column_string_split", "type": "function" }, { "name": "test_add_column_substring", "type": "function" }, { "name": "test_average", "type": "function" }, { "name": "test_count", "type": "function" }, { "name": "test_count_distinct", "type": "function" }, { "name": "test_count_with_filter", "type": "function" }, { "name": "test_count_with_time_window", "type": "function" }, { "name": "test_diff", "type": "function" }, { "name": "test_first_column", "type": "function" }, { "name": "test_impute", "type": "function" }, { "name": "test_last_column", "type": "function" }, { "name": "test_max", "type": "function" }, { "name": "test_median", "type": "function" }, { "name": "test_min", "type": "function" }, { "name": "test_remove_column", "type": "function" }, { "name": "test_select", "type": "function" }, { "name": "test_shift_down", "type": "function" }, { "name": "test_shift_down_with_groupby", "type": "function" }, { "name": "test_shift_up", "type": "function" }, { "name": "test_sum", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__groupby_agg_action", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.tests.base_test import TestCase from data_cleaner.transformer_actions.column import ( add_column, count, count_distinct, diff, # expand_column, first, last, remove_column, select, shift_down, shift_up, ) from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd TEST_DATAFRAME = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'amount', ]) class ColumnTests(TestCase): def test_remove_column(self): df = pd.DataFrame([ [0, False, 'a'], [1, True, 'b'], ], columns=[ 'integer', 'boolean', 'string', ]) action = dict(action_arguments=['string']) df_new = remove_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( integer=0, boolean=False, ), dict( integer=1, boolean=True, ), ]) action = dict(action_arguments=['integer', 'boolean']) df_new = remove_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( string='a', ), dict( string='b', ), ]) def test_add_column_addition(self): df = pd.DataFrame([ [1, 3, 7, 9], [4, 2, 9, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', 'integer3', ], action_options={ 'udf': 'addition', 'value': None, }, outputs=[ dict( uuid='integer_addition', column_type='number', ), ], ) action2 = dict( action_arguments=['integer1'], action_options={ 'udf': 'addition', 'value': 10, }, outputs=[ dict( uuid='integer_addition2', column_type='number', ), ], ) action3 = dict( action_arguments=['integer1', 'integer4'], action_options={ 'udf': 'addition', 'value': 10, }, outputs=[ dict( uuid='integer_addition3', column_type='number', ), ], ) df_new = add_column( add_column( add_column(df, action1), action2, ), action3, ) df_expected = pd.DataFrame([ [1, 3, 7, 9, 11, 11, 20], [4, 2, 9, 3, 15, 14, 17], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_addition', 'integer_addition2', 'integer_addition3', ]) assert_frame_equal(df_new, df_expected) def test_add_column_addition_days(self): df = pd.DataFrame([ ['2021-08-31'], ['2021-08-28'], ], columns=[ 'created_at', ]) action = dict( action_arguments=['created_at'], action_options=dict( column_type='datetime', time_unit='d', udf='addition', value=3, ), outputs=[ dict( uuid='3d_after_creation', column_type='text', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['2021-08-31', '2021-09-03 00:00:00'], ['2021-08-28', '2021-08-31 00:00:00'], ], columns=[ 'created_at', '3d_after_creation' ]) assert_frame_equal(df_new, df_expected) def test_add_column_constant(self): df = pd.DataFrame([ [False], [True], ], columns=[ 'boolean', ]) action = dict( action_arguments=[10], action_options=dict( udf='constant', ), outputs=[ dict( uuid='integer', column_type='number', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( boolean=False, integer=10, ), dict( boolean=True, integer=10, ), ]) def test_add_column_date_trunc(self): df = pd.DataFrame([ ['2021-08-31', False], ['2021-08-28', True], ], columns=[ 'created_at', 'boolean', ]) action = dict( action_arguments=['created_at'], action_options=dict( udf='date_trunc', date_part='week', ), outputs=[ dict( uuid='week_date', column_type='text', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( created_at='2021-08-31', boolean=False, week_date='2021-08-30', ), dict( created_at='2021-08-28', boolean=True, week_date='2021-08-23', ), ]) def test_add_column_difference(self): df = pd.DataFrame([ [1, 3], [4, 2], ], columns=[ 'integer1', 'integer2', ]) action1 = dict( action_arguments=['integer1', 'integer2'], action_options={ 'udf': 'difference', }, outputs=[ dict( uuid='integer_difference', column_type='number', ), ], ) action2 = dict( action_arguments=['integer1'], action_options={ 'udf': 'difference', 'value': 10, }, outputs=[ dict( uuid='integer_difference2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [1, 3, -2, -9], [4, 2, 2, -6], ], columns=[ 'integer1', 'integer2', 'integer_difference', 'integer_difference2' ]) assert_frame_equal(df_new, df_expected) def test_add_column_difference_days(self): df = pd.DataFrame([ ['2021-08-31', '2021-09-14'], ['2021-08-28', '2021-09-03'], ], columns=[ 'created_at', 'converted_at', ]) action = dict( action_arguments=['converted_at', 'created_at'], action_options=dict( column_type='datetime', time_unit='d', udf='difference', ), outputs=[ dict( uuid='days_diff', column_type='number', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['2021-08-31', '2021-09-14', 14], ['2021-08-28', '2021-09-03', 6], ], columns=[ 'created_at', 'converted_at', 'days_diff', ]) assert_frame_equal(df_new, df_expected) def test_add_column_distance_between(self): df = pd.DataFrame([ [26.05308, -97.31838, 33.41939, -112.32606], [39.71954, -84.13056, 33.41939, -112.32606], ], columns=[ 'lat1', 'lng1', 'lat2', 'lng2', ]) action = dict( action_arguments=['lat1', 'lng1', 'lat2', 'lng2'], action_options=dict( udf='distance_between', ), outputs=[ dict( uuid='distance', column_type='number_with_decimals', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( lat1=26.05308, lng1=-97.31838, lat2=33.41939, lng2=-112.32606, distance=1661.8978520305657, ), dict( lat1=39.71954, lng1=-84.13056, lat2=33.41939, lng2=-112.32606, distance=2601.5452571116184, ), ]) def test_add_column_divide(self): df = pd.DataFrame([ [12, 3, 70, 9], [4, 2, 90, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', ], action_options={ 'udf': 'divide', }, outputs=[ dict( uuid='integer_divide', column_type='number', ), ], ) action2 = dict( action_arguments=['integer3'], action_options={ 'udf': 'divide', 'value': 10, }, outputs=[ dict( uuid='integer_divide2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [12, 3, 70, 9, 4, 7], [4, 2, 90, 3, 2, 9], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_divide', 'integer_divide2' ]) assert_frame_equal(df_new, df_expected) # def test_add_column_extract_dict_string(self): # df = pd.DataFrame([ # '{\'country\': \'US\', \'age\': \'20\'}', # '{\'country\': \'CA\'}', # '{\'country\': \'UK\', \'age\': \'24\'}', # '', # ], columns=[ # 'properties', # ]) # action = dict( # action_arguments=['properties', 'country'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_country', # column_type='text', # ), # ], # ) # df_new = add_column(df, action) # self.assertEqual(df_new.to_dict(orient='records'), [ # dict( # properties='{\'country\': \'US\', \'age\': \'20\'}', # property_country='US', # ), # dict( # properties='{\'country\': \'CA\'}', # property_country='CA', # ), # dict( # properties='{\'country\': \'UK\', \'age\': \'24\'}', # property_country='UK', # ), # dict( # properties='', # property_country=np.NaN, # ), # ]) # action2 = dict( # action_arguments=['properties', 'age'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_age', # column_type='number', # ), # ], # ) # df_new2 = add_column(df, action2) # self.assertEqual(df_new2.to_dict(orient='records'), [ # dict( # properties='{\'country\': \'US\', \'age\': \'20\'}', # property_age=20, # ), # dict( # properties='{\'country\': \'CA\'}', # property_age=0, # ), # dict( # properties='{\'country\': \'UK\', \'age\': \'24\'}', # property_age=24, # ), # dict( # properties='', # property_age=0, # ), # ]) # def test_add_column_extract_dict_string_with_json(self): # df = pd.DataFrame([ # '{\"country\": \"US\", \"is_adult\": true}', # '{\"country\": \"CA\"}', # '{\"country\": \"UK\", \"is_adult\": false}', # '', # ], columns=[ # 'properties', # ]) # action = dict( # action_arguments=['properties', 'country'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_country', # column_type='text', # ), # ], # ) # df_new = add_column(df, action) # self.assertEqual(df_new.to_dict(orient='records'), [ # dict( # properties='{\"country\": \"US\", \"is_adult\": true}', # property_country='US', # ), # dict( # properties='{\"country\": \"CA\"}', # property_country='CA', # ), # dict( # properties='{\"country\": \"UK\", \"is_adult\": false}', # property_country='UK', # ), # dict( # properties='', # property_country=np.NaN, # ), # ]) # action2 = dict( # action_arguments=['properties', 'is_adult'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_is_adult', # column_type='true_or_false', # ), # ], # ) # df_new2 = add_column(df, action2) # self.assertEqual(df_new2.to_dict(orient='records'), [ # dict( # properties='{\"country\": \"US\", \"is_adult\": true}', # property_is_adult=True, # ), # dict( # properties='{\"country\": \"CA\"}', # property_is_adult=None, # ), # dict( # properties='{\"country\": \"UK\", \"is_adult\": false}', # property_is_adult=False, # ), # dict( # properties='', # property_is_adult=None, # ), # ]) def test_add_column_formatted_date(self): df = pd.DataFrame([ ['2019-04-10 08:20:58', False], ['2019-03-05 03:30:30', True], ], columns=[ 'created_at', 'boolean', ]) action = dict( action_arguments=['created_at'], action_options=dict( udf='formatted_date', format='%Y-%m-%d', ), outputs=[ dict( uuid='created_date', column_type='text', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( created_at='2019-04-10 08:20:58', boolean=False, created_date='2019-04-10', ), dict( created_at='2019-03-05 03:30:30', boolean=True, created_date='2019-03-05', ), ]) def test_add_column_if_else(self): df = pd.DataFrame([ ['2019-04-10 08:20:58'], [None], ], columns=[ 'converted_at' ]) action = dict( action_arguments=[False, True], action_code='converted_at == null', action_options=dict( udf='if_else', ), outputs=[ dict( uuid='converted', column_type='true_or_false', ), ], ) df_new = add_column(df, action, original_df=df) self.assertEqual(df_new.to_dict(orient='records'), [ dict( converted_at='2019-04-10 08:20:58', converted=True, ), dict( converted_at=None, converted=False, ), ]) def test_add_column_if_else_with_column(self): df = pd.DataFrame([ ['2019-04-10 08:20:58', 'test_user_id'], [None, None], ], columns=[ 'converted_at', 'user_id', ]) action = dict( action_arguments=['unknown', 'user_id'], action_code='converted_at == null', action_options=dict( udf='if_else', arg1_type='value', arg2_type='column', ), outputs=[ dict( uuid='user_id_clean', column_type='text', ), ], ) df_new = add_column(df, action, original_df=df) self.assertEqual(df_new.to_dict(orient='records'), [ dict( converted_at='2019-04-10 08:20:58', user_id='test_user_id', user_id_clean='test_user_id', ), dict( converted_at=None, user_id=None, user_id_clean='unknown', ), ]) def test_add_column_multiply(self): df = pd.DataFrame([ [1, 3, 7, 9], [4, 2, 9, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', ], action_options={ 'udf': 'multiply', }, outputs=[ dict( uuid='integer_multiply', column_type='number', ), ], ) action2 = dict( action_arguments=['integer3'], action_options={ 'udf': 'multiply', 'value': 10, }, outputs=[ dict( uuid='integer_multiply2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [1, 3, 7, 9, 3, 70], [4, 2, 9, 3, 8, 90], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_multiply', 'integer_multiply2' ]) assert_frame_equal(df_new, df_expected) def test_add_column_string_replace(self): df = pd.DataFrame([ ['$1000'], ['$321. '], ['$4,321'], ], columns=[ 'amount', ]) action = dict( action_arguments=['amount'], action_options={ 'udf': 'string_replace', 'pattern': '\\$|\\.|\\,|\\s*', 'replacement': '', }, outputs=[ dict( uuid='amount_clean', column_type='true_or_false', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['$1000', '1000'], ['$321. ', '321'], ['$4,321', '4321'], ], columns=[ 'amount', 'amount_clean', ]) assert_frame_equal(df_new, df_expected) def test_add_column_string_split(self): df = pd.DataFrame([ ['Street1, Long Beach, CA, '], ['Street2,Vernon, CA, 123'], ['Pacific Coast Highway, Los Angeles, CA, 111'], ], columns=[ 'location', ]) action = dict( action_arguments=['location'], action_options={ 'udf': 'string_split', 'separator': ',', 'part_index': 1, }, outputs=[ dict( uuid='location_city', column_type='text', ), ], ) action2 = dict( action_arguments=['location'], action_options={ 'udf': 'string_split', 'separator': ',', 'part_index': 3, }, outputs=[ dict( uuid='num', column_type='number', ), ], ) df_new = add_column(add_column(df, action), action2) df_expected = pd.DataFrame([ ['Street1, Long Beach, CA, ', 'Long Beach', 0], ['Street2,Vernon, CA, 123', 'Vernon', 123], ['Pacific Coast Highway, Los Angeles, CA, 111', 'Los Angeles', 111], ], columns=[ 'location', 'location_city', 'num', ]) assert_frame_equal(df_new, df_expected) def test_add_column_substring(self): df = pd.DataFrame([ ['$1000.0'], ['$321.9'], ], columns=[ 'amount', ]) action = dict( action_arguments=['amount'], action_options={ 'udf': 'substring', 'start': 1, 'stop': -2, }, outputs=[ dict( uuid='amount_int', column_type='text', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['$1000.0', '1000'], ['$321.9', '321'], ], columns=[ 'amount', 'amount_int', ]) assert_frame_equal(df_new, df_expected) def test_average(self): from data_cleaner.transformer_actions.column import average action = self.
7,729
218
41,482
mage-ai__mage-ai
9ed779ccaf3538efbe1f2f54dd68f61fb1c3af55
src/data_cleaner/tests/transformer_actions/test_column.py
infile
__groupby_agg_action
true
function
104
108
true
false
[ "__groupby_agg_action", "assertEqual", "assertRaises", "test_count", "test_shift_down", "test_add_column_addition", "test_add_column_addition_days", "test_add_column_constant", "test_add_column_date_trunc", "test_add_column_difference", "test_add_column_difference_days", "test_add_column_distance_between", "test_add_column_divide", "test_add_column_formatted_date", "test_add_column_if_else", "test_add_column_if_else_with_column", "test_add_column_multiply", "test_add_column_string_replace", "test_add_column_string_split", "test_add_column_substring", "test_average", "test_count_distinct", "test_count_with_filter", "test_count_with_time_window", "test_diff", "test_first_column", "test_impute", "test_last_column", "test_max", "test_median", "test_min", "test_remove_column", "test_select", "test_shift_down_with_groupby", "test_shift_up", "test_sum", "setUp", "tearDown", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "countTestCases", "type": "function" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_column_addition", "type": "function" }, { "name": "test_add_column_addition_days", "type": "function" }, { "name": "test_add_column_constant", "type": "function" }, { "name": "test_add_column_date_trunc", "type": "function" }, { "name": "test_add_column_difference", "type": "function" }, { "name": "test_add_column_difference_days", "type": "function" }, { "name": "test_add_column_distance_between", "type": "function" }, { "name": "test_add_column_divide", "type": "function" }, { "name": "test_add_column_formatted_date", "type": "function" }, { "name": "test_add_column_if_else", "type": "function" }, { "name": "test_add_column_if_else_with_column", "type": "function" }, { "name": "test_add_column_multiply", "type": "function" }, { "name": "test_add_column_string_replace", "type": "function" }, { "name": "test_add_column_string_split", "type": "function" }, { "name": "test_add_column_substring", "type": "function" }, { "name": "test_average", "type": "function" }, { "name": "test_count", "type": "function" }, { "name": "test_count_distinct", "type": "function" }, { "name": "test_count_with_filter", "type": "function" }, { "name": "test_count_with_time_window", "type": "function" }, { "name": "test_diff", "type": "function" }, { "name": "test_first_column", "type": "function" }, { "name": "test_impute", "type": "function" }, { "name": "test_last_column", "type": "function" }, { "name": "test_max", "type": "function" }, { "name": "test_median", "type": "function" }, { "name": "test_min", "type": "function" }, { "name": "test_remove_column", "type": "function" }, { "name": "test_select", "type": "function" }, { "name": "test_shift_down", "type": "function" }, { "name": "test_shift_down_with_groupby", "type": "function" }, { "name": "test_shift_up", "type": "function" }, { "name": "test_sum", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__groupby_agg_action", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.tests.base_test import TestCase from data_cleaner.transformer_actions.column import ( add_column, count, count_distinct, diff, # expand_column, first, last, remove_column, select, shift_down, shift_up, ) from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd TEST_DATAFRAME = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'amount', ]) class ColumnTests(TestCase): def test_remove_column(self): df = pd.DataFrame([ [0, False, 'a'], [1, True, 'b'], ], columns=[ 'integer', 'boolean', 'string', ]) action = dict(action_arguments=['string']) df_new = remove_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( integer=0, boolean=False, ), dict( integer=1, boolean=True, ), ]) action = dict(action_arguments=['integer', 'boolean']) df_new = remove_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( string='a', ), dict( string='b', ), ]) def test_add_column_addition(self): df = pd.DataFrame([ [1, 3, 7, 9], [4, 2, 9, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', 'integer3', ], action_options={ 'udf': 'addition', 'value': None, }, outputs=[ dict( uuid='integer_addition', column_type='number', ), ], ) action2 = dict( action_arguments=['integer1'], action_options={ 'udf': 'addition', 'value': 10, }, outputs=[ dict( uuid='integer_addition2', column_type='number', ), ], ) action3 = dict( action_arguments=['integer1', 'integer4'], action_options={ 'udf': 'addition', 'value': 10, }, outputs=[ dict( uuid='integer_addition3', column_type='number', ), ], ) df_new = add_column( add_column( add_column(df, action1), action2, ), action3, ) df_expected = pd.DataFrame([ [1, 3, 7, 9, 11, 11, 20], [4, 2, 9, 3, 15, 14, 17], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_addition', 'integer_addition2', 'integer_addition3', ]) assert_frame_equal(df_new, df_expected) def test_add_column_addition_days(self): df = pd.DataFrame([ ['2021-08-31'], ['2021-08-28'], ], columns=[ 'created_at', ]) action = dict( action_arguments=['created_at'], action_options=dict( column_type='datetime', time_unit='d', udf='addition', value=3, ), outputs=[ dict( uuid='3d_after_creation', column_type='text', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['2021-08-31', '2021-09-03 00:00:00'], ['2021-08-28', '2021-08-31 00:00:00'], ], columns=[ 'created_at', '3d_after_creation' ]) assert_frame_equal(df_new, df_expected) def test_add_column_constant(self): df = pd.DataFrame([ [False], [True], ], columns=[ 'boolean', ]) action = dict( action_arguments=[10], action_options=dict( udf='constant', ), outputs=[ dict( uuid='integer', column_type='number', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( boolean=False, integer=10, ), dict( boolean=True, integer=10, ), ]) def test_add_column_date_trunc(self): df = pd.DataFrame([ ['2021-08-31', False], ['2021-08-28', True], ], columns=[ 'created_at', 'boolean', ]) action = dict( action_arguments=['created_at'], action_options=dict( udf='date_trunc', date_part='week', ), outputs=[ dict( uuid='week_date', column_type='text', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( created_at='2021-08-31', boolean=False, week_date='2021-08-30', ), dict( created_at='2021-08-28', boolean=True, week_date='2021-08-23', ), ]) def test_add_column_difference(self): df = pd.DataFrame([ [1, 3], [4, 2], ], columns=[ 'integer1', 'integer2', ]) action1 = dict( action_arguments=['integer1', 'integer2'], action_options={ 'udf': 'difference', }, outputs=[ dict( uuid='integer_difference', column_type='number', ), ], ) action2 = dict( action_arguments=['integer1'], action_options={ 'udf': 'difference', 'value': 10, }, outputs=[ dict( uuid='integer_difference2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [1, 3, -2, -9], [4, 2, 2, -6], ], columns=[ 'integer1', 'integer2', 'integer_difference', 'integer_difference2' ]) assert_frame_equal(df_new, df_expected) def test_add_column_difference_days(self): df = pd.DataFrame([ ['2021-08-31', '2021-09-14'], ['2021-08-28', '2021-09-03'], ], columns=[ 'created_at', 'converted_at', ]) action = dict( action_arguments=['converted_at', 'created_at'], action_options=dict( column_type='datetime', time_unit='d', udf='difference', ), outputs=[ dict( uuid='days_diff', column_type='number', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['2021-08-31', '2021-09-14', 14], ['2021-08-28', '2021-09-03', 6], ], columns=[ 'created_at', 'converted_at', 'days_diff', ]) assert_frame_equal(df_new, df_expected) def test_add_column_distance_between(self): df = pd.DataFrame([ [26.05308, -97.31838, 33.41939, -112.32606], [39.71954, -84.13056, 33.41939, -112.32606], ], columns=[ 'lat1', 'lng1', 'lat2', 'lng2', ]) action = dict( action_arguments=['lat1', 'lng1', 'lat2', 'lng2'], action_options=dict( udf='distance_between', ), outputs=[ dict( uuid='distance', column_type='number_with_decimals', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( lat1=26.05308, lng1=-97.31838, lat2=33.41939, lng2=-112.32606, distance=1661.8978520305657, ), dict( lat1=39.71954, lng1=-84.13056, lat2=33.41939, lng2=-112.32606, distance=2601.5452571116184, ), ]) def test_add_column_divide(self): df = pd.DataFrame([ [12, 3, 70, 9], [4, 2, 90, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', ], action_options={ 'udf': 'divide', }, outputs=[ dict( uuid='integer_divide', column_type='number', ), ], ) action2 = dict( action_arguments=['integer3'], action_options={ 'udf': 'divide', 'value': 10, }, outputs=[ dict( uuid='integer_divide2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [12, 3, 70, 9, 4, 7], [4, 2, 90, 3, 2, 9], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_divide', 'integer_divide2' ]) assert_frame_equal(df_new, df_expected) # def test_add_column_extract_dict_string(self): # df = pd.DataFrame([ # '{\'country\': \'US\', \'age\': \'20\'}', # '{\'country\': \'CA\'}', # '{\'country\': \'UK\', \'age\': \'24\'}', # '', # ], columns=[ # 'properties', # ]) # action = dict( # action_arguments=['properties', 'country'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_country', # column_type='text', # ), # ], # ) # df_new = add_column(df, action) # self.assertEqual(df_new.to_dict(orient='records'), [ # dict( # properties='{\'country\': \'US\', \'age\': \'20\'}', # property_country='US', # ), # dict( # properties='{\'country\': \'CA\'}', # property_country='CA', # ), # dict( # properties='{\'country\': \'UK\', \'age\': \'24\'}', # property_country='UK', # ), # dict( # properties='', # property_country=np.NaN, # ), # ]) # action2 = dict( # action_arguments=['properties', 'age'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_age', # column_type='number', # ), # ], # ) # df_new2 = add_column(df, action2) # self.assertEqual(df_new2.to_dict(orient='records'), [ # dict( # properties='{\'country\': \'US\', \'age\': \'20\'}', # property_age=20, # ), # dict( # properties='{\'country\': \'CA\'}', # property_age=0, # ), # dict( # properties='{\'country\': \'UK\', \'age\': \'24\'}', # property_age=24, # ), # dict( # properties='', # property_age=0, # ), # ]) # def test_add_column_extract_dict_string_with_json(self): # df = pd.DataFrame([ # '{\"country\": \"US\", \"is_adult\": true}', # '{\"country\": \"CA\"}', # '{\"country\": \"UK\", \"is_adult\": false}', # '', # ], columns=[ # 'properties', # ]) # action = dict( # action_arguments=['properties', 'country'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_country', # column_type='text', # ), # ], # ) # df_new = add_column(df, action) # self.assertEqual(df_new.to_dict(orient='records'), [ # dict( # properties='{\"country\": \"US\", \"is_adult\": true}', # property_country='US', # ), # dict( # properties='{\"country\": \"CA\"}', # property_country='CA', # ), # dict( # properties='{\"country\": \"UK\", \"is_adult\": false}', # property_country='UK', # ), # dict( # properties='', # property_country=np.NaN, # ), # ]) # action2 = dict( # action_arguments=['properties', 'is_adult'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_is_adult', # column_type='true_or_false', # ), # ], # ) # df_new2 = add_column(df, action2) # self.assertEqual(df_new2.to_dict(orient='records'), [ # dict( # properties='{\"country\": \"US\", \"is_adult\": true}', # property_is_adult=True, # ), # dict( # properties='{\"country\": \"CA\"}', # property_is_adult=None, # ), # dict( # properties='{\"country\": \"UK\", \"is_adult\": false}', # property_is_adult=False, # ), # dict( # properties='', # property_is_adult=None, # ), # ]) def test_add_column_formatted_date(self): df = pd.DataFrame([ ['2019-04-10 08:20:58', False], ['2019-03-05 03:30:30', True], ], columns=[ 'created_at', 'boolean', ]) action = dict( action_arguments=['created_at'], action_options=dict( udf='formatted_date', format='%Y-%m-%d', ), outputs=[ dict( uuid='created_date', column_type='text', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( created_at='2019-04-10 08:20:58', boolean=False, created_date='2019-04-10', ), dict( created_at='2019-03-05 03:30:30', boolean=True, created_date='2019-03-05', ), ]) def test_add_column_if_else(self): df = pd.DataFrame([ ['2019-04-10 08:20:58'], [None], ], columns=[ 'converted_at' ]) action = dict( action_arguments=[False, True], action_code='converted_at == null', action_options=dict( udf='if_else', ), outputs=[ dict( uuid='converted', column_type='true_or_false', ), ], ) df_new = add_column(df, action, original_df=df) self.assertEqual(df_new.to_dict(orient='records'), [ dict( converted_at='2019-04-10 08:20:58', converted=True, ), dict( converted_at=None, converted=False, ), ]) def test_add_column_if_else_with_column(self): df = pd.DataFrame([ ['2019-04-10 08:20:58', 'test_user_id'], [None, None], ], columns=[ 'converted_at', 'user_id', ]) action = dict( action_arguments=['unknown', 'user_id'], action_code='converted_at == null', action_options=dict( udf='if_else', arg1_type='value', arg2_type='column', ), outputs=[ dict( uuid='user_id_clean', column_type='text', ), ], ) df_new = add_column(df, action, original_df=df) self.assertEqual(df_new.to_dict(orient='records'), [ dict( converted_at='2019-04-10 08:20:58', user_id='test_user_id', user_id_clean='test_user_id', ), dict( converted_at=None, user_id=None, user_id_clean='unknown', ), ]) def test_add_column_multiply(self): df = pd.DataFrame([ [1, 3, 7, 9], [4, 2, 9, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', ], action_options={ 'udf': 'multiply', }, outputs=[ dict( uuid='integer_multiply', column_type='number', ), ], ) action2 = dict( action_arguments=['integer3'], action_options={ 'udf': 'multiply', 'value': 10, }, outputs=[ dict( uuid='integer_multiply2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [1, 3, 7, 9, 3, 70], [4, 2, 9, 3, 8, 90], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_multiply', 'integer_multiply2' ]) assert_frame_equal(df_new, df_expected) def test_add_column_string_replace(self): df = pd.DataFrame([ ['$1000'], ['$321. '], ['$4,321'], ], columns=[ 'amount', ]) action = dict( action_arguments=['amount'], action_options={ 'udf': 'string_replace', 'pattern': '\\$|\\.|\\,|\\s*', 'replacement': '', }, outputs=[ dict( uuid='amount_clean', column_type='true_or_false', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['$1000', '1000'], ['$321. ', '321'], ['$4,321', '4321'], ], columns=[ 'amount', 'amount_clean', ]) assert_frame_equal(df_new, df_expected) def test_add_column_string_split(self): df = pd.DataFrame([ ['Street1, Long Beach, CA, '], ['Street2,Vernon, CA, 123'], ['Pacific Coast Highway, Los Angeles, CA, 111'], ], columns=[ 'location', ]) action = dict( action_arguments=['location'], action_options={ 'udf': 'string_split', 'separator': ',', 'part_index': 1, }, outputs=[ dict( uuid='location_city', column_type='text', ), ], ) action2 = dict( action_arguments=['location'], action_options={ 'udf': 'string_split', 'separator': ',', 'part_index': 3, }, outputs=[ dict( uuid='num', column_type='number', ), ], ) df_new = add_column(add_column(df, action), action2) df_expected = pd.DataFrame([ ['Street1, Long Beach, CA, ', 'Long Beach', 0], ['Street2,Vernon, CA, 123', 'Vernon', 123], ['Pacific Coast Highway, Los Angeles, CA, 111', 'Los Angeles', 111], ], columns=[ 'location', 'location_city', 'num', ]) assert_frame_equal(df_new, df_expected) def test_add_column_substring(self): df = pd.DataFrame([ ['$1000.0'], ['$321.9'], ], columns=[ 'amount', ]) action = dict( action_arguments=['amount'], action_options={ 'udf': 'substring', 'start': 1, 'stop': -2, }, outputs=[ dict( uuid='amount_int', column_type='text', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['$1000.0', '1000'], ['$321.9', '321'], ], columns=[ 'amount', 'amount_int', ]) assert_frame_equal(df_new, df_expected) def test_average(self): from data_cleaner.transformer_actions.column import average action = self.__groupby_agg_action('average_amount') df_new = average(TEST_DATAFRAME.copy(), action) df_expected = pd.DataFrame([ [1, 1000, 1050], [2, 1050, 1100], [1, 1100, 1050], [2, 1150, 1100], ], columns=[ 'group_id', 'amount', 'average_amount' ]) assert_frame_equal(df_new, df_expected) def test_count(self): df = pd.DataFrame([ [1, 1000], [1, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='order_count'), ], ) df_new = count(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, order_count=3, ), dict( group_id=1, order_id=1050, order_count=3, ), dict( group_id=1, order_id=1100, order_count=3, ), dict( group_id=2, order_id=1150, order_count=1, ), ]) def test_count_distinct(self): df = pd.DataFrame([ [1, 1000], [1, 1000], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='order_count'), ], ) df_new = count_distinct(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, order_count=2, ), dict( group_id=1, order_id=1000, order_count=2, ), dict( group_id=1, order_id=1100, order_count=2, ), dict( group_id=2, order_id=1150, order_count=1, ), ]) def test_count_with_time_window(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) action = dict( action_arguments=['order_id'], action_code='', action_options=dict( groupby_columns=['group_id'], timestamp_feature_a='group_churned_at', timestamp_feature_b='order_created_at', window=90*24*3600, ), outputs=[ dict(uuid='order_count'), ], ) df_new = count(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, group_churned_at='2021-10-01', order_created_at='2021-09-01', order_count=2, ), dict( group_id=1, order_id=1050, group_churned_at='2021-10-01', order_created_at='2021-08-01', order_count=2, ), dict( group_id=1, order_id=1100, group_churned_at='2021-10-01', order_created_at='2021-01-01', order_count=2, ), dict( group_id=2, order_id=1150, group_churned_at='2021-09-01', order_created_at='2021-08-01', order_count=1, ), ]) def test_count_with_filter(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], [2, 1200, '2021-09-01', '2021-08-16'], [2, 1250, '2021-09-01', '2021-08-14'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) action = dict( action_arguments=['order_id'], action_code='order_created_at < \'2021-08-15\'', action_options=dict( groupby_columns=['group_id'], ), outputs=[ dict(uuid='order_count'), ], ) df_new = count(df, action) df_expected = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01', 2], [1, 1050, '2021-10-01', '2021-08-01', 2], [1, 1100, '2021-10-01', '2021-01-01', 2], [2, 1150, '2021-09-01', '2021-08-01', 2], [2, 1200, '2021-09-01', '2021-08-16', 2], [2, 1250, '2021-09-01', '2021-08-14', 2], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', 'order_count', ]) assert_frame_equal(df_new, df_expected) def test_diff(self): df = pd.DataFrame([ ['2020-01-01', 1000], ['2020-01-02', 1050], ['2020-01-03', 1200], ['2020-01-04', 990], ], columns=[ 'date', 'sold', ]) action = dict( action_arguments=['sold'], outputs=[ dict(uuid='sold_diff'), ], ) df_new = diff(df, action) self.assertEqual(df_new.to_dict(orient='records')[1:], [ dict( date='2020-01-02', sold=1050, sold_diff=50, ), dict( date='2020-01-03', sold=1200, sold_diff=150, ), dict( date='2020-01-04', sold=990, sold_diff=-210, ), ]) # def test_expand_column(self): # df = pd.DataFrame([ # [1, 'game'], # [1, 'book'], # [1, 'game'], # [2, 'Video Game'], # [1, 'Video Game'], # [2, 'book'], # [1, 'Video Game'], # [2, 'Video Game'], # ], columns=[ # 'group_id', # 'category', # ]) # action = dict( # action_arguments=['category'], # action_options=dict( # groupby_columns=['group_id'] # ), # outputs=[ # dict(uuid='category_expanded_count_game'), # dict(uuid='category_expanded_count_book'), # dict(uuid='category_expanded_count_video_game'), # dict(uuid='category_expanded_count_clothing'), # ], # ) # df_new = expand_column(df, action) # df_expected = pd.DataFrame([ # [1, 'game', 2, 1, 2], # [1, 'book', 2, 1, 2], # [1, 'game', 2, 1, 2], # [2, 'Video Game', 0, 1, 2], # [1, 'Video Game', 2, 1, 2], # [2, 'book', 0, 1, 2], # [1, 'Video Game', 2, 1, 2], # [2, 'Video Game', 0, 1, 2], # ], columns=[ # 'group_id', # 'category', # 'category_expanded_count_game', # 'category_expanded_count_book', # 'category_expanded_count_video_game', # ]) # assert_frame_equal(df_new, df_expected) # def test_expand_column_with_time_window(self): # df = pd.DataFrame([ # [1, 'game', '2021-01-02', '2021-01-04'], # [1, 'book', '2021-01-02', '2021-01-04'], # [1, 'game', '2021-01-03', '2021-01-04'], # [2, 'Video Game', '2021-01-01', '2021-01-03'], # [1, 'Video Game', '2021-01-01', '2021-01-04'], # [2, 'book', '2021-01-02', '2021-01-03'], # [1, 'Video Game', '2021-01-03', '2021-01-04'], # [2, 'Video Game', '2020-12-30', '2021-01-03'], # ], columns=[ # 'group_id', # 'category', # 'timestamp1', # 'timestamp2', # ]) # action = dict( # action_arguments=['category'], # action_options=dict( # groupby_columns=['group_id'], # timestamp_feature_a='timestamp2', # timestamp_feature_b='timestamp1', # window=172800, # ), # outputs=[ # dict(uuid='category_expanded_count_game_2d'), # dict(uuid='category_expanded_count_book_2d'), # dict(uuid='category_expanded_count_video_game_2d'), # dict(uuid='category_expanded_count_clothing_2d'), # ], # ) # df_new = expand_column(df, action) # df_expected = pd.DataFrame([ # [1, 'game', '2021-01-02', '2021-01-04', 2, 1, 1], # [1, 'book', '2021-01-02', '2021-01-04', 2, 1, 1], # [1, 'game', '2021-01-03', '2021-01-04', 2, 1, 1], # [2, 'Video Game', '2021-01-01', '2021-01-03', 0, 1, 1], # [1, 'Video Game', '2021-01-01', '2021-01-04', 2, 1, 1], # [2, 'book', '2021-01-02', '2021-01-03', 0, 1, 1], # [1, 'Video Game', '2021-01-03', '2021-01-04', 2, 1, 1], # [2, 'Video Game', '2020-12-30', '2021-01-03', 0, 1, 1], # ], columns=[ # 'group_id', # 'category', # 'timestamp1', # 'timestamp2', # 'category_expanded_count_game_2d', # 'category_expanded_count_book_2d', # 'category_expanded_count_video_game_2d', # ]) # assert_frame_equal(df_new, df_expected) def test_first_column(self): df = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='first_order'), ], ) df_new = first(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, first_order=1000, ), dict( group_id=2, order_id=1050, first_order=1050, ), dict( group_id=1, order_id=1100, first_order=1000, ), dict( group_id=2, order_id=1150, first_order=1050, ), ]) def test_impute(self): from data_cleaner.transformer_actions.column import impute df = pd.DataFrame([ ['2020-01-01', 1000, ' ', 800], ['2020-01-02', '', 1200, 700], ['2020-01-03', 1200, np.NaN, 900], ['2020-01-04', np.NaN, ' ', 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) action1 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'value': '0', }, action_variables={ '0': { 'feature': { 'column_type': 'number', 'uuid': 'sold', }, 'type': 'feature', }, '1': { 'feature': { 'column_type': 'number', 'uuid': 'curr_profit', }, 'type': 'feature', }, }, ) action2 = dict( action_arguments=['sold'], action_options={ 'value': '0', }, action_variables={ '0': { 'feature': { 'column_type': 'number', 'uuid': 'sold', }, 'type': 'feature', }, }, ) action3 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'average', }, ) action4 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'median', }, ) action5 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'column', 'value': 'prev_sold', }, ) action_invalid = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'mode', }, ) df_new1 = impute(df.copy(), action1) df_new2 = impute(df.copy(), action2) df_new3 = impute(df.copy(), action3) df_new4 = impute(df.copy(), action4) df_new5 = impute(df.copy(), action5) df_expected1 = pd.DataFrame([ ['2020-01-01', 1000, 0, 800], ['2020-01-02', 0, 1200, 700], ['2020-01-03', 1200, 0, 900], ['2020-01-04', 0, 0, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected2 = pd.DataFrame([ ['2020-01-01', 1000, ' ', 800], ['2020-01-02', 0, 1200, 700], ['2020-01-03', 1200, np.nan, 900], ['2020-01-04', 0, ' ', 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected3 = pd.DataFrame([ ['2020-01-01', 1000, 1250, 800], ['2020-01-02', 1300, 1200, 700], ['2020-01-03', 1200, 1250, 900], ['2020-01-04', 1300, 1250, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected4 = pd.DataFrame([ ['2020-01-01', 1000, 1250, 800], ['2020-01-02', 1200, 1200, 700], ['2020-01-03', 1200, 1250, 900], ['2020-01-04', 1200, 1250, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected5 = pd.DataFrame([ ['2020-01-01', 1000, 800, 800], ['2020-01-02', 700, 1200, 700], ['2020-01-03', 1200, 900, 900], ['2020-01-04', 700, 700, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_new1['sold'] = df_new1['sold'].astype(int) df_new1['curr_profit'] = df_new1['curr_profit'].astype(int) df_new2['sold'] = df_new2['sold'].astype(int) df_new3['sold'] = df_new3['sold'].astype(int) df_new3['curr_profit'] = df_new3['curr_profit'].astype(int) df_new4['sold'] = df_new4['sold'].astype(int) df_new4['curr_profit'] = df_new4['curr_profit'].astype(int) df_new5['sold'] = df_new5['sold'].astype(int) df_new5['curr_profit'] = df_new5['curr_profit'].astype(int) assert_frame_equal(df_new1, df_expected1) assert_frame_equal(df_new2, df_expected2) assert_frame_equal(df_new3, df_expected3) assert_frame_equal(df_new4, df_expected4) assert_frame_equal(df_new5, df_expected5) with self.assertRaises(Exception): _ = impute(df.copy(), action_invalid) def test_last_column(self): df = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='last_order'), ], ) df_new = last(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, last_order=1100, ), dict( group_id=2, order_id=1050, last_order=1150, ), dict( group_id=1, order_id=1100, last_order=1100, ), dict( group_id=2, order_id=1150, last_order=1150, ), ]) def test_max(self): from data_cleaner.transformer_actions.column import max action = self.
7,730
218
42,543
mage-ai__mage-ai
9ed779ccaf3538efbe1f2f54dd68f61fb1c3af55
src/data_cleaner/tests/transformer_actions/test_column.py
infile
__groupby_agg_action
true
function
104
108
true
false
[ "__groupby_agg_action", "assertEqual", "assertRaises", "test_count", "test_shift_down", "test_add_column_addition", "test_add_column_addition_days", "test_add_column_constant", "test_add_column_date_trunc", "test_add_column_difference", "test_add_column_difference_days", "test_add_column_distance_between", "test_add_column_divide", "test_add_column_formatted_date", "test_add_column_if_else", "test_add_column_if_else_with_column", "test_add_column_multiply", "test_add_column_string_replace", "test_add_column_string_split", "test_add_column_substring", "test_average", "test_count_distinct", "test_count_with_filter", "test_count_with_time_window", "test_diff", "test_first_column", "test_impute", "test_last_column", "test_max", "test_median", "test_min", "test_remove_column", "test_select", "test_shift_down_with_groupby", "test_shift_up", "test_sum", "setUp", "tearDown", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "countTestCases", "type": "function" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_column_addition", "type": "function" }, { "name": "test_add_column_addition_days", "type": "function" }, { "name": "test_add_column_constant", "type": "function" }, { "name": "test_add_column_date_trunc", "type": "function" }, { "name": "test_add_column_difference", "type": "function" }, { "name": "test_add_column_difference_days", "type": "function" }, { "name": "test_add_column_distance_between", "type": "function" }, { "name": "test_add_column_divide", "type": "function" }, { "name": "test_add_column_formatted_date", "type": "function" }, { "name": "test_add_column_if_else", "type": "function" }, { "name": "test_add_column_if_else_with_column", "type": "function" }, { "name": "test_add_column_multiply", "type": "function" }, { "name": "test_add_column_string_replace", "type": "function" }, { "name": "test_add_column_string_split", "type": "function" }, { "name": "test_add_column_substring", "type": "function" }, { "name": "test_average", "type": "function" }, { "name": "test_count", "type": "function" }, { "name": "test_count_distinct", "type": "function" }, { "name": "test_count_with_filter", "type": "function" }, { "name": "test_count_with_time_window", "type": "function" }, { "name": "test_diff", "type": "function" }, { "name": "test_first_column", "type": "function" }, { "name": "test_impute", "type": "function" }, { "name": "test_last_column", "type": "function" }, { "name": "test_max", "type": "function" }, { "name": "test_median", "type": "function" }, { "name": "test_min", "type": "function" }, { "name": "test_remove_column", "type": "function" }, { "name": "test_select", "type": "function" }, { "name": "test_shift_down", "type": "function" }, { "name": "test_shift_down_with_groupby", "type": "function" }, { "name": "test_shift_up", "type": "function" }, { "name": "test_sum", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__groupby_agg_action", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.tests.base_test import TestCase from data_cleaner.transformer_actions.column import ( add_column, count, count_distinct, diff, # expand_column, first, last, remove_column, select, shift_down, shift_up, ) from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd TEST_DATAFRAME = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'amount', ]) class ColumnTests(TestCase): def test_remove_column(self): df = pd.DataFrame([ [0, False, 'a'], [1, True, 'b'], ], columns=[ 'integer', 'boolean', 'string', ]) action = dict(action_arguments=['string']) df_new = remove_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( integer=0, boolean=False, ), dict( integer=1, boolean=True, ), ]) action = dict(action_arguments=['integer', 'boolean']) df_new = remove_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( string='a', ), dict( string='b', ), ]) def test_add_column_addition(self): df = pd.DataFrame([ [1, 3, 7, 9], [4, 2, 9, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', 'integer3', ], action_options={ 'udf': 'addition', 'value': None, }, outputs=[ dict( uuid='integer_addition', column_type='number', ), ], ) action2 = dict( action_arguments=['integer1'], action_options={ 'udf': 'addition', 'value': 10, }, outputs=[ dict( uuid='integer_addition2', column_type='number', ), ], ) action3 = dict( action_arguments=['integer1', 'integer4'], action_options={ 'udf': 'addition', 'value': 10, }, outputs=[ dict( uuid='integer_addition3', column_type='number', ), ], ) df_new = add_column( add_column( add_column(df, action1), action2, ), action3, ) df_expected = pd.DataFrame([ [1, 3, 7, 9, 11, 11, 20], [4, 2, 9, 3, 15, 14, 17], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_addition', 'integer_addition2', 'integer_addition3', ]) assert_frame_equal(df_new, df_expected) def test_add_column_addition_days(self): df = pd.DataFrame([ ['2021-08-31'], ['2021-08-28'], ], columns=[ 'created_at', ]) action = dict( action_arguments=['created_at'], action_options=dict( column_type='datetime', time_unit='d', udf='addition', value=3, ), outputs=[ dict( uuid='3d_after_creation', column_type='text', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['2021-08-31', '2021-09-03 00:00:00'], ['2021-08-28', '2021-08-31 00:00:00'], ], columns=[ 'created_at', '3d_after_creation' ]) assert_frame_equal(df_new, df_expected) def test_add_column_constant(self): df = pd.DataFrame([ [False], [True], ], columns=[ 'boolean', ]) action = dict( action_arguments=[10], action_options=dict( udf='constant', ), outputs=[ dict( uuid='integer', column_type='number', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( boolean=False, integer=10, ), dict( boolean=True, integer=10, ), ]) def test_add_column_date_trunc(self): df = pd.DataFrame([ ['2021-08-31', False], ['2021-08-28', True], ], columns=[ 'created_at', 'boolean', ]) action = dict( action_arguments=['created_at'], action_options=dict( udf='date_trunc', date_part='week', ), outputs=[ dict( uuid='week_date', column_type='text', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( created_at='2021-08-31', boolean=False, week_date='2021-08-30', ), dict( created_at='2021-08-28', boolean=True, week_date='2021-08-23', ), ]) def test_add_column_difference(self): df = pd.DataFrame([ [1, 3], [4, 2], ], columns=[ 'integer1', 'integer2', ]) action1 = dict( action_arguments=['integer1', 'integer2'], action_options={ 'udf': 'difference', }, outputs=[ dict( uuid='integer_difference', column_type='number', ), ], ) action2 = dict( action_arguments=['integer1'], action_options={ 'udf': 'difference', 'value': 10, }, outputs=[ dict( uuid='integer_difference2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [1, 3, -2, -9], [4, 2, 2, -6], ], columns=[ 'integer1', 'integer2', 'integer_difference', 'integer_difference2' ]) assert_frame_equal(df_new, df_expected) def test_add_column_difference_days(self): df = pd.DataFrame([ ['2021-08-31', '2021-09-14'], ['2021-08-28', '2021-09-03'], ], columns=[ 'created_at', 'converted_at', ]) action = dict( action_arguments=['converted_at', 'created_at'], action_options=dict( column_type='datetime', time_unit='d', udf='difference', ), outputs=[ dict( uuid='days_diff', column_type='number', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['2021-08-31', '2021-09-14', 14], ['2021-08-28', '2021-09-03', 6], ], columns=[ 'created_at', 'converted_at', 'days_diff', ]) assert_frame_equal(df_new, df_expected) def test_add_column_distance_between(self): df = pd.DataFrame([ [26.05308, -97.31838, 33.41939, -112.32606], [39.71954, -84.13056, 33.41939, -112.32606], ], columns=[ 'lat1', 'lng1', 'lat2', 'lng2', ]) action = dict( action_arguments=['lat1', 'lng1', 'lat2', 'lng2'], action_options=dict( udf='distance_between', ), outputs=[ dict( uuid='distance', column_type='number_with_decimals', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( lat1=26.05308, lng1=-97.31838, lat2=33.41939, lng2=-112.32606, distance=1661.8978520305657, ), dict( lat1=39.71954, lng1=-84.13056, lat2=33.41939, lng2=-112.32606, distance=2601.5452571116184, ), ]) def test_add_column_divide(self): df = pd.DataFrame([ [12, 3, 70, 9], [4, 2, 90, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', ], action_options={ 'udf': 'divide', }, outputs=[ dict( uuid='integer_divide', column_type='number', ), ], ) action2 = dict( action_arguments=['integer3'], action_options={ 'udf': 'divide', 'value': 10, }, outputs=[ dict( uuid='integer_divide2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [12, 3, 70, 9, 4, 7], [4, 2, 90, 3, 2, 9], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_divide', 'integer_divide2' ]) assert_frame_equal(df_new, df_expected) # def test_add_column_extract_dict_string(self): # df = pd.DataFrame([ # '{\'country\': \'US\', \'age\': \'20\'}', # '{\'country\': \'CA\'}', # '{\'country\': \'UK\', \'age\': \'24\'}', # '', # ], columns=[ # 'properties', # ]) # action = dict( # action_arguments=['properties', 'country'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_country', # column_type='text', # ), # ], # ) # df_new = add_column(df, action) # self.assertEqual(df_new.to_dict(orient='records'), [ # dict( # properties='{\'country\': \'US\', \'age\': \'20\'}', # property_country='US', # ), # dict( # properties='{\'country\': \'CA\'}', # property_country='CA', # ), # dict( # properties='{\'country\': \'UK\', \'age\': \'24\'}', # property_country='UK', # ), # dict( # properties='', # property_country=np.NaN, # ), # ]) # action2 = dict( # action_arguments=['properties', 'age'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_age', # column_type='number', # ), # ], # ) # df_new2 = add_column(df, action2) # self.assertEqual(df_new2.to_dict(orient='records'), [ # dict( # properties='{\'country\': \'US\', \'age\': \'20\'}', # property_age=20, # ), # dict( # properties='{\'country\': \'CA\'}', # property_age=0, # ), # dict( # properties='{\'country\': \'UK\', \'age\': \'24\'}', # property_age=24, # ), # dict( # properties='', # property_age=0, # ), # ]) # def test_add_column_extract_dict_string_with_json(self): # df = pd.DataFrame([ # '{\"country\": \"US\", \"is_adult\": true}', # '{\"country\": \"CA\"}', # '{\"country\": \"UK\", \"is_adult\": false}', # '', # ], columns=[ # 'properties', # ]) # action = dict( # action_arguments=['properties', 'country'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_country', # column_type='text', # ), # ], # ) # df_new = add_column(df, action) # self.assertEqual(df_new.to_dict(orient='records'), [ # dict( # properties='{\"country\": \"US\", \"is_adult\": true}', # property_country='US', # ), # dict( # properties='{\"country\": \"CA\"}', # property_country='CA', # ), # dict( # properties='{\"country\": \"UK\", \"is_adult\": false}', # property_country='UK', # ), # dict( # properties='', # property_country=np.NaN, # ), # ]) # action2 = dict( # action_arguments=['properties', 'is_adult'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_is_adult', # column_type='true_or_false', # ), # ], # ) # df_new2 = add_column(df, action2) # self.assertEqual(df_new2.to_dict(orient='records'), [ # dict( # properties='{\"country\": \"US\", \"is_adult\": true}', # property_is_adult=True, # ), # dict( # properties='{\"country\": \"CA\"}', # property_is_adult=None, # ), # dict( # properties='{\"country\": \"UK\", \"is_adult\": false}', # property_is_adult=False, # ), # dict( # properties='', # property_is_adult=None, # ), # ]) def test_add_column_formatted_date(self): df = pd.DataFrame([ ['2019-04-10 08:20:58', False], ['2019-03-05 03:30:30', True], ], columns=[ 'created_at', 'boolean', ]) action = dict( action_arguments=['created_at'], action_options=dict( udf='formatted_date', format='%Y-%m-%d', ), outputs=[ dict( uuid='created_date', column_type='text', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( created_at='2019-04-10 08:20:58', boolean=False, created_date='2019-04-10', ), dict( created_at='2019-03-05 03:30:30', boolean=True, created_date='2019-03-05', ), ]) def test_add_column_if_else(self): df = pd.DataFrame([ ['2019-04-10 08:20:58'], [None], ], columns=[ 'converted_at' ]) action = dict( action_arguments=[False, True], action_code='converted_at == null', action_options=dict( udf='if_else', ), outputs=[ dict( uuid='converted', column_type='true_or_false', ), ], ) df_new = add_column(df, action, original_df=df) self.assertEqual(df_new.to_dict(orient='records'), [ dict( converted_at='2019-04-10 08:20:58', converted=True, ), dict( converted_at=None, converted=False, ), ]) def test_add_column_if_else_with_column(self): df = pd.DataFrame([ ['2019-04-10 08:20:58', 'test_user_id'], [None, None], ], columns=[ 'converted_at', 'user_id', ]) action = dict( action_arguments=['unknown', 'user_id'], action_code='converted_at == null', action_options=dict( udf='if_else', arg1_type='value', arg2_type='column', ), outputs=[ dict( uuid='user_id_clean', column_type='text', ), ], ) df_new = add_column(df, action, original_df=df) self.assertEqual(df_new.to_dict(orient='records'), [ dict( converted_at='2019-04-10 08:20:58', user_id='test_user_id', user_id_clean='test_user_id', ), dict( converted_at=None, user_id=None, user_id_clean='unknown', ), ]) def test_add_column_multiply(self): df = pd.DataFrame([ [1, 3, 7, 9], [4, 2, 9, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', ], action_options={ 'udf': 'multiply', }, outputs=[ dict( uuid='integer_multiply', column_type='number', ), ], ) action2 = dict( action_arguments=['integer3'], action_options={ 'udf': 'multiply', 'value': 10, }, outputs=[ dict( uuid='integer_multiply2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [1, 3, 7, 9, 3, 70], [4, 2, 9, 3, 8, 90], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_multiply', 'integer_multiply2' ]) assert_frame_equal(df_new, df_expected) def test_add_column_string_replace(self): df = pd.DataFrame([ ['$1000'], ['$321. '], ['$4,321'], ], columns=[ 'amount', ]) action = dict( action_arguments=['amount'], action_options={ 'udf': 'string_replace', 'pattern': '\\$|\\.|\\,|\\s*', 'replacement': '', }, outputs=[ dict( uuid='amount_clean', column_type='true_or_false', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['$1000', '1000'], ['$321. ', '321'], ['$4,321', '4321'], ], columns=[ 'amount', 'amount_clean', ]) assert_frame_equal(df_new, df_expected) def test_add_column_string_split(self): df = pd.DataFrame([ ['Street1, Long Beach, CA, '], ['Street2,Vernon, CA, 123'], ['Pacific Coast Highway, Los Angeles, CA, 111'], ], columns=[ 'location', ]) action = dict( action_arguments=['location'], action_options={ 'udf': 'string_split', 'separator': ',', 'part_index': 1, }, outputs=[ dict( uuid='location_city', column_type='text', ), ], ) action2 = dict( action_arguments=['location'], action_options={ 'udf': 'string_split', 'separator': ',', 'part_index': 3, }, outputs=[ dict( uuid='num', column_type='number', ), ], ) df_new = add_column(add_column(df, action), action2) df_expected = pd.DataFrame([ ['Street1, Long Beach, CA, ', 'Long Beach', 0], ['Street2,Vernon, CA, 123', 'Vernon', 123], ['Pacific Coast Highway, Los Angeles, CA, 111', 'Los Angeles', 111], ], columns=[ 'location', 'location_city', 'num', ]) assert_frame_equal(df_new, df_expected) def test_add_column_substring(self): df = pd.DataFrame([ ['$1000.0'], ['$321.9'], ], columns=[ 'amount', ]) action = dict( action_arguments=['amount'], action_options={ 'udf': 'substring', 'start': 1, 'stop': -2, }, outputs=[ dict( uuid='amount_int', column_type='text', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['$1000.0', '1000'], ['$321.9', '321'], ], columns=[ 'amount', 'amount_int', ]) assert_frame_equal(df_new, df_expected) def test_average(self): from data_cleaner.transformer_actions.column import average action = self.__groupby_agg_action('average_amount') df_new = average(TEST_DATAFRAME.copy(), action) df_expected = pd.DataFrame([ [1, 1000, 1050], [2, 1050, 1100], [1, 1100, 1050], [2, 1150, 1100], ], columns=[ 'group_id', 'amount', 'average_amount' ]) assert_frame_equal(df_new, df_expected) def test_count(self): df = pd.DataFrame([ [1, 1000], [1, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='order_count'), ], ) df_new = count(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, order_count=3, ), dict( group_id=1, order_id=1050, order_count=3, ), dict( group_id=1, order_id=1100, order_count=3, ), dict( group_id=2, order_id=1150, order_count=1, ), ]) def test_count_distinct(self): df = pd.DataFrame([ [1, 1000], [1, 1000], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='order_count'), ], ) df_new = count_distinct(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, order_count=2, ), dict( group_id=1, order_id=1000, order_count=2, ), dict( group_id=1, order_id=1100, order_count=2, ), dict( group_id=2, order_id=1150, order_count=1, ), ]) def test_count_with_time_window(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) action = dict( action_arguments=['order_id'], action_code='', action_options=dict( groupby_columns=['group_id'], timestamp_feature_a='group_churned_at', timestamp_feature_b='order_created_at', window=90*24*3600, ), outputs=[ dict(uuid='order_count'), ], ) df_new = count(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, group_churned_at='2021-10-01', order_created_at='2021-09-01', order_count=2, ), dict( group_id=1, order_id=1050, group_churned_at='2021-10-01', order_created_at='2021-08-01', order_count=2, ), dict( group_id=1, order_id=1100, group_churned_at='2021-10-01', order_created_at='2021-01-01', order_count=2, ), dict( group_id=2, order_id=1150, group_churned_at='2021-09-01', order_created_at='2021-08-01', order_count=1, ), ]) def test_count_with_filter(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], [2, 1200, '2021-09-01', '2021-08-16'], [2, 1250, '2021-09-01', '2021-08-14'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) action = dict( action_arguments=['order_id'], action_code='order_created_at < \'2021-08-15\'', action_options=dict( groupby_columns=['group_id'], ), outputs=[ dict(uuid='order_count'), ], ) df_new = count(df, action) df_expected = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01', 2], [1, 1050, '2021-10-01', '2021-08-01', 2], [1, 1100, '2021-10-01', '2021-01-01', 2], [2, 1150, '2021-09-01', '2021-08-01', 2], [2, 1200, '2021-09-01', '2021-08-16', 2], [2, 1250, '2021-09-01', '2021-08-14', 2], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', 'order_count', ]) assert_frame_equal(df_new, df_expected) def test_diff(self): df = pd.DataFrame([ ['2020-01-01', 1000], ['2020-01-02', 1050], ['2020-01-03', 1200], ['2020-01-04', 990], ], columns=[ 'date', 'sold', ]) action = dict( action_arguments=['sold'], outputs=[ dict(uuid='sold_diff'), ], ) df_new = diff(df, action) self.assertEqual(df_new.to_dict(orient='records')[1:], [ dict( date='2020-01-02', sold=1050, sold_diff=50, ), dict( date='2020-01-03', sold=1200, sold_diff=150, ), dict( date='2020-01-04', sold=990, sold_diff=-210, ), ]) # def test_expand_column(self): # df = pd.DataFrame([ # [1, 'game'], # [1, 'book'], # [1, 'game'], # [2, 'Video Game'], # [1, 'Video Game'], # [2, 'book'], # [1, 'Video Game'], # [2, 'Video Game'], # ], columns=[ # 'group_id', # 'category', # ]) # action = dict( # action_arguments=['category'], # action_options=dict( # groupby_columns=['group_id'] # ), # outputs=[ # dict(uuid='category_expanded_count_game'), # dict(uuid='category_expanded_count_book'), # dict(uuid='category_expanded_count_video_game'), # dict(uuid='category_expanded_count_clothing'), # ], # ) # df_new = expand_column(df, action) # df_expected = pd.DataFrame([ # [1, 'game', 2, 1, 2], # [1, 'book', 2, 1, 2], # [1, 'game', 2, 1, 2], # [2, 'Video Game', 0, 1, 2], # [1, 'Video Game', 2, 1, 2], # [2, 'book', 0, 1, 2], # [1, 'Video Game', 2, 1, 2], # [2, 'Video Game', 0, 1, 2], # ], columns=[ # 'group_id', # 'category', # 'category_expanded_count_game', # 'category_expanded_count_book', # 'category_expanded_count_video_game', # ]) # assert_frame_equal(df_new, df_expected) # def test_expand_column_with_time_window(self): # df = pd.DataFrame([ # [1, 'game', '2021-01-02', '2021-01-04'], # [1, 'book', '2021-01-02', '2021-01-04'], # [1, 'game', '2021-01-03', '2021-01-04'], # [2, 'Video Game', '2021-01-01', '2021-01-03'], # [1, 'Video Game', '2021-01-01', '2021-01-04'], # [2, 'book', '2021-01-02', '2021-01-03'], # [1, 'Video Game', '2021-01-03', '2021-01-04'], # [2, 'Video Game', '2020-12-30', '2021-01-03'], # ], columns=[ # 'group_id', # 'category', # 'timestamp1', # 'timestamp2', # ]) # action = dict( # action_arguments=['category'], # action_options=dict( # groupby_columns=['group_id'], # timestamp_feature_a='timestamp2', # timestamp_feature_b='timestamp1', # window=172800, # ), # outputs=[ # dict(uuid='category_expanded_count_game_2d'), # dict(uuid='category_expanded_count_book_2d'), # dict(uuid='category_expanded_count_video_game_2d'), # dict(uuid='category_expanded_count_clothing_2d'), # ], # ) # df_new = expand_column(df, action) # df_expected = pd.DataFrame([ # [1, 'game', '2021-01-02', '2021-01-04', 2, 1, 1], # [1, 'book', '2021-01-02', '2021-01-04', 2, 1, 1], # [1, 'game', '2021-01-03', '2021-01-04', 2, 1, 1], # [2, 'Video Game', '2021-01-01', '2021-01-03', 0, 1, 1], # [1, 'Video Game', '2021-01-01', '2021-01-04', 2, 1, 1], # [2, 'book', '2021-01-02', '2021-01-03', 0, 1, 1], # [1, 'Video Game', '2021-01-03', '2021-01-04', 2, 1, 1], # [2, 'Video Game', '2020-12-30', '2021-01-03', 0, 1, 1], # ], columns=[ # 'group_id', # 'category', # 'timestamp1', # 'timestamp2', # 'category_expanded_count_game_2d', # 'category_expanded_count_book_2d', # 'category_expanded_count_video_game_2d', # ]) # assert_frame_equal(df_new, df_expected) def test_first_column(self): df = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='first_order'), ], ) df_new = first(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, first_order=1000, ), dict( group_id=2, order_id=1050, first_order=1050, ), dict( group_id=1, order_id=1100, first_order=1000, ), dict( group_id=2, order_id=1150, first_order=1050, ), ]) def test_impute(self): from data_cleaner.transformer_actions.column import impute df = pd.DataFrame([ ['2020-01-01', 1000, ' ', 800], ['2020-01-02', '', 1200, 700], ['2020-01-03', 1200, np.NaN, 900], ['2020-01-04', np.NaN, ' ', 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) action1 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'value': '0', }, action_variables={ '0': { 'feature': { 'column_type': 'number', 'uuid': 'sold', }, 'type': 'feature', }, '1': { 'feature': { 'column_type': 'number', 'uuid': 'curr_profit', }, 'type': 'feature', }, }, ) action2 = dict( action_arguments=['sold'], action_options={ 'value': '0', }, action_variables={ '0': { 'feature': { 'column_type': 'number', 'uuid': 'sold', }, 'type': 'feature', }, }, ) action3 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'average', }, ) action4 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'median', }, ) action5 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'column', 'value': 'prev_sold', }, ) action_invalid = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'mode', }, ) df_new1 = impute(df.copy(), action1) df_new2 = impute(df.copy(), action2) df_new3 = impute(df.copy(), action3) df_new4 = impute(df.copy(), action4) df_new5 = impute(df.copy(), action5) df_expected1 = pd.DataFrame([ ['2020-01-01', 1000, 0, 800], ['2020-01-02', 0, 1200, 700], ['2020-01-03', 1200, 0, 900], ['2020-01-04', 0, 0, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected2 = pd.DataFrame([ ['2020-01-01', 1000, ' ', 800], ['2020-01-02', 0, 1200, 700], ['2020-01-03', 1200, np.nan, 900], ['2020-01-04', 0, ' ', 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected3 = pd.DataFrame([ ['2020-01-01', 1000, 1250, 800], ['2020-01-02', 1300, 1200, 700], ['2020-01-03', 1200, 1250, 900], ['2020-01-04', 1300, 1250, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected4 = pd.DataFrame([ ['2020-01-01', 1000, 1250, 800], ['2020-01-02', 1200, 1200, 700], ['2020-01-03', 1200, 1250, 900], ['2020-01-04', 1200, 1250, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected5 = pd.DataFrame([ ['2020-01-01', 1000, 800, 800], ['2020-01-02', 700, 1200, 700], ['2020-01-03', 1200, 900, 900], ['2020-01-04', 700, 700, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_new1['sold'] = df_new1['sold'].astype(int) df_new1['curr_profit'] = df_new1['curr_profit'].astype(int) df_new2['sold'] = df_new2['sold'].astype(int) df_new3['sold'] = df_new3['sold'].astype(int) df_new3['curr_profit'] = df_new3['curr_profit'].astype(int) df_new4['sold'] = df_new4['sold'].astype(int) df_new4['curr_profit'] = df_new4['curr_profit'].astype(int) df_new5['sold'] = df_new5['sold'].astype(int) df_new5['curr_profit'] = df_new5['curr_profit'].astype(int) assert_frame_equal(df_new1, df_expected1) assert_frame_equal(df_new2, df_expected2) assert_frame_equal(df_new3, df_expected3) assert_frame_equal(df_new4, df_expected4) assert_frame_equal(df_new5, df_expected5) with self.assertRaises(Exception): _ = impute(df.copy(), action_invalid) def test_last_column(self): df = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='last_order'), ], ) df_new = last(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, last_order=1100, ), dict( group_id=2, order_id=1050, last_order=1150, ), dict( group_id=1, order_id=1100, last_order=1100, ), dict( group_id=2, order_id=1150, last_order=1150, ), ]) def test_max(self): from data_cleaner.transformer_actions.column import max action = self.__groupby_agg_action('max_amount') df_new = max(TEST_DATAFRAME.copy(), action) df_expected = pd.DataFrame([ [1, 1000, 1100], [2, 1050, 1150], [1, 1100, 1100], [2, 1150, 1150], ], columns=[ 'group_id', 'amount', 'max_amount', ]) assert_frame_equal(df_new, df_expected) action2 = dict( action_arguments=['amount'], action_options=dict(), outputs=[ dict(uuid='max_amount'), ], ) df_new2 = max(TEST_DATAFRAME.copy(), action2) df_expected2 = pd.DataFrame([ [1, 1000, 1150], [2, 1050, 1150], [1, 1100, 1150], [2, 1150, 1150], ], columns=[ 'group_id', 'amount', 'max_amount', ]) assert_frame_equal(df_new2, df_expected2) def test_median(self): from data_cleaner.transformer_actions.column import median action = self.
7,731
218
43,286
mage-ai__mage-ai
9ed779ccaf3538efbe1f2f54dd68f61fb1c3af55
src/data_cleaner/tests/transformer_actions/test_column.py
infile
__groupby_agg_action
true
function
104
108
true
false
[ "__groupby_agg_action", "assertEqual", "assertRaises", "test_count", "test_shift_down", "test_add_column_addition", "test_add_column_addition_days", "test_add_column_constant", "test_add_column_date_trunc", "test_add_column_difference", "test_add_column_difference_days", "test_add_column_distance_between", "test_add_column_divide", "test_add_column_formatted_date", "test_add_column_if_else", "test_add_column_if_else_with_column", "test_add_column_multiply", "test_add_column_string_replace", "test_add_column_string_split", "test_add_column_substring", "test_average", "test_count_distinct", "test_count_with_filter", "test_count_with_time_window", "test_diff", "test_first_column", "test_impute", "test_last_column", "test_max", "test_median", "test_min", "test_remove_column", "test_select", "test_shift_down_with_groupby", "test_shift_up", "test_sum", "setUp", "tearDown", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "countTestCases", "type": "function" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_column_addition", "type": "function" }, { "name": "test_add_column_addition_days", "type": "function" }, { "name": "test_add_column_constant", "type": "function" }, { "name": "test_add_column_date_trunc", "type": "function" }, { "name": "test_add_column_difference", "type": "function" }, { "name": "test_add_column_difference_days", "type": "function" }, { "name": "test_add_column_distance_between", "type": "function" }, { "name": "test_add_column_divide", "type": "function" }, { "name": "test_add_column_formatted_date", "type": "function" }, { "name": "test_add_column_if_else", "type": "function" }, { "name": "test_add_column_if_else_with_column", "type": "function" }, { "name": "test_add_column_multiply", "type": "function" }, { "name": "test_add_column_string_replace", "type": "function" }, { "name": "test_add_column_string_split", "type": "function" }, { "name": "test_add_column_substring", "type": "function" }, { "name": "test_average", "type": "function" }, { "name": "test_count", "type": "function" }, { "name": "test_count_distinct", "type": "function" }, { "name": "test_count_with_filter", "type": "function" }, { "name": "test_count_with_time_window", "type": "function" }, { "name": "test_diff", "type": "function" }, { "name": "test_first_column", "type": "function" }, { "name": "test_impute", "type": "function" }, { "name": "test_last_column", "type": "function" }, { "name": "test_max", "type": "function" }, { "name": "test_median", "type": "function" }, { "name": "test_min", "type": "function" }, { "name": "test_remove_column", "type": "function" }, { "name": "test_select", "type": "function" }, { "name": "test_shift_down", "type": "function" }, { "name": "test_shift_down_with_groupby", "type": "function" }, { "name": "test_shift_up", "type": "function" }, { "name": "test_sum", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__groupby_agg_action", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.tests.base_test import TestCase from data_cleaner.transformer_actions.column import ( add_column, count, count_distinct, diff, # expand_column, first, last, remove_column, select, shift_down, shift_up, ) from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd TEST_DATAFRAME = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'amount', ]) class ColumnTests(TestCase): def test_remove_column(self): df = pd.DataFrame([ [0, False, 'a'], [1, True, 'b'], ], columns=[ 'integer', 'boolean', 'string', ]) action = dict(action_arguments=['string']) df_new = remove_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( integer=0, boolean=False, ), dict( integer=1, boolean=True, ), ]) action = dict(action_arguments=['integer', 'boolean']) df_new = remove_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( string='a', ), dict( string='b', ), ]) def test_add_column_addition(self): df = pd.DataFrame([ [1, 3, 7, 9], [4, 2, 9, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', 'integer3', ], action_options={ 'udf': 'addition', 'value': None, }, outputs=[ dict( uuid='integer_addition', column_type='number', ), ], ) action2 = dict( action_arguments=['integer1'], action_options={ 'udf': 'addition', 'value': 10, }, outputs=[ dict( uuid='integer_addition2', column_type='number', ), ], ) action3 = dict( action_arguments=['integer1', 'integer4'], action_options={ 'udf': 'addition', 'value': 10, }, outputs=[ dict( uuid='integer_addition3', column_type='number', ), ], ) df_new = add_column( add_column( add_column(df, action1), action2, ), action3, ) df_expected = pd.DataFrame([ [1, 3, 7, 9, 11, 11, 20], [4, 2, 9, 3, 15, 14, 17], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_addition', 'integer_addition2', 'integer_addition3', ]) assert_frame_equal(df_new, df_expected) def test_add_column_addition_days(self): df = pd.DataFrame([ ['2021-08-31'], ['2021-08-28'], ], columns=[ 'created_at', ]) action = dict( action_arguments=['created_at'], action_options=dict( column_type='datetime', time_unit='d', udf='addition', value=3, ), outputs=[ dict( uuid='3d_after_creation', column_type='text', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['2021-08-31', '2021-09-03 00:00:00'], ['2021-08-28', '2021-08-31 00:00:00'], ], columns=[ 'created_at', '3d_after_creation' ]) assert_frame_equal(df_new, df_expected) def test_add_column_constant(self): df = pd.DataFrame([ [False], [True], ], columns=[ 'boolean', ]) action = dict( action_arguments=[10], action_options=dict( udf='constant', ), outputs=[ dict( uuid='integer', column_type='number', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( boolean=False, integer=10, ), dict( boolean=True, integer=10, ), ]) def test_add_column_date_trunc(self): df = pd.DataFrame([ ['2021-08-31', False], ['2021-08-28', True], ], columns=[ 'created_at', 'boolean', ]) action = dict( action_arguments=['created_at'], action_options=dict( udf='date_trunc', date_part='week', ), outputs=[ dict( uuid='week_date', column_type='text', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( created_at='2021-08-31', boolean=False, week_date='2021-08-30', ), dict( created_at='2021-08-28', boolean=True, week_date='2021-08-23', ), ]) def test_add_column_difference(self): df = pd.DataFrame([ [1, 3], [4, 2], ], columns=[ 'integer1', 'integer2', ]) action1 = dict( action_arguments=['integer1', 'integer2'], action_options={ 'udf': 'difference', }, outputs=[ dict( uuid='integer_difference', column_type='number', ), ], ) action2 = dict( action_arguments=['integer1'], action_options={ 'udf': 'difference', 'value': 10, }, outputs=[ dict( uuid='integer_difference2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [1, 3, -2, -9], [4, 2, 2, -6], ], columns=[ 'integer1', 'integer2', 'integer_difference', 'integer_difference2' ]) assert_frame_equal(df_new, df_expected) def test_add_column_difference_days(self): df = pd.DataFrame([ ['2021-08-31', '2021-09-14'], ['2021-08-28', '2021-09-03'], ], columns=[ 'created_at', 'converted_at', ]) action = dict( action_arguments=['converted_at', 'created_at'], action_options=dict( column_type='datetime', time_unit='d', udf='difference', ), outputs=[ dict( uuid='days_diff', column_type='number', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['2021-08-31', '2021-09-14', 14], ['2021-08-28', '2021-09-03', 6], ], columns=[ 'created_at', 'converted_at', 'days_diff', ]) assert_frame_equal(df_new, df_expected) def test_add_column_distance_between(self): df = pd.DataFrame([ [26.05308, -97.31838, 33.41939, -112.32606], [39.71954, -84.13056, 33.41939, -112.32606], ], columns=[ 'lat1', 'lng1', 'lat2', 'lng2', ]) action = dict( action_arguments=['lat1', 'lng1', 'lat2', 'lng2'], action_options=dict( udf='distance_between', ), outputs=[ dict( uuid='distance', column_type='number_with_decimals', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( lat1=26.05308, lng1=-97.31838, lat2=33.41939, lng2=-112.32606, distance=1661.8978520305657, ), dict( lat1=39.71954, lng1=-84.13056, lat2=33.41939, lng2=-112.32606, distance=2601.5452571116184, ), ]) def test_add_column_divide(self): df = pd.DataFrame([ [12, 3, 70, 9], [4, 2, 90, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', ], action_options={ 'udf': 'divide', }, outputs=[ dict( uuid='integer_divide', column_type='number', ), ], ) action2 = dict( action_arguments=['integer3'], action_options={ 'udf': 'divide', 'value': 10, }, outputs=[ dict( uuid='integer_divide2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [12, 3, 70, 9, 4, 7], [4, 2, 90, 3, 2, 9], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_divide', 'integer_divide2' ]) assert_frame_equal(df_new, df_expected) # def test_add_column_extract_dict_string(self): # df = pd.DataFrame([ # '{\'country\': \'US\', \'age\': \'20\'}', # '{\'country\': \'CA\'}', # '{\'country\': \'UK\', \'age\': \'24\'}', # '', # ], columns=[ # 'properties', # ]) # action = dict( # action_arguments=['properties', 'country'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_country', # column_type='text', # ), # ], # ) # df_new = add_column(df, action) # self.assertEqual(df_new.to_dict(orient='records'), [ # dict( # properties='{\'country\': \'US\', \'age\': \'20\'}', # property_country='US', # ), # dict( # properties='{\'country\': \'CA\'}', # property_country='CA', # ), # dict( # properties='{\'country\': \'UK\', \'age\': \'24\'}', # property_country='UK', # ), # dict( # properties='', # property_country=np.NaN, # ), # ]) # action2 = dict( # action_arguments=['properties', 'age'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_age', # column_type='number', # ), # ], # ) # df_new2 = add_column(df, action2) # self.assertEqual(df_new2.to_dict(orient='records'), [ # dict( # properties='{\'country\': \'US\', \'age\': \'20\'}', # property_age=20, # ), # dict( # properties='{\'country\': \'CA\'}', # property_age=0, # ), # dict( # properties='{\'country\': \'UK\', \'age\': \'24\'}', # property_age=24, # ), # dict( # properties='', # property_age=0, # ), # ]) # def test_add_column_extract_dict_string_with_json(self): # df = pd.DataFrame([ # '{\"country\": \"US\", \"is_adult\": true}', # '{\"country\": \"CA\"}', # '{\"country\": \"UK\", \"is_adult\": false}', # '', # ], columns=[ # 'properties', # ]) # action = dict( # action_arguments=['properties', 'country'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_country', # column_type='text', # ), # ], # ) # df_new = add_column(df, action) # self.assertEqual(df_new.to_dict(orient='records'), [ # dict( # properties='{\"country\": \"US\", \"is_adult\": true}', # property_country='US', # ), # dict( # properties='{\"country\": \"CA\"}', # property_country='CA', # ), # dict( # properties='{\"country\": \"UK\", \"is_adult\": false}', # property_country='UK', # ), # dict( # properties='', # property_country=np.NaN, # ), # ]) # action2 = dict( # action_arguments=['properties', 'is_adult'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_is_adult', # column_type='true_or_false', # ), # ], # ) # df_new2 = add_column(df, action2) # self.assertEqual(df_new2.to_dict(orient='records'), [ # dict( # properties='{\"country\": \"US\", \"is_adult\": true}', # property_is_adult=True, # ), # dict( # properties='{\"country\": \"CA\"}', # property_is_adult=None, # ), # dict( # properties='{\"country\": \"UK\", \"is_adult\": false}', # property_is_adult=False, # ), # dict( # properties='', # property_is_adult=None, # ), # ]) def test_add_column_formatted_date(self): df = pd.DataFrame([ ['2019-04-10 08:20:58', False], ['2019-03-05 03:30:30', True], ], columns=[ 'created_at', 'boolean', ]) action = dict( action_arguments=['created_at'], action_options=dict( udf='formatted_date', format='%Y-%m-%d', ), outputs=[ dict( uuid='created_date', column_type='text', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( created_at='2019-04-10 08:20:58', boolean=False, created_date='2019-04-10', ), dict( created_at='2019-03-05 03:30:30', boolean=True, created_date='2019-03-05', ), ]) def test_add_column_if_else(self): df = pd.DataFrame([ ['2019-04-10 08:20:58'], [None], ], columns=[ 'converted_at' ]) action = dict( action_arguments=[False, True], action_code='converted_at == null', action_options=dict( udf='if_else', ), outputs=[ dict( uuid='converted', column_type='true_or_false', ), ], ) df_new = add_column(df, action, original_df=df) self.assertEqual(df_new.to_dict(orient='records'), [ dict( converted_at='2019-04-10 08:20:58', converted=True, ), dict( converted_at=None, converted=False, ), ]) def test_add_column_if_else_with_column(self): df = pd.DataFrame([ ['2019-04-10 08:20:58', 'test_user_id'], [None, None], ], columns=[ 'converted_at', 'user_id', ]) action = dict( action_arguments=['unknown', 'user_id'], action_code='converted_at == null', action_options=dict( udf='if_else', arg1_type='value', arg2_type='column', ), outputs=[ dict( uuid='user_id_clean', column_type='text', ), ], ) df_new = add_column(df, action, original_df=df) self.assertEqual(df_new.to_dict(orient='records'), [ dict( converted_at='2019-04-10 08:20:58', user_id='test_user_id', user_id_clean='test_user_id', ), dict( converted_at=None, user_id=None, user_id_clean='unknown', ), ]) def test_add_column_multiply(self): df = pd.DataFrame([ [1, 3, 7, 9], [4, 2, 9, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', ], action_options={ 'udf': 'multiply', }, outputs=[ dict( uuid='integer_multiply', column_type='number', ), ], ) action2 = dict( action_arguments=['integer3'], action_options={ 'udf': 'multiply', 'value': 10, }, outputs=[ dict( uuid='integer_multiply2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [1, 3, 7, 9, 3, 70], [4, 2, 9, 3, 8, 90], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_multiply', 'integer_multiply2' ]) assert_frame_equal(df_new, df_expected) def test_add_column_string_replace(self): df = pd.DataFrame([ ['$1000'], ['$321. '], ['$4,321'], ], columns=[ 'amount', ]) action = dict( action_arguments=['amount'], action_options={ 'udf': 'string_replace', 'pattern': '\\$|\\.|\\,|\\s*', 'replacement': '', }, outputs=[ dict( uuid='amount_clean', column_type='true_or_false', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['$1000', '1000'], ['$321. ', '321'], ['$4,321', '4321'], ], columns=[ 'amount', 'amount_clean', ]) assert_frame_equal(df_new, df_expected) def test_add_column_string_split(self): df = pd.DataFrame([ ['Street1, Long Beach, CA, '], ['Street2,Vernon, CA, 123'], ['Pacific Coast Highway, Los Angeles, CA, 111'], ], columns=[ 'location', ]) action = dict( action_arguments=['location'], action_options={ 'udf': 'string_split', 'separator': ',', 'part_index': 1, }, outputs=[ dict( uuid='location_city', column_type='text', ), ], ) action2 = dict( action_arguments=['location'], action_options={ 'udf': 'string_split', 'separator': ',', 'part_index': 3, }, outputs=[ dict( uuid='num', column_type='number', ), ], ) df_new = add_column(add_column(df, action), action2) df_expected = pd.DataFrame([ ['Street1, Long Beach, CA, ', 'Long Beach', 0], ['Street2,Vernon, CA, 123', 'Vernon', 123], ['Pacific Coast Highway, Los Angeles, CA, 111', 'Los Angeles', 111], ], columns=[ 'location', 'location_city', 'num', ]) assert_frame_equal(df_new, df_expected) def test_add_column_substring(self): df = pd.DataFrame([ ['$1000.0'], ['$321.9'], ], columns=[ 'amount', ]) action = dict( action_arguments=['amount'], action_options={ 'udf': 'substring', 'start': 1, 'stop': -2, }, outputs=[ dict( uuid='amount_int', column_type='text', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['$1000.0', '1000'], ['$321.9', '321'], ], columns=[ 'amount', 'amount_int', ]) assert_frame_equal(df_new, df_expected) def test_average(self): from data_cleaner.transformer_actions.column import average action = self.__groupby_agg_action('average_amount') df_new = average(TEST_DATAFRAME.copy(), action) df_expected = pd.DataFrame([ [1, 1000, 1050], [2, 1050, 1100], [1, 1100, 1050], [2, 1150, 1100], ], columns=[ 'group_id', 'amount', 'average_amount' ]) assert_frame_equal(df_new, df_expected) def test_count(self): df = pd.DataFrame([ [1, 1000], [1, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='order_count'), ], ) df_new = count(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, order_count=3, ), dict( group_id=1, order_id=1050, order_count=3, ), dict( group_id=1, order_id=1100, order_count=3, ), dict( group_id=2, order_id=1150, order_count=1, ), ]) def test_count_distinct(self): df = pd.DataFrame([ [1, 1000], [1, 1000], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='order_count'), ], ) df_new = count_distinct(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, order_count=2, ), dict( group_id=1, order_id=1000, order_count=2, ), dict( group_id=1, order_id=1100, order_count=2, ), dict( group_id=2, order_id=1150, order_count=1, ), ]) def test_count_with_time_window(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) action = dict( action_arguments=['order_id'], action_code='', action_options=dict( groupby_columns=['group_id'], timestamp_feature_a='group_churned_at', timestamp_feature_b='order_created_at', window=90*24*3600, ), outputs=[ dict(uuid='order_count'), ], ) df_new = count(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, group_churned_at='2021-10-01', order_created_at='2021-09-01', order_count=2, ), dict( group_id=1, order_id=1050, group_churned_at='2021-10-01', order_created_at='2021-08-01', order_count=2, ), dict( group_id=1, order_id=1100, group_churned_at='2021-10-01', order_created_at='2021-01-01', order_count=2, ), dict( group_id=2, order_id=1150, group_churned_at='2021-09-01', order_created_at='2021-08-01', order_count=1, ), ]) def test_count_with_filter(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], [2, 1200, '2021-09-01', '2021-08-16'], [2, 1250, '2021-09-01', '2021-08-14'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) action = dict( action_arguments=['order_id'], action_code='order_created_at < \'2021-08-15\'', action_options=dict( groupby_columns=['group_id'], ), outputs=[ dict(uuid='order_count'), ], ) df_new = count(df, action) df_expected = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01', 2], [1, 1050, '2021-10-01', '2021-08-01', 2], [1, 1100, '2021-10-01', '2021-01-01', 2], [2, 1150, '2021-09-01', '2021-08-01', 2], [2, 1200, '2021-09-01', '2021-08-16', 2], [2, 1250, '2021-09-01', '2021-08-14', 2], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', 'order_count', ]) assert_frame_equal(df_new, df_expected) def test_diff(self): df = pd.DataFrame([ ['2020-01-01', 1000], ['2020-01-02', 1050], ['2020-01-03', 1200], ['2020-01-04', 990], ], columns=[ 'date', 'sold', ]) action = dict( action_arguments=['sold'], outputs=[ dict(uuid='sold_diff'), ], ) df_new = diff(df, action) self.assertEqual(df_new.to_dict(orient='records')[1:], [ dict( date='2020-01-02', sold=1050, sold_diff=50, ), dict( date='2020-01-03', sold=1200, sold_diff=150, ), dict( date='2020-01-04', sold=990, sold_diff=-210, ), ]) # def test_expand_column(self): # df = pd.DataFrame([ # [1, 'game'], # [1, 'book'], # [1, 'game'], # [2, 'Video Game'], # [1, 'Video Game'], # [2, 'book'], # [1, 'Video Game'], # [2, 'Video Game'], # ], columns=[ # 'group_id', # 'category', # ]) # action = dict( # action_arguments=['category'], # action_options=dict( # groupby_columns=['group_id'] # ), # outputs=[ # dict(uuid='category_expanded_count_game'), # dict(uuid='category_expanded_count_book'), # dict(uuid='category_expanded_count_video_game'), # dict(uuid='category_expanded_count_clothing'), # ], # ) # df_new = expand_column(df, action) # df_expected = pd.DataFrame([ # [1, 'game', 2, 1, 2], # [1, 'book', 2, 1, 2], # [1, 'game', 2, 1, 2], # [2, 'Video Game', 0, 1, 2], # [1, 'Video Game', 2, 1, 2], # [2, 'book', 0, 1, 2], # [1, 'Video Game', 2, 1, 2], # [2, 'Video Game', 0, 1, 2], # ], columns=[ # 'group_id', # 'category', # 'category_expanded_count_game', # 'category_expanded_count_book', # 'category_expanded_count_video_game', # ]) # assert_frame_equal(df_new, df_expected) # def test_expand_column_with_time_window(self): # df = pd.DataFrame([ # [1, 'game', '2021-01-02', '2021-01-04'], # [1, 'book', '2021-01-02', '2021-01-04'], # [1, 'game', '2021-01-03', '2021-01-04'], # [2, 'Video Game', '2021-01-01', '2021-01-03'], # [1, 'Video Game', '2021-01-01', '2021-01-04'], # [2, 'book', '2021-01-02', '2021-01-03'], # [1, 'Video Game', '2021-01-03', '2021-01-04'], # [2, 'Video Game', '2020-12-30', '2021-01-03'], # ], columns=[ # 'group_id', # 'category', # 'timestamp1', # 'timestamp2', # ]) # action = dict( # action_arguments=['category'], # action_options=dict( # groupby_columns=['group_id'], # timestamp_feature_a='timestamp2', # timestamp_feature_b='timestamp1', # window=172800, # ), # outputs=[ # dict(uuid='category_expanded_count_game_2d'), # dict(uuid='category_expanded_count_book_2d'), # dict(uuid='category_expanded_count_video_game_2d'), # dict(uuid='category_expanded_count_clothing_2d'), # ], # ) # df_new = expand_column(df, action) # df_expected = pd.DataFrame([ # [1, 'game', '2021-01-02', '2021-01-04', 2, 1, 1], # [1, 'book', '2021-01-02', '2021-01-04', 2, 1, 1], # [1, 'game', '2021-01-03', '2021-01-04', 2, 1, 1], # [2, 'Video Game', '2021-01-01', '2021-01-03', 0, 1, 1], # [1, 'Video Game', '2021-01-01', '2021-01-04', 2, 1, 1], # [2, 'book', '2021-01-02', '2021-01-03', 0, 1, 1], # [1, 'Video Game', '2021-01-03', '2021-01-04', 2, 1, 1], # [2, 'Video Game', '2020-12-30', '2021-01-03', 0, 1, 1], # ], columns=[ # 'group_id', # 'category', # 'timestamp1', # 'timestamp2', # 'category_expanded_count_game_2d', # 'category_expanded_count_book_2d', # 'category_expanded_count_video_game_2d', # ]) # assert_frame_equal(df_new, df_expected) def test_first_column(self): df = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='first_order'), ], ) df_new = first(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, first_order=1000, ), dict( group_id=2, order_id=1050, first_order=1050, ), dict( group_id=1, order_id=1100, first_order=1000, ), dict( group_id=2, order_id=1150, first_order=1050, ), ]) def test_impute(self): from data_cleaner.transformer_actions.column import impute df = pd.DataFrame([ ['2020-01-01', 1000, ' ', 800], ['2020-01-02', '', 1200, 700], ['2020-01-03', 1200, np.NaN, 900], ['2020-01-04', np.NaN, ' ', 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) action1 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'value': '0', }, action_variables={ '0': { 'feature': { 'column_type': 'number', 'uuid': 'sold', }, 'type': 'feature', }, '1': { 'feature': { 'column_type': 'number', 'uuid': 'curr_profit', }, 'type': 'feature', }, }, ) action2 = dict( action_arguments=['sold'], action_options={ 'value': '0', }, action_variables={ '0': { 'feature': { 'column_type': 'number', 'uuid': 'sold', }, 'type': 'feature', }, }, ) action3 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'average', }, ) action4 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'median', }, ) action5 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'column', 'value': 'prev_sold', }, ) action_invalid = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'mode', }, ) df_new1 = impute(df.copy(), action1) df_new2 = impute(df.copy(), action2) df_new3 = impute(df.copy(), action3) df_new4 = impute(df.copy(), action4) df_new5 = impute(df.copy(), action5) df_expected1 = pd.DataFrame([ ['2020-01-01', 1000, 0, 800], ['2020-01-02', 0, 1200, 700], ['2020-01-03', 1200, 0, 900], ['2020-01-04', 0, 0, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected2 = pd.DataFrame([ ['2020-01-01', 1000, ' ', 800], ['2020-01-02', 0, 1200, 700], ['2020-01-03', 1200, np.nan, 900], ['2020-01-04', 0, ' ', 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected3 = pd.DataFrame([ ['2020-01-01', 1000, 1250, 800], ['2020-01-02', 1300, 1200, 700], ['2020-01-03', 1200, 1250, 900], ['2020-01-04', 1300, 1250, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected4 = pd.DataFrame([ ['2020-01-01', 1000, 1250, 800], ['2020-01-02', 1200, 1200, 700], ['2020-01-03', 1200, 1250, 900], ['2020-01-04', 1200, 1250, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected5 = pd.DataFrame([ ['2020-01-01', 1000, 800, 800], ['2020-01-02', 700, 1200, 700], ['2020-01-03', 1200, 900, 900], ['2020-01-04', 700, 700, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_new1['sold'] = df_new1['sold'].astype(int) df_new1['curr_profit'] = df_new1['curr_profit'].astype(int) df_new2['sold'] = df_new2['sold'].astype(int) df_new3['sold'] = df_new3['sold'].astype(int) df_new3['curr_profit'] = df_new3['curr_profit'].astype(int) df_new4['sold'] = df_new4['sold'].astype(int) df_new4['curr_profit'] = df_new4['curr_profit'].astype(int) df_new5['sold'] = df_new5['sold'].astype(int) df_new5['curr_profit'] = df_new5['curr_profit'].astype(int) assert_frame_equal(df_new1, df_expected1) assert_frame_equal(df_new2, df_expected2) assert_frame_equal(df_new3, df_expected3) assert_frame_equal(df_new4, df_expected4) assert_frame_equal(df_new5, df_expected5) with self.assertRaises(Exception): _ = impute(df.copy(), action_invalid) def test_last_column(self): df = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='last_order'), ], ) df_new = last(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, last_order=1100, ), dict( group_id=2, order_id=1050, last_order=1150, ), dict( group_id=1, order_id=1100, last_order=1100, ), dict( group_id=2, order_id=1150, last_order=1150, ), ]) def test_max(self): from data_cleaner.transformer_actions.column import max action = self.__groupby_agg_action('max_amount') df_new = max(TEST_DATAFRAME.copy(), action) df_expected = pd.DataFrame([ [1, 1000, 1100], [2, 1050, 1150], [1, 1100, 1100], [2, 1150, 1150], ], columns=[ 'group_id', 'amount', 'max_amount', ]) assert_frame_equal(df_new, df_expected) action2 = dict( action_arguments=['amount'], action_options=dict(), outputs=[ dict(uuid='max_amount'), ], ) df_new2 = max(TEST_DATAFRAME.copy(), action2) df_expected2 = pd.DataFrame([ [1, 1000, 1150], [2, 1050, 1150], [1, 1100, 1150], [2, 1150, 1150], ], columns=[ 'group_id', 'amount', 'max_amount', ]) assert_frame_equal(df_new2, df_expected2) def test_median(self): from data_cleaner.transformer_actions.column import median action = self.__groupby_agg_action('median_amount') df = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1550], [2, 1150], ], columns=[ 'group_id', 'amount', ]) df_new = median(df, action) df_expected = pd.DataFrame([ [1, 1000, 1050], [2, 1050, 1150], [1, 1100, 1050], [2, 1550, 1150], [2, 1150, 1150], ], columns=[ 'group_id', 'amount', 'median_amount', ]) assert_frame_equal(df_new, df_expected) def test_min(self): from data_cleaner.transformer_actions.column import min action = self.
7,732
218
47,333
mage-ai__mage-ai
9ed779ccaf3538efbe1f2f54dd68f61fb1c3af55
src/data_cleaner/tests/transformer_actions/test_column.py
infile
__groupby_agg_action
true
function
104
108
true
false
[ "__groupby_agg_action", "assertEqual", "test_count", "assertRaises", "test_shift_down", "test_add_column_addition", "test_add_column_addition_days", "test_add_column_constant", "test_add_column_date_trunc", "test_add_column_difference", "test_add_column_difference_days", "test_add_column_distance_between", "test_add_column_divide", "test_add_column_formatted_date", "test_add_column_if_else", "test_add_column_if_else_with_column", "test_add_column_multiply", "test_add_column_string_replace", "test_add_column_string_split", "test_add_column_substring", "test_average", "test_count_distinct", "test_count_with_filter", "test_count_with_time_window", "test_diff", "test_first_column", "test_impute", "test_last_column", "test_max", "test_median", "test_min", "test_remove_column", "test_select", "test_shift_down_with_groupby", "test_shift_up", "test_sum", "setUp", "tearDown", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "countTestCases", "type": "function" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_add_column_addition", "type": "function" }, { "name": "test_add_column_addition_days", "type": "function" }, { "name": "test_add_column_constant", "type": "function" }, { "name": "test_add_column_date_trunc", "type": "function" }, { "name": "test_add_column_difference", "type": "function" }, { "name": "test_add_column_difference_days", "type": "function" }, { "name": "test_add_column_distance_between", "type": "function" }, { "name": "test_add_column_divide", "type": "function" }, { "name": "test_add_column_formatted_date", "type": "function" }, { "name": "test_add_column_if_else", "type": "function" }, { "name": "test_add_column_if_else_with_column", "type": "function" }, { "name": "test_add_column_multiply", "type": "function" }, { "name": "test_add_column_string_replace", "type": "function" }, { "name": "test_add_column_string_split", "type": "function" }, { "name": "test_add_column_substring", "type": "function" }, { "name": "test_average", "type": "function" }, { "name": "test_count", "type": "function" }, { "name": "test_count_distinct", "type": "function" }, { "name": "test_count_with_filter", "type": "function" }, { "name": "test_count_with_time_window", "type": "function" }, { "name": "test_diff", "type": "function" }, { "name": "test_first_column", "type": "function" }, { "name": "test_impute", "type": "function" }, { "name": "test_last_column", "type": "function" }, { "name": "test_max", "type": "function" }, { "name": "test_median", "type": "function" }, { "name": "test_min", "type": "function" }, { "name": "test_remove_column", "type": "function" }, { "name": "test_select", "type": "function" }, { "name": "test_shift_down", "type": "function" }, { "name": "test_shift_down_with_groupby", "type": "function" }, { "name": "test_shift_up", "type": "function" }, { "name": "test_sum", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__groupby_agg_action", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.tests.base_test import TestCase from data_cleaner.transformer_actions.column import ( add_column, count, count_distinct, diff, # expand_column, first, last, remove_column, select, shift_down, shift_up, ) from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd TEST_DATAFRAME = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'amount', ]) class ColumnTests(TestCase): def test_remove_column(self): df = pd.DataFrame([ [0, False, 'a'], [1, True, 'b'], ], columns=[ 'integer', 'boolean', 'string', ]) action = dict(action_arguments=['string']) df_new = remove_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( integer=0, boolean=False, ), dict( integer=1, boolean=True, ), ]) action = dict(action_arguments=['integer', 'boolean']) df_new = remove_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( string='a', ), dict( string='b', ), ]) def test_add_column_addition(self): df = pd.DataFrame([ [1, 3, 7, 9], [4, 2, 9, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', 'integer3', ], action_options={ 'udf': 'addition', 'value': None, }, outputs=[ dict( uuid='integer_addition', column_type='number', ), ], ) action2 = dict( action_arguments=['integer1'], action_options={ 'udf': 'addition', 'value': 10, }, outputs=[ dict( uuid='integer_addition2', column_type='number', ), ], ) action3 = dict( action_arguments=['integer1', 'integer4'], action_options={ 'udf': 'addition', 'value': 10, }, outputs=[ dict( uuid='integer_addition3', column_type='number', ), ], ) df_new = add_column( add_column( add_column(df, action1), action2, ), action3, ) df_expected = pd.DataFrame([ [1, 3, 7, 9, 11, 11, 20], [4, 2, 9, 3, 15, 14, 17], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_addition', 'integer_addition2', 'integer_addition3', ]) assert_frame_equal(df_new, df_expected) def test_add_column_addition_days(self): df = pd.DataFrame([ ['2021-08-31'], ['2021-08-28'], ], columns=[ 'created_at', ]) action = dict( action_arguments=['created_at'], action_options=dict( column_type='datetime', time_unit='d', udf='addition', value=3, ), outputs=[ dict( uuid='3d_after_creation', column_type='text', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['2021-08-31', '2021-09-03 00:00:00'], ['2021-08-28', '2021-08-31 00:00:00'], ], columns=[ 'created_at', '3d_after_creation' ]) assert_frame_equal(df_new, df_expected) def test_add_column_constant(self): df = pd.DataFrame([ [False], [True], ], columns=[ 'boolean', ]) action = dict( action_arguments=[10], action_options=dict( udf='constant', ), outputs=[ dict( uuid='integer', column_type='number', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( boolean=False, integer=10, ), dict( boolean=True, integer=10, ), ]) def test_add_column_date_trunc(self): df = pd.DataFrame([ ['2021-08-31', False], ['2021-08-28', True], ], columns=[ 'created_at', 'boolean', ]) action = dict( action_arguments=['created_at'], action_options=dict( udf='date_trunc', date_part='week', ), outputs=[ dict( uuid='week_date', column_type='text', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( created_at='2021-08-31', boolean=False, week_date='2021-08-30', ), dict( created_at='2021-08-28', boolean=True, week_date='2021-08-23', ), ]) def test_add_column_difference(self): df = pd.DataFrame([ [1, 3], [4, 2], ], columns=[ 'integer1', 'integer2', ]) action1 = dict( action_arguments=['integer1', 'integer2'], action_options={ 'udf': 'difference', }, outputs=[ dict( uuid='integer_difference', column_type='number', ), ], ) action2 = dict( action_arguments=['integer1'], action_options={ 'udf': 'difference', 'value': 10, }, outputs=[ dict( uuid='integer_difference2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [1, 3, -2, -9], [4, 2, 2, -6], ], columns=[ 'integer1', 'integer2', 'integer_difference', 'integer_difference2' ]) assert_frame_equal(df_new, df_expected) def test_add_column_difference_days(self): df = pd.DataFrame([ ['2021-08-31', '2021-09-14'], ['2021-08-28', '2021-09-03'], ], columns=[ 'created_at', 'converted_at', ]) action = dict( action_arguments=['converted_at', 'created_at'], action_options=dict( column_type='datetime', time_unit='d', udf='difference', ), outputs=[ dict( uuid='days_diff', column_type='number', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['2021-08-31', '2021-09-14', 14], ['2021-08-28', '2021-09-03', 6], ], columns=[ 'created_at', 'converted_at', 'days_diff', ]) assert_frame_equal(df_new, df_expected) def test_add_column_distance_between(self): df = pd.DataFrame([ [26.05308, -97.31838, 33.41939, -112.32606], [39.71954, -84.13056, 33.41939, -112.32606], ], columns=[ 'lat1', 'lng1', 'lat2', 'lng2', ]) action = dict( action_arguments=['lat1', 'lng1', 'lat2', 'lng2'], action_options=dict( udf='distance_between', ), outputs=[ dict( uuid='distance', column_type='number_with_decimals', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( lat1=26.05308, lng1=-97.31838, lat2=33.41939, lng2=-112.32606, distance=1661.8978520305657, ), dict( lat1=39.71954, lng1=-84.13056, lat2=33.41939, lng2=-112.32606, distance=2601.5452571116184, ), ]) def test_add_column_divide(self): df = pd.DataFrame([ [12, 3, 70, 9], [4, 2, 90, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', ], action_options={ 'udf': 'divide', }, outputs=[ dict( uuid='integer_divide', column_type='number', ), ], ) action2 = dict( action_arguments=['integer3'], action_options={ 'udf': 'divide', 'value': 10, }, outputs=[ dict( uuid='integer_divide2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [12, 3, 70, 9, 4, 7], [4, 2, 90, 3, 2, 9], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_divide', 'integer_divide2' ]) assert_frame_equal(df_new, df_expected) # def test_add_column_extract_dict_string(self): # df = pd.DataFrame([ # '{\'country\': \'US\', \'age\': \'20\'}', # '{\'country\': \'CA\'}', # '{\'country\': \'UK\', \'age\': \'24\'}', # '', # ], columns=[ # 'properties', # ]) # action = dict( # action_arguments=['properties', 'country'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_country', # column_type='text', # ), # ], # ) # df_new = add_column(df, action) # self.assertEqual(df_new.to_dict(orient='records'), [ # dict( # properties='{\'country\': \'US\', \'age\': \'20\'}', # property_country='US', # ), # dict( # properties='{\'country\': \'CA\'}', # property_country='CA', # ), # dict( # properties='{\'country\': \'UK\', \'age\': \'24\'}', # property_country='UK', # ), # dict( # properties='', # property_country=np.NaN, # ), # ]) # action2 = dict( # action_arguments=['properties', 'age'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_age', # column_type='number', # ), # ], # ) # df_new2 = add_column(df, action2) # self.assertEqual(df_new2.to_dict(orient='records'), [ # dict( # properties='{\'country\': \'US\', \'age\': \'20\'}', # property_age=20, # ), # dict( # properties='{\'country\': \'CA\'}', # property_age=0, # ), # dict( # properties='{\'country\': \'UK\', \'age\': \'24\'}', # property_age=24, # ), # dict( # properties='', # property_age=0, # ), # ]) # def test_add_column_extract_dict_string_with_json(self): # df = pd.DataFrame([ # '{\"country\": \"US\", \"is_adult\": true}', # '{\"country\": \"CA\"}', # '{\"country\": \"UK\", \"is_adult\": false}', # '', # ], columns=[ # 'properties', # ]) # action = dict( # action_arguments=['properties', 'country'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_country', # column_type='text', # ), # ], # ) # df_new = add_column(df, action) # self.assertEqual(df_new.to_dict(orient='records'), [ # dict( # properties='{\"country\": \"US\", \"is_adult\": true}', # property_country='US', # ), # dict( # properties='{\"country\": \"CA\"}', # property_country='CA', # ), # dict( # properties='{\"country\": \"UK\", \"is_adult\": false}', # property_country='UK', # ), # dict( # properties='', # property_country=np.NaN, # ), # ]) # action2 = dict( # action_arguments=['properties', 'is_adult'], # action_options=dict( # udf='extract_dict_value', # ), # outputs=[ # dict( # uuid='property_is_adult', # column_type='true_or_false', # ), # ], # ) # df_new2 = add_column(df, action2) # self.assertEqual(df_new2.to_dict(orient='records'), [ # dict( # properties='{\"country\": \"US\", \"is_adult\": true}', # property_is_adult=True, # ), # dict( # properties='{\"country\": \"CA\"}', # property_is_adult=None, # ), # dict( # properties='{\"country\": \"UK\", \"is_adult\": false}', # property_is_adult=False, # ), # dict( # properties='', # property_is_adult=None, # ), # ]) def test_add_column_formatted_date(self): df = pd.DataFrame([ ['2019-04-10 08:20:58', False], ['2019-03-05 03:30:30', True], ], columns=[ 'created_at', 'boolean', ]) action = dict( action_arguments=['created_at'], action_options=dict( udf='formatted_date', format='%Y-%m-%d', ), outputs=[ dict( uuid='created_date', column_type='text', ), ], ) df_new = add_column(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( created_at='2019-04-10 08:20:58', boolean=False, created_date='2019-04-10', ), dict( created_at='2019-03-05 03:30:30', boolean=True, created_date='2019-03-05', ), ]) def test_add_column_if_else(self): df = pd.DataFrame([ ['2019-04-10 08:20:58'], [None], ], columns=[ 'converted_at' ]) action = dict( action_arguments=[False, True], action_code='converted_at == null', action_options=dict( udf='if_else', ), outputs=[ dict( uuid='converted', column_type='true_or_false', ), ], ) df_new = add_column(df, action, original_df=df) self.assertEqual(df_new.to_dict(orient='records'), [ dict( converted_at='2019-04-10 08:20:58', converted=True, ), dict( converted_at=None, converted=False, ), ]) def test_add_column_if_else_with_column(self): df = pd.DataFrame([ ['2019-04-10 08:20:58', 'test_user_id'], [None, None], ], columns=[ 'converted_at', 'user_id', ]) action = dict( action_arguments=['unknown', 'user_id'], action_code='converted_at == null', action_options=dict( udf='if_else', arg1_type='value', arg2_type='column', ), outputs=[ dict( uuid='user_id_clean', column_type='text', ), ], ) df_new = add_column(df, action, original_df=df) self.assertEqual(df_new.to_dict(orient='records'), [ dict( converted_at='2019-04-10 08:20:58', user_id='test_user_id', user_id_clean='test_user_id', ), dict( converted_at=None, user_id=None, user_id_clean='unknown', ), ]) def test_add_column_multiply(self): df = pd.DataFrame([ [1, 3, 7, 9], [4, 2, 9, 3], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', ]) action1 = dict( action_arguments=[ 'integer1', 'integer2', ], action_options={ 'udf': 'multiply', }, outputs=[ dict( uuid='integer_multiply', column_type='number', ), ], ) action2 = dict( action_arguments=['integer3'], action_options={ 'udf': 'multiply', 'value': 10, }, outputs=[ dict( uuid='integer_multiply2', column_type='number', ), ], ) df_new = add_column(add_column(df, action1), action2) df_expected = pd.DataFrame([ [1, 3, 7, 9, 3, 70], [4, 2, 9, 3, 8, 90], ], columns=[ 'integer1', 'integer2', 'integer3', 'integer4', 'integer_multiply', 'integer_multiply2' ]) assert_frame_equal(df_new, df_expected) def test_add_column_string_replace(self): df = pd.DataFrame([ ['$1000'], ['$321. '], ['$4,321'], ], columns=[ 'amount', ]) action = dict( action_arguments=['amount'], action_options={ 'udf': 'string_replace', 'pattern': '\\$|\\.|\\,|\\s*', 'replacement': '', }, outputs=[ dict( uuid='amount_clean', column_type='true_or_false', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['$1000', '1000'], ['$321. ', '321'], ['$4,321', '4321'], ], columns=[ 'amount', 'amount_clean', ]) assert_frame_equal(df_new, df_expected) def test_add_column_string_split(self): df = pd.DataFrame([ ['Street1, Long Beach, CA, '], ['Street2,Vernon, CA, 123'], ['Pacific Coast Highway, Los Angeles, CA, 111'], ], columns=[ 'location', ]) action = dict( action_arguments=['location'], action_options={ 'udf': 'string_split', 'separator': ',', 'part_index': 1, }, outputs=[ dict( uuid='location_city', column_type='text', ), ], ) action2 = dict( action_arguments=['location'], action_options={ 'udf': 'string_split', 'separator': ',', 'part_index': 3, }, outputs=[ dict( uuid='num', column_type='number', ), ], ) df_new = add_column(add_column(df, action), action2) df_expected = pd.DataFrame([ ['Street1, Long Beach, CA, ', 'Long Beach', 0], ['Street2,Vernon, CA, 123', 'Vernon', 123], ['Pacific Coast Highway, Los Angeles, CA, 111', 'Los Angeles', 111], ], columns=[ 'location', 'location_city', 'num', ]) assert_frame_equal(df_new, df_expected) def test_add_column_substring(self): df = pd.DataFrame([ ['$1000.0'], ['$321.9'], ], columns=[ 'amount', ]) action = dict( action_arguments=['amount'], action_options={ 'udf': 'substring', 'start': 1, 'stop': -2, }, outputs=[ dict( uuid='amount_int', column_type='text', ), ], ) df_new = add_column(df, action) df_expected = pd.DataFrame([ ['$1000.0', '1000'], ['$321.9', '321'], ], columns=[ 'amount', 'amount_int', ]) assert_frame_equal(df_new, df_expected) def test_average(self): from data_cleaner.transformer_actions.column import average action = self.__groupby_agg_action('average_amount') df_new = average(TEST_DATAFRAME.copy(), action) df_expected = pd.DataFrame([ [1, 1000, 1050], [2, 1050, 1100], [1, 1100, 1050], [2, 1150, 1100], ], columns=[ 'group_id', 'amount', 'average_amount' ]) assert_frame_equal(df_new, df_expected) def test_count(self): df = pd.DataFrame([ [1, 1000], [1, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='order_count'), ], ) df_new = count(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, order_count=3, ), dict( group_id=1, order_id=1050, order_count=3, ), dict( group_id=1, order_id=1100, order_count=3, ), dict( group_id=2, order_id=1150, order_count=1, ), ]) def test_count_distinct(self): df = pd.DataFrame([ [1, 1000], [1, 1000], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='order_count'), ], ) df_new = count_distinct(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, order_count=2, ), dict( group_id=1, order_id=1000, order_count=2, ), dict( group_id=1, order_id=1100, order_count=2, ), dict( group_id=2, order_id=1150, order_count=1, ), ]) def test_count_with_time_window(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) action = dict( action_arguments=['order_id'], action_code='', action_options=dict( groupby_columns=['group_id'], timestamp_feature_a='group_churned_at', timestamp_feature_b='order_created_at', window=90*24*3600, ), outputs=[ dict(uuid='order_count'), ], ) df_new = count(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, group_churned_at='2021-10-01', order_created_at='2021-09-01', order_count=2, ), dict( group_id=1, order_id=1050, group_churned_at='2021-10-01', order_created_at='2021-08-01', order_count=2, ), dict( group_id=1, order_id=1100, group_churned_at='2021-10-01', order_created_at='2021-01-01', order_count=2, ), dict( group_id=2, order_id=1150, group_churned_at='2021-09-01', order_created_at='2021-08-01', order_count=1, ), ]) def test_count_with_filter(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], [2, 1200, '2021-09-01', '2021-08-16'], [2, 1250, '2021-09-01', '2021-08-14'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) action = dict( action_arguments=['order_id'], action_code='order_created_at < \'2021-08-15\'', action_options=dict( groupby_columns=['group_id'], ), outputs=[ dict(uuid='order_count'), ], ) df_new = count(df, action) df_expected = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01', 2], [1, 1050, '2021-10-01', '2021-08-01', 2], [1, 1100, '2021-10-01', '2021-01-01', 2], [2, 1150, '2021-09-01', '2021-08-01', 2], [2, 1200, '2021-09-01', '2021-08-16', 2], [2, 1250, '2021-09-01', '2021-08-14', 2], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', 'order_count', ]) assert_frame_equal(df_new, df_expected) def test_diff(self): df = pd.DataFrame([ ['2020-01-01', 1000], ['2020-01-02', 1050], ['2020-01-03', 1200], ['2020-01-04', 990], ], columns=[ 'date', 'sold', ]) action = dict( action_arguments=['sold'], outputs=[ dict(uuid='sold_diff'), ], ) df_new = diff(df, action) self.assertEqual(df_new.to_dict(orient='records')[1:], [ dict( date='2020-01-02', sold=1050, sold_diff=50, ), dict( date='2020-01-03', sold=1200, sold_diff=150, ), dict( date='2020-01-04', sold=990, sold_diff=-210, ), ]) # def test_expand_column(self): # df = pd.DataFrame([ # [1, 'game'], # [1, 'book'], # [1, 'game'], # [2, 'Video Game'], # [1, 'Video Game'], # [2, 'book'], # [1, 'Video Game'], # [2, 'Video Game'], # ], columns=[ # 'group_id', # 'category', # ]) # action = dict( # action_arguments=['category'], # action_options=dict( # groupby_columns=['group_id'] # ), # outputs=[ # dict(uuid='category_expanded_count_game'), # dict(uuid='category_expanded_count_book'), # dict(uuid='category_expanded_count_video_game'), # dict(uuid='category_expanded_count_clothing'), # ], # ) # df_new = expand_column(df, action) # df_expected = pd.DataFrame([ # [1, 'game', 2, 1, 2], # [1, 'book', 2, 1, 2], # [1, 'game', 2, 1, 2], # [2, 'Video Game', 0, 1, 2], # [1, 'Video Game', 2, 1, 2], # [2, 'book', 0, 1, 2], # [1, 'Video Game', 2, 1, 2], # [2, 'Video Game', 0, 1, 2], # ], columns=[ # 'group_id', # 'category', # 'category_expanded_count_game', # 'category_expanded_count_book', # 'category_expanded_count_video_game', # ]) # assert_frame_equal(df_new, df_expected) # def test_expand_column_with_time_window(self): # df = pd.DataFrame([ # [1, 'game', '2021-01-02', '2021-01-04'], # [1, 'book', '2021-01-02', '2021-01-04'], # [1, 'game', '2021-01-03', '2021-01-04'], # [2, 'Video Game', '2021-01-01', '2021-01-03'], # [1, 'Video Game', '2021-01-01', '2021-01-04'], # [2, 'book', '2021-01-02', '2021-01-03'], # [1, 'Video Game', '2021-01-03', '2021-01-04'], # [2, 'Video Game', '2020-12-30', '2021-01-03'], # ], columns=[ # 'group_id', # 'category', # 'timestamp1', # 'timestamp2', # ]) # action = dict( # action_arguments=['category'], # action_options=dict( # groupby_columns=['group_id'], # timestamp_feature_a='timestamp2', # timestamp_feature_b='timestamp1', # window=172800, # ), # outputs=[ # dict(uuid='category_expanded_count_game_2d'), # dict(uuid='category_expanded_count_book_2d'), # dict(uuid='category_expanded_count_video_game_2d'), # dict(uuid='category_expanded_count_clothing_2d'), # ], # ) # df_new = expand_column(df, action) # df_expected = pd.DataFrame([ # [1, 'game', '2021-01-02', '2021-01-04', 2, 1, 1], # [1, 'book', '2021-01-02', '2021-01-04', 2, 1, 1], # [1, 'game', '2021-01-03', '2021-01-04', 2, 1, 1], # [2, 'Video Game', '2021-01-01', '2021-01-03', 0, 1, 1], # [1, 'Video Game', '2021-01-01', '2021-01-04', 2, 1, 1], # [2, 'book', '2021-01-02', '2021-01-03', 0, 1, 1], # [1, 'Video Game', '2021-01-03', '2021-01-04', 2, 1, 1], # [2, 'Video Game', '2020-12-30', '2021-01-03', 0, 1, 1], # ], columns=[ # 'group_id', # 'category', # 'timestamp1', # 'timestamp2', # 'category_expanded_count_game_2d', # 'category_expanded_count_book_2d', # 'category_expanded_count_video_game_2d', # ]) # assert_frame_equal(df_new, df_expected) def test_first_column(self): df = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='first_order'), ], ) df_new = first(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, first_order=1000, ), dict( group_id=2, order_id=1050, first_order=1050, ), dict( group_id=1, order_id=1100, first_order=1000, ), dict( group_id=2, order_id=1150, first_order=1050, ), ]) def test_impute(self): from data_cleaner.transformer_actions.column import impute df = pd.DataFrame([ ['2020-01-01', 1000, ' ', 800], ['2020-01-02', '', 1200, 700], ['2020-01-03', 1200, np.NaN, 900], ['2020-01-04', np.NaN, ' ', 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) action1 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'value': '0', }, action_variables={ '0': { 'feature': { 'column_type': 'number', 'uuid': 'sold', }, 'type': 'feature', }, '1': { 'feature': { 'column_type': 'number', 'uuid': 'curr_profit', }, 'type': 'feature', }, }, ) action2 = dict( action_arguments=['sold'], action_options={ 'value': '0', }, action_variables={ '0': { 'feature': { 'column_type': 'number', 'uuid': 'sold', }, 'type': 'feature', }, }, ) action3 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'average', }, ) action4 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'median', }, ) action5 = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'column', 'value': 'prev_sold', }, ) action_invalid = dict( action_arguments=['sold', 'curr_profit'], action_options={ 'strategy': 'mode', }, ) df_new1 = impute(df.copy(), action1) df_new2 = impute(df.copy(), action2) df_new3 = impute(df.copy(), action3) df_new4 = impute(df.copy(), action4) df_new5 = impute(df.copy(), action5) df_expected1 = pd.DataFrame([ ['2020-01-01', 1000, 0, 800], ['2020-01-02', 0, 1200, 700], ['2020-01-03', 1200, 0, 900], ['2020-01-04', 0, 0, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected2 = pd.DataFrame([ ['2020-01-01', 1000, ' ', 800], ['2020-01-02', 0, 1200, 700], ['2020-01-03', 1200, np.nan, 900], ['2020-01-04', 0, ' ', 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected3 = pd.DataFrame([ ['2020-01-01', 1000, 1250, 800], ['2020-01-02', 1300, 1200, 700], ['2020-01-03', 1200, 1250, 900], ['2020-01-04', 1300, 1250, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected4 = pd.DataFrame([ ['2020-01-01', 1000, 1250, 800], ['2020-01-02', 1200, 1200, 700], ['2020-01-03', 1200, 1250, 900], ['2020-01-04', 1200, 1250, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_expected5 = pd.DataFrame([ ['2020-01-01', 1000, 800, 800], ['2020-01-02', 700, 1200, 700], ['2020-01-03', 1200, 900, 900], ['2020-01-04', 700, 700, 700], ['2020-01-05', 1700, 1300, 800], ], columns=[ 'date', 'sold', 'curr_profit', 'prev_sold', ]) df_new1['sold'] = df_new1['sold'].astype(int) df_new1['curr_profit'] = df_new1['curr_profit'].astype(int) df_new2['sold'] = df_new2['sold'].astype(int) df_new3['sold'] = df_new3['sold'].astype(int) df_new3['curr_profit'] = df_new3['curr_profit'].astype(int) df_new4['sold'] = df_new4['sold'].astype(int) df_new4['curr_profit'] = df_new4['curr_profit'].astype(int) df_new5['sold'] = df_new5['sold'].astype(int) df_new5['curr_profit'] = df_new5['curr_profit'].astype(int) assert_frame_equal(df_new1, df_expected1) assert_frame_equal(df_new2, df_expected2) assert_frame_equal(df_new3, df_expected3) assert_frame_equal(df_new4, df_expected4) assert_frame_equal(df_new5, df_expected5) with self.assertRaises(Exception): _ = impute(df.copy(), action_invalid) def test_last_column(self): df = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1150], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['order_id'], action_options=dict( groupby_columns=['group_id'] ), outputs=[ dict(uuid='last_order'), ], ) df_new = last(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, order_id=1000, last_order=1100, ), dict( group_id=2, order_id=1050, last_order=1150, ), dict( group_id=1, order_id=1100, last_order=1100, ), dict( group_id=2, order_id=1150, last_order=1150, ), ]) def test_max(self): from data_cleaner.transformer_actions.column import max action = self.__groupby_agg_action('max_amount') df_new = max(TEST_DATAFRAME.copy(), action) df_expected = pd.DataFrame([ [1, 1000, 1100], [2, 1050, 1150], [1, 1100, 1100], [2, 1150, 1150], ], columns=[ 'group_id', 'amount', 'max_amount', ]) assert_frame_equal(df_new, df_expected) action2 = dict( action_arguments=['amount'], action_options=dict(), outputs=[ dict(uuid='max_amount'), ], ) df_new2 = max(TEST_DATAFRAME.copy(), action2) df_expected2 = pd.DataFrame([ [1, 1000, 1150], [2, 1050, 1150], [1, 1100, 1150], [2, 1150, 1150], ], columns=[ 'group_id', 'amount', 'max_amount', ]) assert_frame_equal(df_new2, df_expected2) def test_median(self): from data_cleaner.transformer_actions.column import median action = self.__groupby_agg_action('median_amount') df = pd.DataFrame([ [1, 1000], [2, 1050], [1, 1100], [2, 1550], [2, 1150], ], columns=[ 'group_id', 'amount', ]) df_new = median(df, action) df_expected = pd.DataFrame([ [1, 1000, 1050], [2, 1050, 1150], [1, 1100, 1050], [2, 1550, 1150], [2, 1150, 1150], ], columns=[ 'group_id', 'amount', 'median_amount', ]) assert_frame_equal(df_new, df_expected) def test_min(self): from data_cleaner.transformer_actions.column import min action = self.__groupby_agg_action('min_amount') df_new = min(TEST_DATAFRAME.copy(), action) df_expected = pd.DataFrame([ [1, 1000, 1000], [2, 1050, 1050], [1, 1100, 1000], [2, 1150, 1050], ], columns=[ 'group_id', 'amount', 'min_amount', ]) assert_frame_equal(df_new, df_expected) def test_select(self): df = pd.DataFrame([ [1, 1000], [2, 1050], ], columns=[ 'group_id', 'order_id', ]) action = dict( action_arguments=['group_id'] ) df_new = select(df, action) self.assertEqual(df_new.to_dict(orient='records'), [ dict( group_id=1, ), dict( group_id=2, ), ]) def test_shift_down(self): df = pd.DataFrame([ ['2020-01-01', 1000], ['2020-01-02', 1050], ['2020-01-03', 1200], ['2020-01-04', 990], ], columns=[ 'date', 'sold', ]) action = dict( action_arguments=['sold'], outputs=[ dict(uuid='prev_sold'), ], ) df_new = shift_down(df, action) self.assertEqual(df_new.to_dict(orient='records')[1:], [ dict( date='2020-01-02', sold=1050, prev_sold=1000, ), dict( date='2020-01-03', sold=1200, prev_sold=1050, ), dict( date='2020-01-04', sold=990, prev_sold=1200, ), ]) def test_shift_down_with_groupby(self): df = pd.DataFrame([ [1, '2020-01-01', 1000], [1, '2020-01-02', 1050], [2, '2020-01-03', 1200], [1, '2020-01-04', 990], [2, '2020-01-05', 980], [2, '2020-01-06', 970], [2, '2020-01-07', 960], ], columns=[ 'group_id', 'date', 'sold', ]) action = dict( action_arguments=['sold'], action_options=dict( groupby_columns=['group_id'], periods=2, ), outputs=[ dict(uuid='prev_sold'), ], ) df_new = shift_down(df, action) df_expected = pd.DataFrame([ [1, '2020-01-01', 1000, None], [1, '2020-01-02', 1050, None], [2, '2020-01-03', 1200, None], [1, '2020-01-04', 990, 1000], [2, '2020-01-05', 980, None], [2, '2020-01-06', 970, 1200], [2, '2020-01-07', 960, 980], ], columns=[ 'group_id', 'date', 'sold', 'prev_sold', ]) assert_frame_equal(df_new, df_expected) def test_shift_up(self): df = pd.DataFrame([ ['2020-01-01', 1000], ['2020-01-02', 1050], ['2020-01-03', 1200], ['2020-01-04', 990], ], columns=[ 'date', 'sold', ]) action = dict( action_arguments=['sold'], outputs=[ dict(uuid='next_sold'), ], ) df_new = shift_up(df, action) self.assertEqual(df_new.to_dict(orient='records')[:-1], [ dict( date='2020-01-01', sold=1000, next_sold=1050, ), dict( date='2020-01-02', sold=1050, next_sold=1200, ), dict( date='2020-01-03', sold=1200, next_sold=990, ), ]) def test_sum(self): from data_cleaner.transformer_actions.column import sum action = self.
7,733
219
13,763
mage-ai__mage-ai
9ed779ccaf3538efbe1f2f54dd68f61fb1c3af55
src/data_cleaner/tests/transformer_actions/test_row.py
common
execute
true
function
9
9
false
true
[ "action", "action_type", "hydrate_action", "axis", "join", "columns_by_type", "execute", "groupby", "transform", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "action", "type": "statement" }, { "name": "action_type", "type": "property" }, { "name": "axis", "type": "property" }, { "name": "columns_by_type", "type": "statement" }, { "name": "execute", "type": "function" }, { "name": "groupby", "type": "function" }, { "name": "hydrate_action", "type": "function" }, { "name": "join", "type": "function" }, { "name": "transform", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.tests.base_test import TestCase from data_cleaner.transformer_actions.base import BaseAction from data_cleaner.transformer_actions.row import ( drop_duplicates, # explode, filter_rows, sort_rows, ) from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RowTests(TestCase): def test_drop_duplicates(self): df = pd.DataFrame([ [0, False, 'a'], [1, True, 'b'], [1, True, 'c'], [0, True, 'd'], ], columns=[ 'integer', 'boolean', 'string', ]) test_cases = [ (dict(action_arguments=['integer']), df.iloc[[2, 3]]), (dict(action_arguments=['integer'], action_options=dict(keep='first')), df.iloc[[0, 1]]), (dict(action_arguments=['boolean']), df.iloc[[0, 3]]), (dict(action_arguments=['boolean'], action_options=dict(keep='first')), df.iloc[[0, 1]]), (dict(action_arguments=['integer', 'boolean']), df.iloc[[0, 2, 3]]), ] for action, val in test_cases: self.assertTrue(drop_duplicates(df, action).equals(val)) # def test_explode(self): # df = pd.DataFrame([ # ['(a, b, c)'], # ['[b, c, d]'], # [' e, f '], # ], columns=['tags']) # action = dict( # action_arguments=['tags'], # action_options={ # 'separator': ',', # }, # outputs=[ # dict( # uuid='tag', # column_type='text', # ), # ], # ) # df_new = explode(df, action) # df_expected = pd.DataFrame([ # ['a', '(a, b, c)'], # ['b', '(a, b, c)'], # ['c', '(a, b, c)'], # ['b', '[b, c, d]'], # ['c', '[b, c, d]'], # ['d', '[b, c, d]'], # ['e', ' e, f '], # ['f', ' e, f '], # ], columns=['tag', 'tags']) # assert_frame_equal(df_new.reset_index(drop=True), df_expected) def test_filter_rows(self): df = pd.DataFrame([ [0, False, 'a'], [1, True, 'b'], ], columns=[ 'integer', 'boolean', 'string', ]) test_cases = [ ([0, False, 'a'], 'integer == 0'), ([0, False, 'a'], 'string == \'a\''), ([1, True, 'b'], 'boolean == True'), ([1, True, 'b'], 'integer >= 1'), ([1, True, 'b'], 'integer >= 1 and boolean == True'), ([1, True, 'b'], 'integer >= 1 and (boolean == False or string == \'b\')'), ] for val, query in test_cases: self.assertEqual( val, filter_rows(df, dict(action_code=query)).iloc[0].values.tolist(), ) def test_filter_rows_is_null(self): df = pd.DataFrame([ [None, False, 'a'], [2, True, 'b'], [3, False, 'c'], [1, None, 'a'], [2, True, 'b'], [3, '', 'c'], [1, False, None], [2, True, 'b'], [3, False, ''], ], columns=[ 'integer', 'boolean', 'string', ]) integer_rows = filter_rows( df, dict(action_code='integer == null'), original_df=df, ).values.tolist() self.assertEqual(len(integer_rows), 1) self.assertEqual(integer_rows[0][1], False) self.assertEqual(integer_rows[0][2], 'a') boolean_rows = filter_rows( df, dict(action_code='boolean == null'), original_df=df, ).values.tolist() self.assertEqual(len(boolean_rows), 2) self.assertEqual(boolean_rows[0][0], 1.0) self.assertEqual(boolean_rows[0][1], None) self.assertEqual(boolean_rows[0][2], 'a') self.assertEqual(boolean_rows[1][0], 3.0) self.assertEqual(boolean_rows[1][1], '') self.assertEqual(boolean_rows[1][2], 'c') string_rows = filter_rows( df, dict(action_code='string == null'), original_df=df, ).values.tolist() self.assertEqual(len(string_rows), 2) self.assertEqual(string_rows[0][0], 1.0) self.assertEqual(string_rows[0][1], False) self.assertEqual(string_rows[0][2], None) self.assertEqual(string_rows[1][0], 3.0) self.assertEqual(string_rows[1][1], False) self.assertEqual(string_rows[1][2], '') def test_filter_rows_is_not_null(self): df = pd.DataFrame([ [None, False, 'a'], [2, True, 'b'], [3, False, 'c'], [1, None, 'a'], [2, True, 'b'], [3, '', 'c'], [1, False, None], [2, True, 'b'], [3, False, ''], ], columns=[ 'integer', 'boolean', 'string', ]) integer_rows = filter_rows( df, dict(action_code='integer != null'), original_df=df, )['integer'].values.tolist() self.assertEqual(integer_rows, [ 2, 3, 1, 2, 3, 1, 2, 3, ]) boolean_rows = filter_rows( df, dict(action_code='boolean != null'), original_df=df, )['boolean'].values.tolist() self.assertEqual(boolean_rows, [ False, True, False, True, False, True, False, ]) string_rows = filter_rows( df, dict(action_code='string != null'), original_df=df, )['string'].values.tolist() self.assertEqual(string_rows, [ 'a', 'b', 'c', 'a', 'b', 'c', 'b', ]) def test_filter_row_contains_string(self): df = pd.DataFrame([ ['fsdijfosidjfiosfj'], ['[email protected]'], [np.NaN], ['fsdfsdfdsfdsf'], ['[email protected]'], ], columns=[ 'id', ]) action = dict( action_code='id contains @', ) action2 = dict( action_code='id contains \'@\'', ) df_new = filter_rows(df, action, original_df=df).reset_index(drop=True) df_new2 = filter_rows(df, action2, original_df=df).reset_index(drop=True) df_expected = pd.DataFrame([ ['[email protected]'], ['[email protected]'], ], columns=[ 'id', ]) assert_frame_equal(df_new, df_expected) assert_frame_equal(df_new2, df_expected) def test_filter_row_not_contains_string(self): df = pd.DataFrame([ [np.NaN, False], ['[email protected]', True], ['[email protected]', True], ['fsdfsdfdsfdsf', False], ['[email protected]', False], ['eeeeasdf', True] ], columns=[ 'email', 'subscription' ]) action = dict( action_code='email not contains mailnet', ) action2 = dict( action_code='email not contains \'mailnet\'', ) action3 = dict( action_code = 'email not contains @', ) action4 = dict( action_code = 'email not contains \'^e+\w\'', ) action_invalid = dict( action_code='subscription not contains False' ) df_new = filter_rows(df, action, original_df=df).reset_index(drop=True) df_new2 = filter_rows(df, action2, original_df=df).reset_index(drop=True) df_new3 = filter_rows(df, action3, original_df=df).reset_index(drop=True) df_new4 = filter_rows(df, action4, original_df=df).reset_index(drop=True) df_expected1 = pd.DataFrame([ [np.NaN, False], ['[email protected]', True], ['fsdfsdfdsfdsf', False], ['eeeeasdf', True] ], columns=[ 'email', 'subscription' ]) df_expected2 = pd.DataFrame([ [np.NaN, False], ['fsdfsdfdsfdsf', False], ['eeeeasdf', True] ], columns=[ 'email', 'subscription' ]) df_expected3 = pd.DataFrame([ [np.NaN, False], ['[email protected]', True], ['[email protected]', True], ['fsdfsdfdsfdsf', False], ['[email protected]', False] ], columns=[ 'email', 'subscription' ]) assert_frame_equal(df_new, df_expected1) assert_frame_equal(df_new2, df_expected1) assert_frame_equal(df_new3, df_expected2) assert_frame_equal(df_new4, df_expected3) with self.assertRaises(Exception): _ = filter_rows(df, action_invalid, original_df=df).reset_index(drop=True) def test_filter_rows_multi_condition(self): df = pd.DataFrame( [ [100, None, '', 10], [250, 'brand1', False, np.NaN], [np.NaN, 'brand2', None, 18], [50, 'brand1', True, 13], [75, '', '', 80], [None, 'company3', False, 23], ], columns=['value', 'brand', 'discounted', 'inventory'] ) action = dict(action_code='(value < 110 and value >= 50) and (value != null)') action2 = dict(action_code='brand contains brand and inventory != null') action3 = dict(action_code='(brand != null and value > 60) or (discounted == null)') action4 = dict( action_code='(discounted == True and inventory > 15)' ' or (discounted == False and value != null)' ) action5 = dict( action_code='(brand not contains company and value == 75 and inventory <= 80)' ' or (discounted != null)' ) df_expected = pd.DataFrame( [ [100, None, '', 10], [50, 'brand1', True, 13], [75, '', '', 80], ], columns=['value', 'brand', 'discounted', 'inventory'] ) df_expected2 = pd.DataFrame( [ [np.NaN, 'brand2', None, 18], [50, 'brand1', True, 13], ], columns=['value', 'brand', 'discounted', 'inventory'] ) df_expected3 = pd.DataFrame( [ [100, None, '', 10], [250, 'brand1', False, np.NaN], [np.NaN, 'brand2', None, 18], [75, '', '', 80], ], columns=['value', 'brand', 'discounted', 'inventory'] ) df_expected4 = pd.DataFrame( [ [250, 'brand1', False, np.NaN], ], columns=['value', 'brand', 'discounted', 'inventory'] ) df_expected5 = pd.DataFrame( [ [250, 'brand1', False, np.NaN], [50, 'brand1', True, 13], [75, '', '', 80], [None, 'company3', False, 23], ], columns=['value', 'brand', 'discounted', 'inventory'] ) df_new = filter_rows(df, action, original_df=df).reset_index(drop=True) df_new2 = filter_rows(df, action2, original_df=df).reset_index(drop=True) df_new3 = filter_rows(df, action3, original_df=df).reset_index(drop=True) df_new4 = filter_rows(df, action4, original_df=df).reset_index(drop=True) df_new5 = filter_rows(df, action5, original_df=df).reset_index(drop=True) df_new['value'] = df_new['value'].astype(int) df_new['inventory'] = df_new['inventory'].astype(int) df_new2['brand'] = df_new2['brand'].astype(str) df_new2['inventory'] = df_new2['inventory'].astype(int) df_new4['value'] = df_new4['value'].astype(int) df_new4['brand'] = df_new4['brand'].astype(str) df_new4['discounted'] = df_new4['discounted'].astype(bool) assert_frame_equal(df_expected, df_new) assert_frame_equal(df_expected2, df_new2) assert_frame_equal(df_expected3, df_new3) assert_frame_equal(df_expected4, df_new4) assert_frame_equal(df_expected5, df_new5) def test_filter_row_implicit_null(self): # tests that implicit null values in the transformed dataframe are still removed df = pd.DataFrame( [ [100, None, '', 10], [250, 'brand1', False, np.NaN], [np.NaN, 'brand2', None, 18], [50, 'brand1', True, 13], [75, '', '', 80], [None, 'company3', False, 23], ], columns=['value', 'brand', 'discounted', 'inventory'] ) action_payload = { 'action_type': 'filter', 'action_code': '%{1} != null', 'action_arguments': [], 'action_options': {}, 'axis': 'row', 'action_variables': { '1': { 'id': 'value', 'type': 'feature', 'feature': { 'column_type': 'number', 'uuid': 'value' } }, }, 'outputs': [] } action = BaseAction(action_payload) df_new = action.
7,735
220
351
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
commited
setUp
true
function
75
74
false
true
[ "setUp", "assertEqual", "assertAlmostEqual", "fail", "failIf", "tearDown", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDownClass", "_addSkip", "_formatMessage", "_getAssertEqualityFunc", "_testMethodDoc", "_testMethodName", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "countTestCases", "type": "function" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().
7,736
220
1,107
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
evaluate
true
function
14
15
false
true
[ "numeric_columns", "evaluate", "df_columns", "column_types", "numeric_df", "df", "EPSILON", "filter_numeric_types", "get_variance_inflation_factor", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "VIF_UB", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).
7,737
220
1,916
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
evaluate
true
function
14
15
false
false
[ "numeric_columns", "evaluate", "df_columns", "column_types", "numeric_df", "df", "EPSILON", "filter_numeric_types", "get_variance_inflation_factor", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "VIF_UB", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).
7,738
220
2,473
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
inproject
evaluate
true
function
14
15
false
false
[ "numeric_columns", "evaluate", "df_columns", "column_types", "numeric_df", "df", "EPSILON", "filter_numeric_types", "get_variance_inflation_factor", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "VIF_UB", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).
7,739
220
3,533
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
evaluate
true
function
14
15
false
false
[ "evaluate", "numeric_columns", "numeric_df", "get_variance_inflation_factor", "column_types", "df", "df_columns", "EPSILON", "filter_numeric_types", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "VIF_UB", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.
7,740
220
6,861
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
numeric_df
true
statement
14
15
false
true
[ "df", "evaluate", "column_types", "numeric_df", "numeric_columns", "df_columns", "EPSILON", "filter_numeric_types", "get_variance_inflation_factor", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "VIF_UB", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_bad_dtypes(self): df = pd.DataFrame([ [1000, 'US', 30000, '10', 'cute animal #1', 100, '30'], ['500', 'CA', 10000, '20', 'intro to regression', 3000, '20'], [200, '', np.nan, 50, 'daily news #1', None, '75'], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, '20'], ['1000', 'MX', 45003, '20', 'cute animal #4', 90, '40'], [1500, 'MX', 75000, '30', '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, '25'], [None, 'US', 75000, '30', 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, '50', 'cute animal #3', 80, '20'], ['200', 'CA', 5000, '30', '', 10000, '30'], [800, 'US', 12050, '40', 'meme compilation', 2000, '45'], ['600', 'CA', 11000, '50', 'daily news #2', 3000, '50'], [600, 'CA', '', 50, '', 3000, None], ['700', 'MX', 11750, '20', 'cute animal #2', 2750, '55'], [700, '', None, 20, '', None, '55'], [700, 'MX', 11750, '', '', 2750, '55'], [1200, 'MX', 52000, '10', 'vc funding strats', 75, '60'] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.
7,741
220
6,919
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
evaluate
true
function
14
15
false
false
[ "evaluate", "numeric_df", "numeric_columns", "get_variance_inflation_factor", "df", "column_types", "df_columns", "EPSILON", "filter_numeric_types", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "VIF_UB", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_bad_dtypes(self): df = pd.DataFrame([ [1000, 'US', 30000, '10', 'cute animal #1', 100, '30'], ['500', 'CA', 10000, '20', 'intro to regression', 3000, '20'], [200, '', np.nan, 50, 'daily news #1', None, '75'], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, '20'], ['1000', 'MX', 45003, '20', 'cute animal #4', 90, '40'], [1500, 'MX', 75000, '30', '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, '25'], [None, 'US', 75000, '30', 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, '50', 'cute animal #3', 80, '20'], ['200', 'CA', 5000, '30', '', 10000, '30'], [800, 'US', 12050, '40', 'meme compilation', 2000, '45'], ['600', 'CA', 11000, '50', 'daily news #2', 3000, '50'], [600, 'CA', '', 50, '', 3000, None], ['700', 'MX', 11750, '20', 'cute animal #2', 2750, '55'], [700, '', None, 20, '', None, '55'], [700, 'MX', 11750, '', '', 2750, '55'], [1200, 'MX', 52000, '10', 'vc funding strats', 75, '60'] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.
7,742
220
9,708
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
numeric_df
true
statement
14
15
false
false
[ "df", "evaluate", "column_types", "numeric_df", "numeric_columns", "df_columns", "EPSILON", "filter_numeric_types", "get_variance_inflation_factor", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "VIF_UB", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_bad_dtypes(self): df = pd.DataFrame([ [1000, 'US', 30000, '10', 'cute animal #1', 100, '30'], ['500', 'CA', 10000, '20', 'intro to regression', 3000, '20'], [200, '', np.nan, 50, 'daily news #1', None, '75'], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, '20'], ['1000', 'MX', 45003, '20', 'cute animal #4', 90, '40'], [1500, 'MX', 75000, '30', '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, '25'], [None, 'US', 75000, '30', 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, '50', 'cute animal #3', 80, '20'], ['200', 'CA', 5000, '30', '', 10000, '30'], [800, 'US', 12050, '40', 'meme compilation', 2000, '45'], ['600', 'CA', 11000, '50', 'daily news #2', 3000, '50'], [600, 'CA', '', 50, '', 3000, None], ['700', 'MX', 11750, '20', 'cute animal #2', 2750, '55'], [700, '', None, 20, '', None, '55'], [700, 'MX', 11750, '', '', 2750, '55'], [1200, 'MX', 52000, '10', 'vc funding strats', 75, '60'] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_dirty(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [200, np.nan, 50, None, 75], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1500, 75000, np.nan, 70, 25], [None, 75000, 30, 70, np.nan], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [600, '', 50, 3000, None], [700, 11750, 20, 2750, 55], [700, None, 20, None, 55], [700, 11750, '', 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.
7,743
220
9,766
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
inproject
evaluate
true
function
14
15
false
false
[ "evaluate", "numeric_df", "numeric_columns", "get_variance_inflation_factor", "df", "column_types", "df_columns", "EPSILON", "filter_numeric_types", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "VIF_UB", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_bad_dtypes(self): df = pd.DataFrame([ [1000, 'US', 30000, '10', 'cute animal #1', 100, '30'], ['500', 'CA', 10000, '20', 'intro to regression', 3000, '20'], [200, '', np.nan, 50, 'daily news #1', None, '75'], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, '20'], ['1000', 'MX', 45003, '20', 'cute animal #4', 90, '40'], [1500, 'MX', 75000, '30', '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, '25'], [None, 'US', 75000, '30', 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, '50', 'cute animal #3', 80, '20'], ['200', 'CA', 5000, '30', '', 10000, '30'], [800, 'US', 12050, '40', 'meme compilation', 2000, '45'], ['600', 'CA', 11000, '50', 'daily news #2', 3000, '50'], [600, 'CA', '', 50, '', 3000, None], ['700', 'MX', 11750, '20', 'cute animal #2', 2750, '55'], [700, '', None, 20, '', None, '55'], [700, 'MX', 11750, '', '', 2750, '55'], [1200, 'MX', 52000, '10', 'vc funding strats', 75, '60'] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_dirty(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [200, np.nan, 50, None, 75], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1500, 75000, np.nan, 70, 25], [None, 75000, 30, 70, np.nan], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [600, '', 50, 3000, None], [700, 11750, 20, 2750, 55], [700, None, 20, None, 55], [700, 11750, '', 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.
7,744
220
13,035
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
numeric_df
true
statement
14
15
false
false
[ "numeric_df", "df", "evaluate", "column_types", "numeric_columns", "df_columns", "EPSILON", "filter_numeric_types", "get_variance_inflation_factor", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "VIF_UB", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_bad_dtypes(self): df = pd.DataFrame([ [1000, 'US', 30000, '10', 'cute animal #1', 100, '30'], ['500', 'CA', 10000, '20', 'intro to regression', 3000, '20'], [200, '', np.nan, 50, 'daily news #1', None, '75'], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, '20'], ['1000', 'MX', 45003, '20', 'cute animal #4', 90, '40'], [1500, 'MX', 75000, '30', '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, '25'], [None, 'US', 75000, '30', 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, '50', 'cute animal #3', 80, '20'], ['200', 'CA', 5000, '30', '', 10000, '30'], [800, 'US', 12050, '40', 'meme compilation', 2000, '45'], ['600', 'CA', 11000, '50', 'daily news #2', 3000, '50'], [600, 'CA', '', 50, '', 3000, None], ['700', 'MX', 11750, '20', 'cute animal #2', 2750, '55'], [700, '', None, 20, '', None, '55'], [700, 'MX', 11750, '', '', 2750, '55'], [1200, 'MX', 52000, '10', 'vc funding strats', 75, '60'] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_dirty(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [200, np.nan, 50, None, 75], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1500, 75000, np.nan, 70, 25], [None, 75000, 30, 70, np.nan], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [600, '', 50, 3000, None], [700, 11750, 20, 2750, 55], [700, None, 20, None, 55], [700, 11750, '', 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_non_numeric(self): df = pd.DataFrame([ [1000, 'US', 30000, 10, 'cute animal #1', 100, 30], [500, 'CA', 10000, 20, 'intro to regression', 3000, 20], [200, '', np.nan, 50, 'daily news #1', None, 75], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, 20], [1000, 'MX', 45003, 20, 'cute animal #4', 90, 40], [1500, 'MX', 75000, 30, '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, 25], [None, 'US', 75000, 30, 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, 50, 'cute animal #3', 80, 20], [200, 'CA', 5000, 30, '', 10000, 30], [800, 'US', 12050, 40, 'meme compilation', 2000, 45], [600, 'CA', 11000, 50, 'daily news #2', 3000, 50], [600, 'CA', '', 50, '', 3000, None], [700, 'MX', 11750, 20, 'cute animal #2', 2750, 55], [700, '', None, 20, '', None, 55], [700, 'MX', 11750, '', '', 2750, 55], [1200, 'MX', 52000, 10, 'vc funding strats', 75, 60] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.
7,745
220
13,093
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
evaluate
true
function
14
15
false
false
[ "evaluate", "numeric_df", "numeric_columns", "get_variance_inflation_factor", "df", "column_types", "df_columns", "EPSILON", "filter_numeric_types", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "VIF_UB", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_bad_dtypes(self): df = pd.DataFrame([ [1000, 'US', 30000, '10', 'cute animal #1', 100, '30'], ['500', 'CA', 10000, '20', 'intro to regression', 3000, '20'], [200, '', np.nan, 50, 'daily news #1', None, '75'], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, '20'], ['1000', 'MX', 45003, '20', 'cute animal #4', 90, '40'], [1500, 'MX', 75000, '30', '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, '25'], [None, 'US', 75000, '30', 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, '50', 'cute animal #3', 80, '20'], ['200', 'CA', 5000, '30', '', 10000, '30'], [800, 'US', 12050, '40', 'meme compilation', 2000, '45'], ['600', 'CA', 11000, '50', 'daily news #2', 3000, '50'], [600, 'CA', '', 50, '', 3000, None], ['700', 'MX', 11750, '20', 'cute animal #2', 2750, '55'], [700, '', None, 20, '', None, '55'], [700, 'MX', 11750, '', '', 2750, '55'], [1200, 'MX', 52000, '10', 'vc funding strats', 75, '60'] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_dirty(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [200, np.nan, 50, None, 75], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1500, 75000, np.nan, 70, 25], [None, 75000, 30, 70, np.nan], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [600, '', 50, 3000, None], [700, 11750, 20, 2750, 55], [700, None, 20, None, 55], [700, 11750, '', 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_non_numeric(self): df = pd.DataFrame([ [1000, 'US', 30000, 10, 'cute animal #1', 100, 30], [500, 'CA', 10000, 20, 'intro to regression', 3000, 20], [200, '', np.nan, 50, 'daily news #1', None, 75], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, 20], [1000, 'MX', 45003, 20, 'cute animal #4', 90, 40], [1500, 'MX', 75000, 30, '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, 25], [None, 'US', 75000, 30, 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, 50, 'cute animal #3', 80, 20], [200, 'CA', 5000, 30, '', 10000, 30], [800, 'US', 12050, 40, 'meme compilation', 2000, 45], [600, 'CA', 11000, 50, 'daily news #2', 3000, 50], [600, 'CA', '', 50, '', 3000, None], [700, 'MX', 11750, 20, 'cute animal #2', 2750, 55], [700, '', None, 20, '', None, 55], [700, 'MX', 11750, '', '', 2750, 55], [1200, 'MX', 52000, 10, 'vc funding strats', 75, 60] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.
7,746
220
14,004
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
rng
true
statement
80
84
false
true
[ "test_evaluate", "rng", "setUp", "test_collinear_no_results", "test_evaluate_dirty", "test_categorical_data_frame", "test_clean_removes_all_data_frame", "test_evaluate_bad_dtypes", "test_evaluate_non_numeric", "test_perfectly_collinear", "test_vif_calcuation", "tearDown", "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNoLogs", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "countTestCases", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "longMessage", "maxDiff", "run", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDownClass", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "addClassCleanup", "type": "function" }, { "name": "addCleanup", "type": "function" }, { "name": "addTypeEqualityFunc", "type": "function" }, { "name": "assert_", "type": "function" }, { "name": "assertAlmostEqual", "type": "function" }, { "name": "assertAlmostEquals", "type": "function" }, { "name": "assertCountEqual", "type": "function" }, { "name": "assertDictContainsSubset", "type": "function" }, { "name": "assertDictEqual", "type": "function" }, { "name": "assertEqual", "type": "function" }, { "name": "assertEquals", "type": "function" }, { "name": "assertFalse", "type": "function" }, { "name": "assertGreater", "type": "function" }, { "name": "assertGreaterEqual", "type": "function" }, { "name": "assertIn", "type": "function" }, { "name": "assertIs", "type": "function" }, { "name": "assertIsInstance", "type": "function" }, { "name": "assertIsNone", "type": "function" }, { "name": "assertIsNot", "type": "function" }, { "name": "assertIsNotNone", "type": "function" }, { "name": "assertLess", "type": "function" }, { "name": "assertLessEqual", "type": "function" }, { "name": "assertListEqual", "type": "function" }, { "name": "assertLogs", "type": "function" }, { "name": "assertMultiLineEqual", "type": "function" }, { "name": "assertNotAlmostEqual", "type": "function" }, { "name": "assertNotAlmostEquals", "type": "function" }, { "name": "assertNotEqual", "type": "function" }, { "name": "assertNotEquals", "type": "function" }, { "name": "assertNotIn", "type": "function" }, { "name": "assertNotIsInstance", "type": "function" }, { "name": "assertNotRegex", "type": "function" }, { "name": "assertNotRegexpMatches", "type": "function" }, { "name": "assertRaises", "type": "function" }, { "name": "assertRaisesRegex", "type": "function" }, { "name": "assertRaisesRegexp", "type": "function" }, { "name": "assertRegex", "type": "function" }, { "name": "assertRegexpMatches", "type": "function" }, { "name": "assertSequenceEqual", "type": "function" }, { "name": "assertSetEqual", "type": "function" }, { "name": "assertTrue", "type": "function" }, { "name": "assertTupleEqual", "type": "function" }, { "name": "assertWarns", "type": "function" }, { "name": "assertWarnsRegex", "type": "function" }, { "name": "countTestCases", "type": "function" }, { "name": "debug", "type": "function" }, { "name": "defaultTestResult", "type": "function" }, { "name": "doClassCleanups", "type": "function" }, { "name": "doCleanups", "type": "function" }, { "name": "fail", "type": "function" }, { "name": "failIf", "type": "function" }, { "name": "failIfAlmostEqual", "type": "function" }, { "name": "failIfEqual", "type": "function" }, { "name": "failUnless", "type": "function" }, { "name": "failUnlessAlmostEqual", "type": "function" }, { "name": "failUnlessEqual", "type": "function" }, { "name": "failUnlessRaises", "type": "function" }, { "name": "failureException", "type": "statement" }, { "name": "id", "type": "function" }, { "name": "longMessage", "type": "statement" }, { "name": "maxDiff", "type": "statement" }, { "name": "rng", "type": "statement" }, { "name": "run", "type": "function" }, { "name": "setUp", "type": "function" }, { "name": "setUpClass", "type": "function" }, { "name": "shortDescription", "type": "function" }, { "name": "skipTest", "type": "function" }, { "name": "subTest", "type": "function" }, { "name": "tearDown", "type": "function" }, { "name": "tearDownClass", "type": "function" }, { "name": "test_categorical_data_frame", "type": "function" }, { "name": "test_clean_removes_all_data_frame", "type": "function" }, { "name": "test_collinear_no_results", "type": "function" }, { "name": "test_evaluate", "type": "function" }, { "name": "test_evaluate_bad_dtypes", "type": "function" }, { "name": "test_evaluate_dirty", "type": "function" }, { "name": "test_evaluate_non_numeric", "type": "function" }, { "name": "test_perfectly_collinear", "type": "function" }, { "name": "test_vif_calcuation", "type": "function" }, { "name": "_addSkip", "type": "function" }, { "name": "_formatMessage", "type": "function" }, { "name": "_getAssertEqualityFunc", "type": "function" }, { "name": "_testMethodDoc", "type": "statement" }, { "name": "_testMethodName", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_bad_dtypes(self): df = pd.DataFrame([ [1000, 'US', 30000, '10', 'cute animal #1', 100, '30'], ['500', 'CA', 10000, '20', 'intro to regression', 3000, '20'], [200, '', np.nan, 50, 'daily news #1', None, '75'], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, '20'], ['1000', 'MX', 45003, '20', 'cute animal #4', 90, '40'], [1500, 'MX', 75000, '30', '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, '25'], [None, 'US', 75000, '30', 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, '50', 'cute animal #3', 80, '20'], ['200', 'CA', 5000, '30', '', 10000, '30'], [800, 'US', 12050, '40', 'meme compilation', 2000, '45'], ['600', 'CA', 11000, '50', 'daily news #2', 3000, '50'], [600, 'CA', '', 50, '', 3000, None], ['700', 'MX', 11750, '20', 'cute animal #2', 2750, '55'], [700, '', None, 20, '', None, '55'], [700, 'MX', 11750, '', '', 2750, '55'], [1200, 'MX', 52000, '10', 'vc funding strats', 75, '60'] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_dirty(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [200, np.nan, 50, None, 75], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1500, 75000, np.nan, 70, 25], [None, 75000, 30, 70, np.nan], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [600, '', 50, 3000, None], [700, 11750, 20, 2750, 55], [700, None, 20, None, 55], [700, 11750, '', 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_non_numeric(self): df = pd.DataFrame([ [1000, 'US', 30000, 10, 'cute animal #1', 100, 30], [500, 'CA', 10000, 20, 'intro to regression', 3000, 20], [200, '', np.nan, 50, 'daily news #1', None, 75], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, 20], [1000, 'MX', 45003, 20, 'cute animal #4', 90, 40], [1500, 'MX', 75000, 30, '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, 25], [None, 'US', 75000, 30, 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, 50, 'cute animal #3', 80, 20], [200, 'CA', 5000, 30, '', 10000, 30], [800, 'US', 12050, 40, 'meme compilation', 2000, 45], [600, 'CA', 11000, 50, 'daily news #2', 3000, 50], [600, 'CA', '', 50, '', 3000, None], [700, 'MX', 11750, 20, 'cute animal #2', 2750, 55], [700, '', None, 20, '', None, 55], [700, 'MX', 11750, '', '', 2750, 55], [1200, 'MX', 52000, 10, 'vc funding strats', 75, 60] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_perfectly_collinear(self): number_of_users = self.
7,747
220
14,619
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
evaluate
true
function
14
15
false
false
[ "numeric_columns", "evaluate", "df_columns", "column_types", "numeric_df", "df", "EPSILON", "filter_numeric_types", "get_variance_inflation_factor", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "VIF_UB", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_bad_dtypes(self): df = pd.DataFrame([ [1000, 'US', 30000, '10', 'cute animal #1', 100, '30'], ['500', 'CA', 10000, '20', 'intro to regression', 3000, '20'], [200, '', np.nan, 50, 'daily news #1', None, '75'], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, '20'], ['1000', 'MX', 45003, '20', 'cute animal #4', 90, '40'], [1500, 'MX', 75000, '30', '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, '25'], [None, 'US', 75000, '30', 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, '50', 'cute animal #3', 80, '20'], ['200', 'CA', 5000, '30', '', 10000, '30'], [800, 'US', 12050, '40', 'meme compilation', 2000, '45'], ['600', 'CA', 11000, '50', 'daily news #2', 3000, '50'], [600, 'CA', '', 50, '', 3000, None], ['700', 'MX', 11750, '20', 'cute animal #2', 2750, '55'], [700, '', None, 20, '', None, '55'], [700, 'MX', 11750, '', '', 2750, '55'], [1200, 'MX', 52000, '10', 'vc funding strats', 75, '60'] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_dirty(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [200, np.nan, 50, None, 75], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1500, 75000, np.nan, 70, 25], [None, 75000, 30, 70, np.nan], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [600, '', 50, 3000, None], [700, 11750, 20, 2750, 55], [700, None, 20, None, 55], [700, 11750, '', 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_non_numeric(self): df = pd.DataFrame([ [1000, 'US', 30000, 10, 'cute animal #1', 100, 30], [500, 'CA', 10000, 20, 'intro to regression', 3000, 20], [200, '', np.nan, 50, 'daily news #1', None, 75], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, 20], [1000, 'MX', 45003, 20, 'cute animal #4', 90, 40], [1500, 'MX', 75000, 30, '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, 25], [None, 'US', 75000, 30, 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, 50, 'cute animal #3', 80, 20], [200, 'CA', 5000, 30, '', 10000, 30], [800, 'US', 12050, 40, 'meme compilation', 2000, 45], [600, 'CA', 11000, 50, 'daily news #2', 3000, 50], [600, 'CA', '', 50, '', 3000, None], [700, 'MX', 11750, 20, 'cute animal #2', 2750, 55], [700, '', None, 20, '', None, 55], [700, 'MX', 11750, '', '', 2750, 55], [1200, 'MX', 52000, 10, 'vc funding strats', 75, 60] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_perfectly_collinear(self): number_of_users = self.rng.integers(1000, 500000, (10000)) views = number_of_users * 300 revenue = 2 * views - number_of_users losses = revenue / views + number_of_users df = pd.DataFrame({ 'number_of_users':number_of_users, 'views': views, 'revenue': revenue, 'losses': losses }) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).
7,748
220
16,938
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
numeric_columns
true
statement
14
15
false
true
[ "numeric_columns", "numeric_df", "evaluate", "VIF_UB", "column_types", "df", "df_columns", "EPSILON", "filter_numeric_types", "get_variance_inflation_factor", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_bad_dtypes(self): df = pd.DataFrame([ [1000, 'US', 30000, '10', 'cute animal #1', 100, '30'], ['500', 'CA', 10000, '20', 'intro to regression', 3000, '20'], [200, '', np.nan, 50, 'daily news #1', None, '75'], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, '20'], ['1000', 'MX', 45003, '20', 'cute animal #4', 90, '40'], [1500, 'MX', 75000, '30', '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, '25'], [None, 'US', 75000, '30', 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, '50', 'cute animal #3', 80, '20'], ['200', 'CA', 5000, '30', '', 10000, '30'], [800, 'US', 12050, '40', 'meme compilation', 2000, '45'], ['600', 'CA', 11000, '50', 'daily news #2', 3000, '50'], [600, 'CA', '', 50, '', 3000, None], ['700', 'MX', 11750, '20', 'cute animal #2', 2750, '55'], [700, '', None, 20, '', None, '55'], [700, 'MX', 11750, '', '', 2750, '55'], [1200, 'MX', 52000, '10', 'vc funding strats', 75, '60'] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_dirty(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [200, np.nan, 50, None, 75], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1500, 75000, np.nan, 70, 25], [None, 75000, 30, 70, np.nan], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [600, '', 50, 3000, None], [700, 11750, 20, 2750, 55], [700, None, 20, None, 55], [700, 11750, '', 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_non_numeric(self): df = pd.DataFrame([ [1000, 'US', 30000, 10, 'cute animal #1', 100, 30], [500, 'CA', 10000, 20, 'intro to regression', 3000, 20], [200, '', np.nan, 50, 'daily news #1', None, 75], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, 20], [1000, 'MX', 45003, 20, 'cute animal #4', 90, 40], [1500, 'MX', 75000, 30, '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, 25], [None, 'US', 75000, 30, 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, 50, 'cute animal #3', 80, 20], [200, 'CA', 5000, 30, '', 10000, 30], [800, 'US', 12050, 40, 'meme compilation', 2000, 45], [600, 'CA', 11000, 50, 'daily news #2', 3000, 50], [600, 'CA', '', 50, '', 3000, None], [700, 'MX', 11750, 20, 'cute animal #2', 2750, 55], [700, '', None, 20, '', None, 55], [700, 'MX', 11750, '', '', 2750, 55], [1200, 'MX', 52000, 10, 'vc funding strats', 75, 60] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_perfectly_collinear(self): number_of_users = self.rng.integers(1000, 500000, (10000)) views = number_of_users * 300 revenue = 2 * views - number_of_users losses = revenue / views + number_of_users df = pd.DataFrame({ 'number_of_users':number_of_users, 'views': views, 'revenue': revenue, 'losses': losses }) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset:' ' [\'number_of_users\', \'views\', \'revenue\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users', 'views', 'revenue'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(result, expected_results) def test_vif_calcuation(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) expected_vifs_no_remove = ( 59.32817701051733, 26.10502642724925, 5.6541251174451315, 2.6033835916281176, 10.735934980453335 ) expected_vifs_remove = ( 59.32817701051733, 2.941751614824833, 3.4216357503903243, 1.370441833599666 ) for column, expected_vif in zip(rule.
7,749
220
17,004
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
get_variance_inflation_factor
true
function
14
15
false
true
[ "evaluate", "numeric_columns", "numeric_df", "VIF_UB", "get_variance_inflation_factor", "column_types", "df", "df_columns", "EPSILON", "filter_numeric_types", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_bad_dtypes(self): df = pd.DataFrame([ [1000, 'US', 30000, '10', 'cute animal #1', 100, '30'], ['500', 'CA', 10000, '20', 'intro to regression', 3000, '20'], [200, '', np.nan, 50, 'daily news #1', None, '75'], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, '20'], ['1000', 'MX', 45003, '20', 'cute animal #4', 90, '40'], [1500, 'MX', 75000, '30', '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, '25'], [None, 'US', 75000, '30', 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, '50', 'cute animal #3', 80, '20'], ['200', 'CA', 5000, '30', '', 10000, '30'], [800, 'US', 12050, '40', 'meme compilation', 2000, '45'], ['600', 'CA', 11000, '50', 'daily news #2', 3000, '50'], [600, 'CA', '', 50, '', 3000, None], ['700', 'MX', 11750, '20', 'cute animal #2', 2750, '55'], [700, '', None, 20, '', None, '55'], [700, 'MX', 11750, '', '', 2750, '55'], [1200, 'MX', 52000, '10', 'vc funding strats', 75, '60'] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_dirty(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [200, np.nan, 50, None, 75], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1500, 75000, np.nan, 70, 25], [None, 75000, 30, 70, np.nan], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [600, '', 50, 3000, None], [700, 11750, 20, 2750, 55], [700, None, 20, None, 55], [700, 11750, '', 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_non_numeric(self): df = pd.DataFrame([ [1000, 'US', 30000, 10, 'cute animal #1', 100, 30], [500, 'CA', 10000, 20, 'intro to regression', 3000, 20], [200, '', np.nan, 50, 'daily news #1', None, 75], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, 20], [1000, 'MX', 45003, 20, 'cute animal #4', 90, 40], [1500, 'MX', 75000, 30, '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, 25], [None, 'US', 75000, 30, 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, 50, 'cute animal #3', 80, 20], [200, 'CA', 5000, 30, '', 10000, 30], [800, 'US', 12050, 40, 'meme compilation', 2000, 45], [600, 'CA', 11000, 50, 'daily news #2', 3000, 50], [600, 'CA', '', 50, '', 3000, None], [700, 'MX', 11750, 20, 'cute animal #2', 2750, 55], [700, '', None, 20, '', None, 55], [700, 'MX', 11750, '', '', 2750, 55], [1200, 'MX', 52000, 10, 'vc funding strats', 75, 60] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_perfectly_collinear(self): number_of_users = self.rng.integers(1000, 500000, (10000)) views = number_of_users * 300 revenue = 2 * views - number_of_users losses = revenue / views + number_of_users df = pd.DataFrame({ 'number_of_users':number_of_users, 'views': views, 'revenue': revenue, 'losses': losses }) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset:' ' [\'number_of_users\', \'views\', \'revenue\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users', 'views', 'revenue'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(result, expected_results) def test_vif_calcuation(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) expected_vifs_no_remove = ( 59.32817701051733, 26.10502642724925, 5.6541251174451315, 2.6033835916281176, 10.735934980453335 ) expected_vifs_remove = ( 59.32817701051733, 2.941751614824833, 3.4216357503903243, 1.370441833599666 ) for column, expected_vif in zip(rule.numeric_columns, expected_vifs_no_remove): vif = rule.
7,750
220
17,141
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
numeric_columns
true
statement
14
15
false
false
[ "numeric_columns", "numeric_df", "evaluate", "VIF_UB", "column_types", "df", "df_columns", "EPSILON", "filter_numeric_types", "get_variance_inflation_factor", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_bad_dtypes(self): df = pd.DataFrame([ [1000, 'US', 30000, '10', 'cute animal #1', 100, '30'], ['500', 'CA', 10000, '20', 'intro to regression', 3000, '20'], [200, '', np.nan, 50, 'daily news #1', None, '75'], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, '20'], ['1000', 'MX', 45003, '20', 'cute animal #4', 90, '40'], [1500, 'MX', 75000, '30', '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, '25'], [None, 'US', 75000, '30', 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, '50', 'cute animal #3', 80, '20'], ['200', 'CA', 5000, '30', '', 10000, '30'], [800, 'US', 12050, '40', 'meme compilation', 2000, '45'], ['600', 'CA', 11000, '50', 'daily news #2', 3000, '50'], [600, 'CA', '', 50, '', 3000, None], ['700', 'MX', 11750, '20', 'cute animal #2', 2750, '55'], [700, '', None, 20, '', None, '55'], [700, 'MX', 11750, '', '', 2750, '55'], [1200, 'MX', 52000, '10', 'vc funding strats', 75, '60'] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_dirty(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [200, np.nan, 50, None, 75], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1500, 75000, np.nan, 70, 25], [None, 75000, 30, 70, np.nan], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [600, '', 50, 3000, None], [700, 11750, 20, 2750, 55], [700, None, 20, None, 55], [700, 11750, '', 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_non_numeric(self): df = pd.DataFrame([ [1000, 'US', 30000, 10, 'cute animal #1', 100, 30], [500, 'CA', 10000, 20, 'intro to regression', 3000, 20], [200, '', np.nan, 50, 'daily news #1', None, 75], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, 20], [1000, 'MX', 45003, 20, 'cute animal #4', 90, 40], [1500, 'MX', 75000, 30, '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, 25], [None, 'US', 75000, 30, 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, 50, 'cute animal #3', 80, 20], [200, 'CA', 5000, 30, '', 10000, 30], [800, 'US', 12050, 40, 'meme compilation', 2000, 45], [600, 'CA', 11000, 50, 'daily news #2', 3000, 50], [600, 'CA', '', 50, '', 3000, None], [700, 'MX', 11750, 20, 'cute animal #2', 2750, 55], [700, '', None, 20, '', None, 55], [700, 'MX', 11750, '', '', 2750, 55], [1200, 'MX', 52000, 10, 'vc funding strats', 75, 60] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_perfectly_collinear(self): number_of_users = self.rng.integers(1000, 500000, (10000)) views = number_of_users * 300 revenue = 2 * views - number_of_users losses = revenue / views + number_of_users df = pd.DataFrame({ 'number_of_users':number_of_users, 'views': views, 'revenue': revenue, 'losses': losses }) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset:' ' [\'number_of_users\', \'views\', \'revenue\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users', 'views', 'revenue'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(result, expected_results) def test_vif_calcuation(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) expected_vifs_no_remove = ( 59.32817701051733, 26.10502642724925, 5.6541251174451315, 2.6033835916281176, 10.735934980453335 ) expected_vifs_remove = ( 59.32817701051733, 2.941751614824833, 3.4216357503903243, 1.370441833599666 ) for column, expected_vif in zip(rule.numeric_columns, expected_vifs_no_remove): vif = rule.get_variance_inflation_factor(column) self.assertAlmostEqual(vif, expected_vif) for column, expected_vif in zip(rule.
7,751
220
17,209
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
Unknown
get_variance_inflation_factor
true
function
14
15
false
false
[ "evaluate", "numeric_columns", "numeric_df", "VIF_UB", "get_variance_inflation_factor", "column_types", "df", "df_columns", "EPSILON", "filter_numeric_types", "MIN_ENTRIES", "numeric_indices", "ROW_SAMPLE_SIZE", "statistics", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_bad_dtypes(self): df = pd.DataFrame([ [1000, 'US', 30000, '10', 'cute animal #1', 100, '30'], ['500', 'CA', 10000, '20', 'intro to regression', 3000, '20'], [200, '', np.nan, 50, 'daily news #1', None, '75'], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, '20'], ['1000', 'MX', 45003, '20', 'cute animal #4', 90, '40'], [1500, 'MX', 75000, '30', '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, '25'], [None, 'US', 75000, '30', 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, '50', 'cute animal #3', 80, '20'], ['200', 'CA', 5000, '30', '', 10000, '30'], [800, 'US', 12050, '40', 'meme compilation', 2000, '45'], ['600', 'CA', 11000, '50', 'daily news #2', 3000, '50'], [600, 'CA', '', 50, '', 3000, None], ['700', 'MX', 11750, '20', 'cute animal #2', 2750, '55'], [700, '', None, 20, '', None, '55'], [700, 'MX', 11750, '', '', 2750, '55'], [1200, 'MX', 52000, '10', 'vc funding strats', 75, '60'] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_dirty(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [200, np.nan, 50, None, 75], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1500, 75000, np.nan, 70, 25], [None, 75000, 30, 70, np.nan], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [600, '', 50, 3000, None], [700, 11750, 20, 2750, 55], [700, None, 20, None, 55], [700, 11750, '', 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_non_numeric(self): df = pd.DataFrame([ [1000, 'US', 30000, 10, 'cute animal #1', 100, 30], [500, 'CA', 10000, 20, 'intro to regression', 3000, 20], [200, '', np.nan, 50, 'daily news #1', None, 75], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, 20], [1000, 'MX', 45003, 20, 'cute animal #4', 90, 40], [1500, 'MX', 75000, 30, '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, 25], [None, 'US', 75000, 30, 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, 50, 'cute animal #3', 80, 20], [200, 'CA', 5000, 30, '', 10000, 30], [800, 'US', 12050, 40, 'meme compilation', 2000, 45], [600, 'CA', 11000, 50, 'daily news #2', 3000, 50], [600, 'CA', '', 50, '', 3000, None], [700, 'MX', 11750, 20, 'cute animal #2', 2750, 55], [700, '', None, 20, '', None, 55], [700, 'MX', 11750, '', '', 2750, 55], [1200, 'MX', 52000, 10, 'vc funding strats', 75, 60] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_perfectly_collinear(self): number_of_users = self.rng.integers(1000, 500000, (10000)) views = number_of_users * 300 revenue = 2 * views - number_of_users losses = revenue / views + number_of_users df = pd.DataFrame({ 'number_of_users':number_of_users, 'views': views, 'revenue': revenue, 'losses': losses }) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset:' ' [\'number_of_users\', \'views\', \'revenue\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users', 'views', 'revenue'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(result, expected_results) def test_vif_calcuation(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) expected_vifs_no_remove = ( 59.32817701051733, 26.10502642724925, 5.6541251174451315, 2.6033835916281176, 10.735934980453335 ) expected_vifs_remove = ( 59.32817701051733, 2.941751614824833, 3.4216357503903243, 1.370441833599666 ) for column, expected_vif in zip(rule.numeric_columns, expected_vifs_no_remove): vif = rule.get_variance_inflation_factor(column) self.assertAlmostEqual(vif, expected_vif) for column, expected_vif in zip(rule.numeric_columns[:-1], expected_vifs_remove): vif = rule.
7,752
220
17,318
mage-ai__mage-ai
5d823db31cab8cb2e89873aec656b5a522769873
mage_ai/tests/data_cleaner/cleaning_rules/test_remove_collinear_columns.py
inproject
numeric_df
true
statement
14
15
false
false
[ "column_types", "numeric_columns", "df", "VIF_UB", "statistics", "df_columns", "EPSILON", "evaluate", "filter_numeric_types", "get_variance_inflation_factor", "MIN_ENTRIES", "numeric_df", "numeric_indices", "ROW_SAMPLE_SIZE", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "column_types", "type": "statement" }, { "name": "df", "type": "statement" }, { "name": "df_columns", "type": "statement" }, { "name": "EPSILON", "type": "statement" }, { "name": "evaluate", "type": "function" }, { "name": "filter_numeric_types", "type": "function" }, { "name": "get_variance_inflation_factor", "type": "function" }, { "name": "MIN_ENTRIES", "type": "statement" }, { "name": "numeric_columns", "type": "statement" }, { "name": "numeric_df", "type": "statement" }, { "name": "numeric_indices", "type": "statement" }, { "name": "ROW_SAMPLE_SIZE", "type": "statement" }, { "name": "statistics", "type": "statement" }, { "name": "VIF_UB", "type": "statement" }, { "name": "_build_transformer_action_suggestion", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.cleaning_rules.remove_collinear_columns import RemoveCollinearColumns from tests.base_test import TestCase from pandas.util.testing import assert_frame_equal import numpy as np import pandas as pd class RemoveCollinearColumnsTests(TestCase): def setUp(self): self.rng = np.random.default_rng(42) return super().setUp() def test_categorical_data_frame(self): df = pd.DataFrame([ [1, 1000, '2021-10-01', '2021-09-01'], [1, 1050, '2021-10-01', '2021-08-01'], [1, 1100, '2021-10-01', '2021-01-01'], [2, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'category', 'order_id': 'category', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_clean_removes_all_data_frame(self): df = pd.DataFrame([ [None, 1000, '2021-10-01', '2021-09-01'], [1, None, '2021-10-01', '2021-08-01'], [np.nan, 1100, '2021-10-01', '2021-01-01'], [None, 1150, '2021-09-01', '2021-08-01'], ], columns=[ 'group_id', 'order_id', 'group_churned_at', 'order_created_at', ]) column_types = { 'group_id': 'number', 'order_id': 'number', 'group_churned_at': 'datetime', 'order_created_at': 'datetime' } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_collinear_no_results(self): df = pd.DataFrame([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], columns=['number_of_users', 'views', 'revenue', 'losses']) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() self.assertEqual(result, []) def test_evaluate(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_bad_dtypes(self): df = pd.DataFrame([ [1000, 'US', 30000, '10', 'cute animal #1', 100, '30'], ['500', 'CA', 10000, '20', 'intro to regression', 3000, '20'], [200, '', np.nan, 50, 'daily news #1', None, '75'], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, '20'], ['1000', 'MX', 45003, '20', 'cute animal #4', 90, '40'], [1500, 'MX', 75000, '30', '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, '25'], [None, 'US', 75000, '30', 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, '50', 'cute animal #3', 80, '20'], ['200', 'CA', 5000, '30', '', 10000, '30'], [800, 'US', 12050, '40', 'meme compilation', 2000, '45'], ['600', 'CA', 11000, '50', 'daily news #2', 3000, '50'], [600, 'CA', '', 50, '', 3000, None], ['700', 'MX', 11750, '20', 'cute animal #2', 2750, '55'], [700, '', None, 20, '', None, '55'], [700, 'MX', 11750, '', '', 2750, '55'], [1200, 'MX', 52000, '10', 'vc funding strats', 75, '60'] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_dirty(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [200, np.nan, 50, None, 75], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1500, 75000, np.nan, 70, 25], [None, 75000, 30, 70, np.nan], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [600, '', 50, 3000, None], [700, 11750, 20, 2750, 55], [700, None, 20, None, 55], [700, 11750, '', 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_evaluate_non_numeric(self): df = pd.DataFrame([ [1000, 'US', 30000, 10, 'cute animal #1', 100, 30], [500, 'CA', 10000, 20, 'intro to regression', 3000, 20], [200, '', np.nan, 50, 'daily news #1', None, 75], [250, 'CA', 7500, 25, 'machine learning seminar', 8000, 20], [1000, 'MX', 45003, 20, 'cute animal #4', 90, 40], [1500, 'MX', 75000, 30, '', 70, 25], [1500, 'US', 75000, np.nan, 'daily news #3', 70, 25], [None, 'US', 75000, 30, 'tutorial: how to start a startup', 70, np.nan], [1250, 'US', 60000, 50, 'cute animal #3', 80, 20], [200, 'CA', 5000, 30, '', 10000, 30], [800, 'US', 12050, 40, 'meme compilation', 2000, 45], [600, 'CA', 11000, 50, 'daily news #2', 3000, 50], [600, 'CA', '', 50, '', 3000, None], [700, 'MX', 11750, 20, 'cute animal #2', 2750, 55], [700, '', None, 20, '', None, 55], [700, 'MX', 11750, '', '', 2750, 55], [1200, 'MX', 52000, 10, 'vc funding strats', 75, 60] ], columns=[ 'number_of_users', 'location', 'views', 'number_of_creators', 'name', 'losses', 'number_of_advertisers' ]) cleaned_df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]).astype(float) column_types = { 'number_of_users': 'number', 'location': 'category', 'views': 'number', 'number_of_creators': 'number', 'name': 'text', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) assert_frame_equal(cleaned_df, rule.numeric_df.reset_index(drop=True)) results = rule.evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset: [\'number_of_users\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(results, expected_results) def test_perfectly_collinear(self): number_of_users = self.rng.integers(1000, 500000, (10000)) views = number_of_users * 300 revenue = 2 * views - number_of_users losses = revenue / views + number_of_users df = pd.DataFrame({ 'number_of_users':number_of_users, 'views': views, 'revenue': revenue, 'losses': losses }) column_types = { 'number_of_users': 'number', 'views': 'number', 'revenue': 'number', 'losses': 'number', } statistics = {} result = RemoveCollinearColumns(df, column_types, statistics).evaluate() expected_results = [ dict( title='Remove collinear columns', message='The following columns are strongly correlated ' 'with other columns in the dataset:' ' [\'number_of_users\', \'views\', \'revenue\']. ' 'Removing these columns may increase data quality ' 'by removing redundant and closely related data.', action_payload=dict( action_type='remove', action_arguments=['number_of_users', 'views', 'revenue'], axis='column', action_options = {}, action_variables = {}, action_code = '', outputs = [], ) ) ] self.assertEqual(result, expected_results) def test_vif_calcuation(self): df = pd.DataFrame([ [1000, 30000, 10, 100, 30], [500, 10000, 20, 3000, 20], [250, 7500, 25, 8000, 20], [1000, 45003, 20, 90, 40], [1500, 75000, 30, 70, 25], [1250, 60000, 50, 80, 20], [200, 5000, 30, 10000, 30], [800, 12050, 40, 2000, 45], [600, 11000, 50, 3000, 50], [700, 11750, 20, 2750, 55], [1200, 52000, 10, 75, 60] ], columns=[ 'number_of_users', 'views', 'number_of_creators', 'losses', 'number_of_advertisers' ]) column_types = { 'number_of_users': 'number', 'views': 'number', 'number_of_creators': 'number', 'losses': 'number', 'number_of_advertisers': 'number' } statistics = {} rule = RemoveCollinearColumns(df, column_types, statistics) expected_vifs_no_remove = ( 59.32817701051733, 26.10502642724925, 5.6541251174451315, 2.6033835916281176, 10.735934980453335 ) expected_vifs_remove = ( 59.32817701051733, 2.941751614824833, 3.4216357503903243, 1.370441833599666 ) for column, expected_vif in zip(rule.numeric_columns, expected_vifs_no_remove): vif = rule.get_variance_inflation_factor(column) self.assertAlmostEqual(vif, expected_vif) for column, expected_vif in zip(rule.numeric_columns[:-1], expected_vifs_remove): vif = rule.get_variance_inflation_factor(column) self.assertAlmostEqual(vif, expected_vif) rule.
7,753
221
817
mage-ai__mage-ai
5d174cafe82dab0bc46d82b5ac6dff808a60f5ac
mage_ai/server/routes.py
infile
data
true
statement
17
18
false
true
[ "metadata", "data", "to_dict", "write_files", "id", "dir", "folder_name", "insights", "objects", "path", "path_name", "pipeline", "read_json_file", "sample_data", "statistics", "suggestions", "write_json_file", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "data", "type": "statement" }, { "name": "dir", "type": "statement" }, { "name": "folder_name", "type": "function" }, { "name": "id", "type": "statement" }, { "name": "insights", "type": "statement" }, { "name": "metadata", "type": "statement" }, { "name": "objects", "type": "function" }, { "name": "path", "type": "statement" }, { "name": "path_name", "type": "function" }, { "name": "pipeline", "type": "property" }, { "name": "read_json_file", "type": "function" }, { "name": "sample_data", "type": "property" }, { "name": "statistics", "type": "statement" }, { "name": "suggestions", "type": "statement" }, { "name": "to_dict", "type": "function" }, { "name": "write_files", "type": "function" }, { "name": "write_json_file", "type": "function" }, { "name": "_data", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.data_cleaner import analyze, clean as clean_data from data_cleaner.pipelines.base import BasePipeline from flask import render_template, request from numpyencoder import NumpyEncoder from server.data.models import FeatureSet, Pipeline from server import app import json import threading @app.route("/") def index(): return render_template('index.html') """ request: { id: string (feature set id) clean: boolean } response: { id, metadata, sample_data, statistics, insights, suggestions } """ @app.route("/process", methods=["POST"]) def process(): request_data = request.json if not request_data: request_data = request.form id = request_data['id'] if not id: return feature_set = FeatureSet(id=id) df = feature_set.
7,754
221
849
mage-ai__mage-ai
5d174cafe82dab0bc46d82b5ac6dff808a60f5ac
mage_ai/server/routes.py
Unknown
metadata
true
statement
17
18
false
true
[ "metadata", "data", "to_dict", "write_files", "id", "dir", "folder_name", "insights", "objects", "path", "path_name", "pipeline", "read_json_file", "sample_data", "statistics", "suggestions", "write_json_file", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "data", "type": "statement" }, { "name": "dir", "type": "statement" }, { "name": "folder_name", "type": "function" }, { "name": "id", "type": "statement" }, { "name": "insights", "type": "statement" }, { "name": "metadata", "type": "statement" }, { "name": "objects", "type": "function" }, { "name": "path", "type": "statement" }, { "name": "path_name", "type": "function" }, { "name": "pipeline", "type": "property" }, { "name": "read_json_file", "type": "function" }, { "name": "sample_data", "type": "property" }, { "name": "statistics", "type": "statement" }, { "name": "suggestions", "type": "statement" }, { "name": "to_dict", "type": "function" }, { "name": "write_files", "type": "function" }, { "name": "write_json_file", "type": "function" }, { "name": "_data", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.data_cleaner import analyze, clean as clean_data from data_cleaner.pipelines.base import BasePipeline from flask import render_template, request from numpyencoder import NumpyEncoder from server.data.models import FeatureSet, Pipeline from server import app import json import threading @app.route("/") def index(): return render_template('index.html') """ request: { id: string (feature set id) clean: boolean } response: { id, metadata, sample_data, statistics, insights, suggestions } """ @app.route("/process", methods=["POST"]) def process(): request_data = request.json if not request_data: request_data = request.form id = request_data['id'] if not id: return feature_set = FeatureSet(id=id) df = feature_set.data metadata = feature_set.
7,755
221
987
mage-ai__mage-ai
5d174cafe82dab0bc46d82b5ac6dff808a60f5ac
mage_ai/server/routes.py
Unknown
write_files
true
function
17
18
false
true
[ "write_files", "metadata", "data", "to_dict", "id", "dir", "folder_name", "insights", "objects", "path", "path_name", "pipeline", "read_json_file", "sample_data", "statistics", "suggestions", "write_json_file", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "data", "type": "statement" }, { "name": "dir", "type": "statement" }, { "name": "folder_name", "type": "function" }, { "name": "id", "type": "statement" }, { "name": "insights", "type": "statement" }, { "name": "metadata", "type": "statement" }, { "name": "objects", "type": "function" }, { "name": "path", "type": "statement" }, { "name": "path_name", "type": "function" }, { "name": "pipeline", "type": "property" }, { "name": "read_json_file", "type": "function" }, { "name": "sample_data", "type": "property" }, { "name": "statistics", "type": "statement" }, { "name": "suggestions", "type": "statement" }, { "name": "to_dict", "type": "function" }, { "name": "write_files", "type": "function" }, { "name": "write_json_file", "type": "function" }, { "name": "_data", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.data_cleaner import analyze, clean as clean_data from data_cleaner.pipelines.base import BasePipeline from flask import render_template, request from numpyencoder import NumpyEncoder from server.data.models import FeatureSet, Pipeline from server import app import json import threading @app.route("/") def index(): return render_template('index.html') """ request: { id: string (feature set id) clean: boolean } response: { id, metadata, sample_data, statistics, insights, suggestions } """ @app.route("/process", methods=["POST"]) def process(): request_data = request.json if not request_data: request_data = request.form id = request_data['id'] if not id: return feature_set = FeatureSet(id=id) df = feature_set.data metadata = feature_set.metadata if request_data.get('clean', True): result = clean_data(df) else: result = analyze(df) feature_set.
7,757
221
1,211
mage-ai__mage-ai
5d174cafe82dab0bc46d82b5ac6dff808a60f5ac
mage_ai/server/routes.py
Unknown
to_dict
true
function
17
18
false
true
[ "metadata", "to_dict", "data", "write_files", "id", "dir", "folder_name", "insights", "objects", "path", "path_name", "pipeline", "read_json_file", "sample_data", "statistics", "suggestions", "write_json_file", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "data", "type": "statement" }, { "name": "dir", "type": "statement" }, { "name": "folder_name", "type": "function" }, { "name": "id", "type": "statement" }, { "name": "insights", "type": "statement" }, { "name": "metadata", "type": "statement" }, { "name": "objects", "type": "function" }, { "name": "path", "type": "statement" }, { "name": "path_name", "type": "function" }, { "name": "pipeline", "type": "property" }, { "name": "read_json_file", "type": "function" }, { "name": "sample_data", "type": "property" }, { "name": "statistics", "type": "statement" }, { "name": "suggestions", "type": "statement" }, { "name": "to_dict", "type": "function" }, { "name": "write_files", "type": "function" }, { "name": "write_json_file", "type": "function" }, { "name": "_data", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
from data_cleaner.data_cleaner import analyze, clean as clean_data from data_cleaner.pipelines.base import BasePipeline from flask import render_template, request from numpyencoder import NumpyEncoder from server.data.models import FeatureSet, Pipeline from server import app import json import threading @app.route("/") def index(): return render_template('index.html') """ request: { id: string (feature set id) clean: boolean } response: { id, metadata, sample_data, statistics, insights, suggestions } """ @app.route("/process", methods=["POST"]) def process(): request_data = request.json if not request_data: request_data = request.form id = request_data['id'] if not id: return feature_set = FeatureSet(id=id) df = feature_set.data metadata = feature_set.metadata if request_data.get('clean', True): result = clean_data(df) else: result = analyze(df) feature_set.write_files(result) column_types = result['column_types'] metadata['column_types'] = column_types feature_set.metadata = metadata response = app.response_class( response=json.dumps(feature_set.
7,758
221
1,505
mage-ai__mage-ai
5d174cafe82dab0bc46d82b5ac6dff808a60f5ac
mage_ai/server/routes.py
infile
objects
true
function
15
15
false
true
[ "to_dict", "data", "metadata", "write_files", "pipeline", "folder_name", "insights", "objects", "path_name", "read_json_file", "sample_data", "statistics", "suggestions", "write_json_file", "mro", "__init__", "__annotations__", "__base__", "__bases__", "__basicsize__", "__call__", "__delattr__", "__dict__", "__dictoffset__", "__dir__", "__eq__", "__flags__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__instancecheck__", "__itemsize__", "__mro__", "__name__", "__ne__", "__new__", "__or__", "__prepare__", "__qualname__", "__reduce__", "__reduce_ex__", "__repr__", "__ror__", "__setattr__", "__sizeof__", "__str__", "__subclasscheck__", "__subclasses__", "__subclasshook__", "__text_signature__", "__weakrefoffset__", "__class__", "__doc__", "__module__" ]
[ { "name": "data", "type": "property" }, { "name": "folder_name", "type": "function" }, { "name": "insights", "type": "property" }, { "name": "metadata", "type": "property" }, { "name": "mro", "type": "function" }, { "name": "objects", "type": "function" }, { "name": "path_name", "type": "function" }, { "name": "pipeline", "type": "property" }, { "name": "read_json_file", "type": "function" }, { "name": "sample_data", "type": "property" }, { "name": "statistics", "type": "property" }, { "name": "suggestions", "type": "property" }, { "name": "to_dict", "type": "function" }, { "name": "write_files", "type": "function" }, { "name": "write_json_file", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__base__", "type": "statement" }, { "name": "__bases__", "type": "statement" }, { "name": "__basicsize__", "type": "statement" }, { "name": "__call__", "type": "function" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dictoffset__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__flags__", "type": "statement" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__instancecheck__", "type": "function" }, { "name": "__itemsize__", "type": "statement" }, { "name": "__module__", "type": "statement" }, { "name": "__mro__", "type": "statement" }, { "name": "__name__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__prepare__", "type": "function" }, { "name": "__qualname__", "type": "statement" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" }, { "name": "__subclasscheck__", "type": "function" }, { "name": "__subclasses__", "type": "function" }, { "name": "__text_signature__", "type": "statement" }, { "name": "__weakrefoffset__", "type": "statement" } ]
from data_cleaner.data_cleaner import analyze, clean as clean_data from data_cleaner.pipelines.base import BasePipeline from flask import render_template, request from numpyencoder import NumpyEncoder from server.data.models import FeatureSet, Pipeline from server import app import json import threading @app.route("/") def index(): return render_template('index.html') """ request: { id: string (feature set id) clean: boolean } response: { id, metadata, sample_data, statistics, insights, suggestions } """ @app.route("/process", methods=["POST"]) def process(): request_data = request.json if not request_data: request_data = request.form id = request_data['id'] if not id: return feature_set = FeatureSet(id=id) df = feature_set.data metadata = feature_set.metadata if request_data.get('clean', True): result = clean_data(df) else: result = analyze(df) feature_set.write_files(result) column_types = result['column_types'] metadata['column_types'] = column_types feature_set.metadata = metadata response = app.response_class( response=json.dumps(feature_set.to_dict(), cls=NumpyEncoder), status=200, mimetype='application/json' ) return response """ response: [ { id, metadata, } ] """ @app.route("/feature_sets") def feature_sets(): feature_sets = list(map(lambda fs: fs.to_dict(False), FeatureSet.
7,761
222
4,543
qiboteam__qibolab
097a3fc1a66f8aff1fce4978054707b1d7b2c596
examples/qili_single_qubit/diagnostics.py
common
platform
true
statement
6
6
false
true
[ "platform", "sequence", "name", "label", "unit", "__init__", "get", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "get", "type": "function" }, { "name": "label", "type": "statement" }, { "name": "name", "type": "statement" }, { "name": "platform", "type": "statement" }, { "name": "sequence", "type": "statement" }, { "name": "unit", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.
7,762
222
4,565
qiboteam__qibolab
097a3fc1a66f8aff1fce4978054707b1d7b2c596
examples/qili_single_qubit/diagnostics.py
common
sequence
true
statement
6
6
false
true
[ "platform", "name", "sequence", "label", "unit", "__init__", "get", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "get", "type": "function" }, { "name": "label", "type": "statement" }, { "name": "name", "type": "statement" }, { "name": "platform", "type": "statement" }, { "name": "sequence", "type": "statement" }, { "name": "unit", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.
7,805
223
1,131
qiboteam__qibolab
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
src/qibolab/calibration/calibration.py
Unknown
platform
true
statement
11
11
false
true
[ "platform", "mc", "pl", "load_settings", "ins", "__init__", "auto_calibrate_plaform", "callibrate_qubit_states", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "auto_calibrate_plaform", "type": "function" }, { "name": "callibrate_qubit_states", "type": "function" }, { "name": "ins", "type": "statement" }, { "name": "load_settings", "type": "function" }, { "name": "mc", "type": "statement" }, { "name": "pl", "type": "statement" }, { "name": "platform", "type": "statement" }, { "name": "run_qubit_spectroscopy", "type": "function" }, { "name": "run_rabi_pulse_length", "type": "function" }, { "name": "run_resonator_spectroscopy", "type": "function" }, { "name": "run_t1", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.
7,806
223
1,193
qiboteam__qibolab
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
src/qibolab/calibration/calibration.py
Unknown
mc
true
statement
11
11
false
true
[ "mc", "platform", "pl", "load_settings", "ins", "__init__", "auto_calibrate_plaform", "callibrate_qubit_states", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "auto_calibrate_plaform", "type": "function" }, { "name": "callibrate_qubit_states", "type": "function" }, { "name": "ins", "type": "statement" }, { "name": "load_settings", "type": "function" }, { "name": "mc", "type": "statement" }, { "name": "pl", "type": "statement" }, { "name": "platform", "type": "statement" }, { "name": "run_qubit_spectroscopy", "type": "function" }, { "name": "run_rabi_pulse_length", "type": "function" }, { "name": "run_resonator_spectroscopy", "type": "function" }, { "name": "run_t1", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.
7,807
223
1,687
qiboteam__qibolab
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
src/qibolab/calibration/calibration.py
inproject
add
true
function
8
8
false
true
[ "add", "pulses", "phase", "qcm_pulses", "qrm_pulses", "add_measurement", "add_u3", "time", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add", "type": "function" }, { "name": "add_measurement", "type": "function" }, { "name": "add_u3", "type": "function" }, { "name": "phase", "type": "statement" }, { "name": "pulses", "type": "statement" }, { "name": "qcm_pulses", "type": "statement" }, { "name": "qrm_pulses", "type": "statement" }, { "name": "time", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.
7,808
223
1,718
qiboteam__qibolab
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
src/qibolab/calibration/calibration.py
Unknown
add
true
function
8
8
false
false
[ "add", "pulses", "phase", "qcm_pulses", "qrm_pulses", "add_measurement", "add_u3", "time", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add", "type": "function" }, { "name": "add_measurement", "type": "function" }, { "name": "add_u3", "type": "function" }, { "name": "phase", "type": "statement" }, { "name": "pulses", "type": "statement" }, { "name": "qcm_pulses", "type": "statement" }, { "name": "qrm_pulses", "type": "statement" }, { "name": "time", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.
7,809
223
1,751
qiboteam__qibolab
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
src/qibolab/calibration/calibration.py
Unknown
load_settings
true
function
11
11
false
true
[ "platform", "mc", "pl", "load_settings", "ins", "__init__", "auto_calibrate_plaform", "callibrate_qubit_states", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "auto_calibrate_plaform", "type": "function" }, { "name": "callibrate_qubit_states", "type": "function" }, { "name": "ins", "type": "statement" }, { "name": "load_settings", "type": "function" }, { "name": "mc", "type": "statement" }, { "name": "pl", "type": "statement" }, { "name": "platform", "type": "statement" }, { "name": "run_qubit_spectroscopy", "type": "function" }, { "name": "run_rabi_pulse_length", "type": "function" }, { "name": "run_resonator_spectroscopy", "type": "function" }, { "name": "run_t1", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.
7,810
223
1,780
qiboteam__qibolab
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
src/qibolab/calibration/calibration.py
Unknown
pl
true
statement
11
11
false
true
[ "mc", "platform", "run_t1", "pl", "load_settings", "__init__", "auto_calibrate_plaform", "callibrate_qubit_states", "ins", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "auto_calibrate_plaform", "type": "function" }, { "name": "callibrate_qubit_states", "type": "function" }, { "name": "ins", "type": "statement" }, { "name": "load_settings", "type": "function" }, { "name": "mc", "type": "statement" }, { "name": "pl", "type": "statement" }, { "name": "platform", "type": "statement" }, { "name": "run_qubit_spectroscopy", "type": "function" }, { "name": "run_rabi_pulse_length", "type": "function" }, { "name": "run_resonator_spectroscopy", "type": "function" }, { "name": "run_t1", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.
7,811
223
3,549
qiboteam__qibolab
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
src/qibolab/calibration/calibration.py
inproject
lorentzian_fit
true
function
12
17
false
true
[ "t1_fit", "rabi_fit", "lorentzian_fit", "ramsey_fit", "curve_fit", "BaseAnalysis", "data_post", "exp", "rabi", "ramsey", "resonator_peak", "set_datadir" ]
[ { "name": "BaseAnalysis", "type": "module" }, { "name": "curve_fit", "type": "module" }, { "name": "data_post", "type": "function" }, { "name": "exp", "type": "function" }, { "name": "lmfit", "type": "module" }, { "name": "lorentzian_fit", "type": "function" }, { "name": "np", "type": "module" }, { "name": "os", "type": "module" }, { "name": "pathlib", "type": "module" }, { "name": "plt", "type": "module" }, { "name": "rabi", "type": "function" }, { "name": "rabi_fit", "type": "function" }, { "name": "ramsey", "type": "function" }, { "name": "ramsey_fit", "type": "function" }, { "name": "resonator_peak", "type": "function" }, { "name": "set_datadir", "type": "module" }, { "name": "t1_fit", "type": "function" }, { "name": "__doc__", "type": "instance" }, { "name": "__file__", "type": "instance" }, { "name": "__name__", "type": "instance" }, { "name": "__package__", "type": "instance" } ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.
7,812
223
3,869
qiboteam__qibolab
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
src/qibolab/calibration/calibration.py
Unknown
platform
true
statement
11
11
false
false
[ "platform", "mc", "load_settings", "pl", "ins", "__init__", "auto_calibrate_plaform", "callibrate_qubit_states", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "auto_calibrate_plaform", "type": "function" }, { "name": "callibrate_qubit_states", "type": "function" }, { "name": "ins", "type": "statement" }, { "name": "load_settings", "type": "function" }, { "name": "mc", "type": "statement" }, { "name": "pl", "type": "statement" }, { "name": "platform", "type": "statement" }, { "name": "run_qubit_spectroscopy", "type": "function" }, { "name": "run_rabi_pulse_length", "type": "function" }, { "name": "run_resonator_spectroscopy", "type": "function" }, { "name": "run_t1", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.
7,813
223
3,931
qiboteam__qibolab
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
src/qibolab/calibration/calibration.py
random
mc
true
statement
11
11
false
false
[ "mc", "platform", "load_settings", "pl", "ins", "__init__", "auto_calibrate_plaform", "callibrate_qubit_states", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "auto_calibrate_plaform", "type": "function" }, { "name": "callibrate_qubit_states", "type": "function" }, { "name": "ins", "type": "statement" }, { "name": "load_settings", "type": "function" }, { "name": "mc", "type": "statement" }, { "name": "pl", "type": "statement" }, { "name": "platform", "type": "statement" }, { "name": "run_qubit_spectroscopy", "type": "function" }, { "name": "run_rabi_pulse_length", "type": "function" }, { "name": "run_resonator_spectroscopy", "type": "function" }, { "name": "run_t1", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.
7,814
223
4,425
qiboteam__qibolab
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
src/qibolab/calibration/calibration.py
Unknown
add
true
function
8
8
false
false
[ "add", "pulses", "phase", "qcm_pulses", "qrm_pulses", "add_measurement", "add_u3", "time", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add", "type": "function" }, { "name": "add_measurement", "type": "function" }, { "name": "add_u3", "type": "function" }, { "name": "phase", "type": "statement" }, { "name": "pulses", "type": "statement" }, { "name": "qcm_pulses", "type": "statement" }, { "name": "qrm_pulses", "type": "statement" }, { "name": "time", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.
7,815
223
4,456
qiboteam__qibolab
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
src/qibolab/calibration/calibration.py
Unknown
add
true
function
8
8
false
false
[ "add", "pulses", "phase", "qcm_pulses", "qrm_pulses", "add_measurement", "add_u3", "time", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "add", "type": "function" }, { "name": "add_measurement", "type": "function" }, { "name": "add_u3", "type": "function" }, { "name": "phase", "type": "statement" }, { "name": "pulses", "type": "statement" }, { "name": "qcm_pulses", "type": "statement" }, { "name": "qrm_pulses", "type": "statement" }, { "name": "time", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.