idx
int64 2
7.85k
| idx_lca
int64 0
223
| offset
int64 165
54.4k
| repo
stringclasses 54
values | commit_hash
stringclasses 100
values | target_file
stringclasses 118
values | line_type_lca
stringclasses 6
values | ground_truth
stringlengths 1
40
| in_completions
bool 1
class | completion_type
stringclasses 6
values | non_dunder_count_intellij
int64 1
127
| non_dunder_count_jedi
int64 1
128
| start_with_
bool 1
class | first_occurrence
bool 2
classes | intellij_completions
listlengths 1
149
| jedi_completions
listlengths 3
148
| prefix
stringlengths 165
54.4k
| intellij_completions_filtered
listlengths 1
123
| prefix_truncated
stringlengths 165
1.92k
| __index_level_0__
int64 1
5.53k
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7,660
| 216
| 3,685
|
vizzuhq__ipyvizzu
|
54b0334aa736a77f9430739c9375b16be145b3fd
|
tests/test_data/test_pandas.py
|
inproject
|
add_df
| 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",
"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"
] |
(
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.
| 5,394
|
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.
|
[
"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"
] |
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.
| 5,402
|
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.
|
[
"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"
] |
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.
| 5,403
|
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.
|
[
"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"
] |
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.
| 5,406
|
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.
|
[
"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"
] |
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.
| 5,407
|
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.
|
[
"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"
] |
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.
| 5,408
|
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.
|
[
"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"
] |
th_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.
| 5,409
|
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.
|
[
"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"
] |
plicated_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.
| 5,410
|
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.
|
[
"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"
] |
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.
| 5,411
|
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.
|
[
"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"
] |
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.
| 5,415
|
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.
|
[
"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"
] |
tEqual(
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.
| 5,416
|
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.
|
[
"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"
] |
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.
| 5,417
|
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.
|
[
"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"
] |
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.
| 5,418
|
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.
|
[
"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"
] |
.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.
| 5,419
|
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.
|
[
"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"
] |
)
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.
| 5,420
|
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.
|
[
"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"
] |
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.
| 5,424
|
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.
|
[
"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"
] |
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.
| 5,425
|
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.
|
[
"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"
] |
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.
| 5,429
|
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.
|
[
"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"
] |
est_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.
| 5,430
|
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.
|
[
"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"
] |
n_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.
| 5,431
|
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.
|
[
"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"
] |
,
)
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.
| 5,434
|
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.
|
[
"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"
] |
)
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.
| 5,435
|
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.
|
[
"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"
] |
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.
| 5,439
|
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.
|
[
"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"
] |
_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.
| 5,440
|
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.
|
[
"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"
] |
ith_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.
| 5,444
|
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.
|
[
"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"
] |
mpty_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.
| 5,445
|
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.
|
[
"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"
] |
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.
| 5,446
|
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.
|
[
"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"
] |
easure)
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.
| 5,451
|
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.
|
[
"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"
] |
ains_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.
| 5,452
|
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.
|
[
"action",
"action_type",
"hydrate_action",
"axis",
"join",
"columns_by_type",
"execute",
"groupby",
"transform"
] |
inal_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.
| 5,463
|
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().
|
[
"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"
] |
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().
| 5,464
|
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).
|
[
"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"
] |
[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).
| 5,467
|
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.
|
[
"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"
] |
, 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.
| 5,472
|
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.
|
[
"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"
] |
',
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.
| 5,481
|
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.
|
[
"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"
] |
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.
| 5,482
|
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.
|
[
"to_dict",
"data",
"metadata",
"write_files",
"pipeline",
"folder_name",
"insights",
"objects",
"path_name",
"read_json_file",
"sample_data",
"statistics",
"suggestions",
"write_json_file",
"mro"
] |
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.
| 5,486
|
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.
|
[
"platform",
"sequence",
"name",
"label",
"unit",
"get"
] |
g, 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.
| 5,487
|
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.
|
[
"platform",
"name",
"sequence",
"label",
"unit",
"get"
] |
, 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.
| 5,488
|
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.
|
[
"add",
"pulses",
"phase",
"qcm_pulses",
"qrm_pulses",
"add_measurement",
"add_u3",
"time"
] |
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.
| 5,491
|
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.
|
[
"t1_fit",
"rabi_fit",
"lorentzian_fit",
"ramsey_fit",
"curve_fit",
"BaseAnalysis",
"data_post",
"exp",
"rabi",
"ramsey",
"resonator_peak",
"set_datadir"
] |
hape)
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.
| 5,495
|
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.
|
[
"mc",
"platform",
"load_settings",
"pl",
"ins",
"auto_calibrate_plaform",
"callibrate_qubit_states",
"run_qubit_spectroscopy",
"run_rabi_pulse_length",
"run_resonator_spectroscopy",
"run_t1"
] |
idth = 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.
| 5,497
|
7,818
| 223
| 6,259
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
inproject
|
lorentzian_fit
| true
|
function
| 12
| 17
| false
| false
|
[
"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.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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.
|
[
"t1_fit",
"rabi_fit",
"lorentzian_fit",
"ramsey_fit",
"curve_fit",
"BaseAnalysis",
"data_post",
"exp",
"rabi",
"ramsey",
"resonator_peak",
"set_datadir"
] |
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['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.
| 5,502
|
7,823
| 223
| 7,173
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
infile
|
load_settings
| true
|
function
| 11
| 11
| false
| false
|
[
"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.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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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.
|
[
"platform",
"mc",
"pl",
"load_settings",
"ins",
"auto_calibrate_plaform",
"callibrate_qubit_states",
"run_qubit_spectroscopy",
"run_rabi_pulse_length",
"run_resonator_spectroscopy",
"run_t1"
] |
Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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.
| 5,507
|
7,825
| 223
| 8,038
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
inproject
|
rabi_fit
| true
|
function
| 12
| 17
| false
| true
|
[
"t1_fit",
"lorentzian_fit",
"rabi",
"rabi_fit",
"ramsey_fit",
"BaseAnalysis",
"curve_fit",
"data_post",
"exp",
"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.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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.
|
[
"t1_fit",
"lorentzian_fit",
"rabi",
"rabi_fit",
"ramsey_fit",
"BaseAnalysis",
"curve_fit",
"data_post",
"exp",
"ramsey",
"resonator_peak",
"set_datadir"
] |
th_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.
| 5,509
|
7,828
| 223
| 9,446
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
inproject
|
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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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",
"pulses",
"phase",
"qcm_pulses",
"qrm_pulses",
"add_measurement",
"add_u3",
"time"
] |
le(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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.
| 5,512
|
7,832
| 223
| 10,331
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
inproject
|
t1_fit
| true
|
function
| 12
| 17
| false
| true
|
[
"lorentzian_fit",
"rabi_fit",
"t1_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.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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.
|
[
"lorentzian_fit",
"rabi_fit",
"t1_fit",
"ramsey_fit",
"curve_fit",
"BaseAnalysis",
"data_post",
"exp",
"rabi",
"ramsey",
"resonator_peak",
"set_datadir"
] |
qual to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.
| 5,516
|
7,834
| 223
| 11,252
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
inproject
|
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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.t1_fit(dataset)
utils.plot(smooth_dataset, dataset, "t1", 1)
print(f'\nT1 = {t1}')
return t1, smooth_dataset, dataset
def callibrate_qubit_states(self):
platform = self.platform
platform.reload_settings()
ps = platform.settings['settings']
niter=10
nshots=1
#create exc and gnd pulses
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.
|
[
"add",
"pulses",
"phase",
"qcm_pulses",
"qrm_pulses",
"add_measurement",
"add_u3",
"time"
] |
e = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape)
sequence = PulseSequence()
sequence.add(qc_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.t1_fit(dataset)
utils.plot(smooth_dataset, dataset, "t1", 1)
print(f'\nT1 = {t1}')
return t1, smooth_dataset, dataset
def callibrate_qubit_states(self):
platform = self.platform
platform.reload_settings()
ps = platform.settings['settings']
niter=10
nshots=1
#create exc and gnd pulses
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.
| 5,518
|
7,835
| 223
| 11,391
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
inproject
|
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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.t1_fit(dataset)
utils.plot(smooth_dataset, dataset, "t1", 1)
print(f'\nT1 = {t1}')
return t1, smooth_dataset, dataset
def callibrate_qubit_states(self):
platform = self.platform
platform.reload_settings()
ps = platform.settings['settings']
niter=10
nshots=1
#create exc and gnd pulses
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.add(qc_pi_pulse)
gnd_sequence.add(ro_pulse)
gnd_sequence = PulseSequence()
#ro_pulse.start=0
gnd_sequence.
|
[
"add",
"pulses",
"phase",
"qcm_pulses",
"qrm_pulses",
"add_measurement",
"add_u3",
"time"
] |
sequence.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.t1_fit(dataset)
utils.plot(smooth_dataset, dataset, "t1", 1)
print(f'\nT1 = {t1}')
return t1, smooth_dataset, dataset
def callibrate_qubit_states(self):
platform = self.platform
platform.reload_settings()
ps = platform.settings['settings']
niter=10
nshots=1
#create exc and gnd pulses
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.add(qc_pi_pulse)
gnd_sequence.add(ro_pulse)
gnd_sequence = PulseSequence()
#ro_pulse.start=0
gnd_sequence.
| 5,519
|
7,837
| 223
| 12,736
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
infile
|
run_resonator_spectroscopy
| 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.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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.t1_fit(dataset)
utils.plot(smooth_dataset, dataset, "t1", 1)
print(f'\nT1 = {t1}')
return t1, smooth_dataset, dataset
def callibrate_qubit_states(self):
platform = self.platform
platform.reload_settings()
ps = platform.settings['settings']
niter=10
nshots=1
#create exc and gnd pulses
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.add(qc_pi_pulse)
gnd_sequence.add(ro_pulse)
gnd_sequence = PulseSequence()
#ro_pulse.start=0
gnd_sequence.add(ro_pulse)
platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency)
platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency)
platform.start()
#Exectue niter single gnd shots
platform.LO_qcm.off()
all_gnd_states = []
for i in range(niter):
qubit_state = platform.execute(gnd_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_gnd_states.add(point)
#Exectue niter single exc shots
platform.LO_qcm.on()
all_exc_states = []
for i in range(niter):
qubit_state = platform.execute(exc_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_exc_states.add(point)
platform.stop()
return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states)
def auto_calibrate_plaform(self):
platform = self.platform
#backup latest platform runcard
utils.backup_config_file(platform)
#run and save cavity spectroscopy calibration
resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.
|
[
"platform",
"mc",
"pl",
"load_settings",
"ins",
"auto_calibrate_plaform",
"callibrate_qubit_states",
"run_qubit_spectroscopy",
"run_rabi_pulse_length",
"run_resonator_spectroscopy",
"run_t1"
] |
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.add(qc_pi_pulse)
gnd_sequence.add(ro_pulse)
gnd_sequence = PulseSequence()
#ro_pulse.start=0
gnd_sequence.add(ro_pulse)
platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency)
platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency)
platform.start()
#Exectue niter single gnd shots
platform.LO_qcm.off()
all_gnd_states = []
for i in range(niter):
qubit_state = platform.execute(gnd_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_gnd_states.add(point)
#Exectue niter single exc shots
platform.LO_qcm.on()
all_exc_states = []
for i in range(niter):
qubit_state = platform.execute(exc_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_exc_states.add(point)
platform.stop()
return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states)
def auto_calibrate_plaform(self):
platform = self.platform
#backup latest platform runcard
utils.backup_config_file(platform)
#run and save cavity spectroscopy calibration
resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.
| 5,521
|
7,838
| 223
| 13,689
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
infile
|
run_qubit_spectroscopy
| true
|
function
| 11
| 11
| false
| true
|
[
"platform",
"mc",
"pl",
"callibrate_qubit_states",
"load_settings",
"__init__",
"auto_calibrate_plaform",
"ins",
"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.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['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.t1_fit(dataset)
utils.plot(smooth_dataset, dataset, "t1", 1)
print(f'\nT1 = {t1}')
return t1, smooth_dataset, dataset
def callibrate_qubit_states(self):
platform = self.platform
platform.reload_settings()
ps = platform.settings['settings']
niter=10
nshots=1
#create exc and gnd pulses
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.add(qc_pi_pulse)
gnd_sequence.add(ro_pulse)
gnd_sequence = PulseSequence()
#ro_pulse.start=0
gnd_sequence.add(ro_pulse)
platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency)
platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency)
platform.start()
#Exectue niter single gnd shots
platform.LO_qcm.off()
all_gnd_states = []
for i in range(niter):
qubit_state = platform.execute(gnd_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_gnd_states.add(point)
#Exectue niter single exc shots
platform.LO_qcm.on()
all_exc_states = []
for i in range(niter):
qubit_state = platform.execute(exc_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_exc_states.add(point)
platform.stop()
return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states)
def auto_calibrate_plaform(self):
platform = self.platform
#backup latest platform runcard
utils.backup_config_file(platform)
#run and save cavity spectroscopy calibration
resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy()
print(utils.get_config_parameter("settings", "", "resonator_freq"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage"))
print(utils.get_config_parameter("LO_QRM_settings", "", "frequency"))
# utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage))
# utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000))
#run and save qubit spectroscopy calibration
qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.
|
[
"platform",
"mc",
"pl",
"callibrate_qubit_states",
"load_settings",
"auto_calibrate_plaform",
"ins",
"run_qubit_spectroscopy",
"run_rabi_pulse_length",
"run_resonator_spectroscopy",
"run_t1"
] |
sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_gnd_states.add(point)
#Exectue niter single exc shots
platform.LO_qcm.on()
all_exc_states = []
for i in range(niter):
qubit_state = platform.execute(exc_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_exc_states.add(point)
platform.stop()
return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states)
def auto_calibrate_plaform(self):
platform = self.platform
#backup latest platform runcard
utils.backup_config_file(platform)
#run and save cavity spectroscopy calibration
resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy()
print(utils.get_config_parameter("settings", "", "resonator_freq"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage"))
print(utils.get_config_parameter("LO_QRM_settings", "", "frequency"))
# utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage))
# utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000))
#run and save qubit spectroscopy calibration
qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.
| 5,522
|
7,839
| 223
| 14,451
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
inproject
|
run_rabi_pulse_length
| 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.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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.t1_fit(dataset)
utils.plot(smooth_dataset, dataset, "t1", 1)
print(f'\nT1 = {t1}')
return t1, smooth_dataset, dataset
def callibrate_qubit_states(self):
platform = self.platform
platform.reload_settings()
ps = platform.settings['settings']
niter=10
nshots=1
#create exc and gnd pulses
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.add(qc_pi_pulse)
gnd_sequence.add(ro_pulse)
gnd_sequence = PulseSequence()
#ro_pulse.start=0
gnd_sequence.add(ro_pulse)
platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency)
platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency)
platform.start()
#Exectue niter single gnd shots
platform.LO_qcm.off()
all_gnd_states = []
for i in range(niter):
qubit_state = platform.execute(gnd_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_gnd_states.add(point)
#Exectue niter single exc shots
platform.LO_qcm.on()
all_exc_states = []
for i in range(niter):
qubit_state = platform.execute(exc_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_exc_states.add(point)
platform.stop()
return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states)
def auto_calibrate_plaform(self):
platform = self.platform
#backup latest platform runcard
utils.backup_config_file(platform)
#run and save cavity spectroscopy calibration
resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy()
print(utils.get_config_parameter("settings", "", "resonator_freq"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage"))
print(utils.get_config_parameter("LO_QRM_settings", "", "frequency"))
# utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage))
# utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000))
#run and save qubit spectroscopy calibration
qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy()
print(utils.get_config_parameter("settings", "", "qubit_freq"))
print(utils.get_config_parameter("LO_QCM_settings", "", "frequency"))
print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage"))
# utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq))
# utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000))
# utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage))
# #run Rabi and save Pi pulse params from calibration
dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.
|
[
"platform",
"mc",
"pl",
"load_settings",
"ins",
"auto_calibrate_plaform",
"callibrate_qubit_states",
"run_qubit_spectroscopy",
"run_rabi_pulse_length",
"run_resonator_spectroscopy",
"run_t1"
] |
t platform runcard
utils.backup_config_file(platform)
#run and save cavity spectroscopy calibration
resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy()
print(utils.get_config_parameter("settings", "", "resonator_freq"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage"))
print(utils.get_config_parameter("LO_QRM_settings", "", "frequency"))
# utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage))
# utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000))
#run and save qubit spectroscopy calibration
qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy()
print(utils.get_config_parameter("settings", "", "qubit_freq"))
print(utils.get_config_parameter("LO_QCM_settings", "", "frequency"))
print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage"))
# utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq))
# utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000))
# utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage))
# #run Rabi and save Pi pulse params from calibration
dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.
| 5,523
|
7,840
| 223
| 15,369
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
infile
|
callibrate_qubit_states
| 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.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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.t1_fit(dataset)
utils.plot(smooth_dataset, dataset, "t1", 1)
print(f'\nT1 = {t1}')
return t1, smooth_dataset, dataset
def callibrate_qubit_states(self):
platform = self.platform
platform.reload_settings()
ps = platform.settings['settings']
niter=10
nshots=1
#create exc and gnd pulses
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.add(qc_pi_pulse)
gnd_sequence.add(ro_pulse)
gnd_sequence = PulseSequence()
#ro_pulse.start=0
gnd_sequence.add(ro_pulse)
platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency)
platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency)
platform.start()
#Exectue niter single gnd shots
platform.LO_qcm.off()
all_gnd_states = []
for i in range(niter):
qubit_state = platform.execute(gnd_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_gnd_states.add(point)
#Exectue niter single exc shots
platform.LO_qcm.on()
all_exc_states = []
for i in range(niter):
qubit_state = platform.execute(exc_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_exc_states.add(point)
platform.stop()
return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states)
def auto_calibrate_plaform(self):
platform = self.platform
#backup latest platform runcard
utils.backup_config_file(platform)
#run and save cavity spectroscopy calibration
resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy()
print(utils.get_config_parameter("settings", "", "resonator_freq"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage"))
print(utils.get_config_parameter("LO_QRM_settings", "", "frequency"))
# utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage))
# utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000))
#run and save qubit spectroscopy calibration
qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy()
print(utils.get_config_parameter("settings", "", "qubit_freq"))
print(utils.get_config_parameter("LO_QCM_settings", "", "frequency"))
print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage"))
# utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq))
# utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000))
# utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage))
# #run Rabi and save Pi pulse params from calibration
dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length()
print(utils.get_config_parameter("settings", "", "pi_pulse_duration"))
print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude"))
print(utils.get_config_parameter("settings", "", "pi_pulse_gain"))
print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage"))
# utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration))
# utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude))
# utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain))
# utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage))
# #run calibration_qubit_states
all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.
|
[
"platform",
"mc",
"pl",
"load_settings",
"ins",
"auto_calibrate_plaform",
"callibrate_qubit_states",
"run_qubit_spectroscopy",
"run_rabi_pulse_length",
"run_resonator_spectroscopy",
"run_t1"
] |
oltage))
# utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000))
#run and save qubit spectroscopy calibration
qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy()
print(utils.get_config_parameter("settings", "", "qubit_freq"))
print(utils.get_config_parameter("LO_QCM_settings", "", "frequency"))
print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage"))
# utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq))
# utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000))
# utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage))
# #run Rabi and save Pi pulse params from calibration
dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length()
print(utils.get_config_parameter("settings", "", "pi_pulse_duration"))
print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude"))
print(utils.get_config_parameter("settings", "", "pi_pulse_gain"))
print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage"))
# utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration))
# utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude))
# utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain))
# utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage))
# #run calibration_qubit_states
all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.
| 5,524
|
7,844
| 223
| 16,579
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
common
|
ro_pulse
| true
|
statement
| 6
| 6
| false
| true
|
[
"ro_pulse",
"qc_pulse",
"name",
"unit",
"label",
"__init__",
"set",
"__annotations__",
"__class__",
"__delattr__",
"__dict__",
"__dir__",
"__eq__",
"__format__",
"__getattribute__",
"__hash__",
"__init_subclass__",
"__ne__",
"__new__",
"__reduce__",
"__reduce_ex__",
"__repr__",
"__setattr__",
"__sizeof__",
"__str__",
"__subclasshook__",
"__doc__",
"__module__"
] |
[
{
"name": "label",
"type": "statement"
},
{
"name": "name",
"type": "statement"
},
{
"name": "qc_pulse",
"type": "statement"
},
{
"name": "ro_pulse",
"type": "statement"
},
{
"name": "set",
"type": "function"
},
{
"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 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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.t1_fit(dataset)
utils.plot(smooth_dataset, dataset, "t1", 1)
print(f'\nT1 = {t1}')
return t1, smooth_dataset, dataset
def callibrate_qubit_states(self):
platform = self.platform
platform.reload_settings()
ps = platform.settings['settings']
niter=10
nshots=1
#create exc and gnd pulses
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.add(qc_pi_pulse)
gnd_sequence.add(ro_pulse)
gnd_sequence = PulseSequence()
#ro_pulse.start=0
gnd_sequence.add(ro_pulse)
platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency)
platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency)
platform.start()
#Exectue niter single gnd shots
platform.LO_qcm.off()
all_gnd_states = []
for i in range(niter):
qubit_state = platform.execute(gnd_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_gnd_states.add(point)
#Exectue niter single exc shots
platform.LO_qcm.on()
all_exc_states = []
for i in range(niter):
qubit_state = platform.execute(exc_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_exc_states.add(point)
platform.stop()
return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states)
def auto_calibrate_plaform(self):
platform = self.platform
#backup latest platform runcard
utils.backup_config_file(platform)
#run and save cavity spectroscopy calibration
resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy()
print(utils.get_config_parameter("settings", "", "resonator_freq"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage"))
print(utils.get_config_parameter("LO_QRM_settings", "", "frequency"))
# utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage))
# utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000))
#run and save qubit spectroscopy calibration
qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy()
print(utils.get_config_parameter("settings", "", "qubit_freq"))
print(utils.get_config_parameter("LO_QCM_settings", "", "frequency"))
print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage"))
# utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq))
# utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000))
# utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage))
# #run Rabi and save Pi pulse params from calibration
dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length()
print(utils.get_config_parameter("settings", "", "pi_pulse_duration"))
print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude"))
print(utils.get_config_parameter("settings", "", "pi_pulse_gain"))
print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage"))
# utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration))
# utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude))
# utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain))
# utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage))
# #run calibration_qubit_states
all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states()
# #TODO: save in runcard mean_gnd_states and mean_exc_states
print(all_gnd_states)
print(mean_gnd_states)
print(all_exc_states)
print(mean_exc_states)
# #TODO: Remove plot qubit states results when tested
utils.plot_qubit_states(all_gnd_states, all_exc_states)
#TODO: Remove 0 and 1 classification from auto calibration when tested
#Classify all points into 0 and 1
classified_gnd_results = []
for point in all_gnd_states:
classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
classified_exc_results = []
for point in all_exc_states:
classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
print(classified_gnd_results)
print(classified_exc_results)
# help classes
class QCPulseLengthParameter():
label = 'Qubit Control Pulse Length'
unit = 'ns'
name = 'qc_pulse_length'
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.qc_pulse = qc_pulse
def set(self, value):
self.qc_pulse.duration = value
self.
|
[
"ro_pulse",
"qc_pulse",
"name",
"unit",
"label",
"set"
] |
onfig_parameter("settings", "", "pi_pulse_gain"))
print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage"))
# utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration))
# utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude))
# utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain))
# utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage))
# #run calibration_qubit_states
all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states()
# #TODO: save in runcard mean_gnd_states and mean_exc_states
print(all_gnd_states)
print(mean_gnd_states)
print(all_exc_states)
print(mean_exc_states)
# #TODO: Remove plot qubit states results when tested
utils.plot_qubit_states(all_gnd_states, all_exc_states)
#TODO: Remove 0 and 1 classification from auto calibration when tested
#Classify all points into 0 and 1
classified_gnd_results = []
for point in all_gnd_states:
classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
classified_exc_results = []
for point in all_exc_states:
classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
print(classified_gnd_results)
print(classified_exc_results)
# help classes
class QCPulseLengthParameter():
label = 'Qubit Control Pulse Length'
unit = 'ns'
name = 'qc_pulse_length'
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.qc_pulse = qc_pulse
def set(self, value):
self.qc_pulse.duration = value
self.
| 5,526
|
7,848
| 223
| 17,001
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
common
|
ro_pulse
| true
|
statement
| 7
| 7
| false
| false
|
[
"ro_pulse",
"name",
"unit",
"label",
"initial_value",
"__init__",
"base_duration",
"set",
"__annotations__",
"__class__",
"__delattr__",
"__dict__",
"__dir__",
"__eq__",
"__format__",
"__getattribute__",
"__hash__",
"__init_subclass__",
"__ne__",
"__new__",
"__reduce__",
"__reduce_ex__",
"__repr__",
"__setattr__",
"__sizeof__",
"__str__",
"__subclasshook__",
"__doc__",
"__module__"
] |
[
{
"name": "base_duration",
"type": "statement"
},
{
"name": "initial_value",
"type": "statement"
},
{
"name": "label",
"type": "statement"
},
{
"name": "name",
"type": "statement"
},
{
"name": "ro_pulse",
"type": "statement"
},
{
"name": "set",
"type": "function"
},
{
"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 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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.t1_fit(dataset)
utils.plot(smooth_dataset, dataset, "t1", 1)
print(f'\nT1 = {t1}')
return t1, smooth_dataset, dataset
def callibrate_qubit_states(self):
platform = self.platform
platform.reload_settings()
ps = platform.settings['settings']
niter=10
nshots=1
#create exc and gnd pulses
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.add(qc_pi_pulse)
gnd_sequence.add(ro_pulse)
gnd_sequence = PulseSequence()
#ro_pulse.start=0
gnd_sequence.add(ro_pulse)
platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency)
platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency)
platform.start()
#Exectue niter single gnd shots
platform.LO_qcm.off()
all_gnd_states = []
for i in range(niter):
qubit_state = platform.execute(gnd_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_gnd_states.add(point)
#Exectue niter single exc shots
platform.LO_qcm.on()
all_exc_states = []
for i in range(niter):
qubit_state = platform.execute(exc_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_exc_states.add(point)
platform.stop()
return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states)
def auto_calibrate_plaform(self):
platform = self.platform
#backup latest platform runcard
utils.backup_config_file(platform)
#run and save cavity spectroscopy calibration
resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy()
print(utils.get_config_parameter("settings", "", "resonator_freq"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage"))
print(utils.get_config_parameter("LO_QRM_settings", "", "frequency"))
# utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage))
# utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000))
#run and save qubit spectroscopy calibration
qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy()
print(utils.get_config_parameter("settings", "", "qubit_freq"))
print(utils.get_config_parameter("LO_QCM_settings", "", "frequency"))
print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage"))
# utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq))
# utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000))
# utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage))
# #run Rabi and save Pi pulse params from calibration
dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length()
print(utils.get_config_parameter("settings", "", "pi_pulse_duration"))
print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude"))
print(utils.get_config_parameter("settings", "", "pi_pulse_gain"))
print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage"))
# utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration))
# utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude))
# utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain))
# utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage))
# #run calibration_qubit_states
all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states()
# #TODO: save in runcard mean_gnd_states and mean_exc_states
print(all_gnd_states)
print(mean_gnd_states)
print(all_exc_states)
print(mean_exc_states)
# #TODO: Remove plot qubit states results when tested
utils.plot_qubit_states(all_gnd_states, all_exc_states)
#TODO: Remove 0 and 1 classification from auto calibration when tested
#Classify all points into 0 and 1
classified_gnd_results = []
for point in all_gnd_states:
classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
classified_exc_results = []
for point in all_exc_states:
classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
print(classified_gnd_results)
print(classified_exc_results)
# help classes
class QCPulseLengthParameter():
label = 'Qubit Control Pulse Length'
unit = 'ns'
name = 'qc_pulse_length'
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.qc_pulse = qc_pulse
def set(self, value):
self.qc_pulse.duration = value
self.ro_pulse.start = value + 4
class T1WaitParameter():
label = 'Time'
unit = 'ns'
name = 't1_wait'
initial_value = 0
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.base_duration = qc_pulse.duration
def set(self, value):
# TODO: implement following condition
#must be >= 4ns <= 65535
#platform.delay_before_readout = value
self.
|
[
"ro_pulse",
"name",
"unit",
"label",
"initial_value",
"base_duration",
"set"
] |
, float(pi_pulse_gain))
# utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage))
# #run calibration_qubit_states
all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states()
# #TODO: save in runcard mean_gnd_states and mean_exc_states
print(all_gnd_states)
print(mean_gnd_states)
print(all_exc_states)
print(mean_exc_states)
# #TODO: Remove plot qubit states results when tested
utils.plot_qubit_states(all_gnd_states, all_exc_states)
#TODO: Remove 0 and 1 classification from auto calibration when tested
#Classify all points into 0 and 1
classified_gnd_results = []
for point in all_gnd_states:
classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
classified_exc_results = []
for point in all_exc_states:
classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
print(classified_gnd_results)
print(classified_exc_results)
# help classes
class QCPulseLengthParameter():
label = 'Qubit Control Pulse Length'
unit = 'ns'
name = 'qc_pulse_length'
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.qc_pulse = qc_pulse
def set(self, value):
self.qc_pulse.duration = value
self.ro_pulse.start = value + 4
class T1WaitParameter():
label = 'Time'
unit = 'ns'
name = 't1_wait'
initial_value = 0
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.base_duration = qc_pulse.duration
def set(self, value):
# TODO: implement following condition
#must be >= 4ns <= 65535
#platform.delay_before_readout = value
self.
| 5,527
|
7,850
| 223
| 17,023
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
common
|
base_duration
| true
|
statement
| 7
| 7
| false
| true
|
[
"ro_pulse",
"base_duration",
"name",
"unit",
"label",
"__init__",
"initial_value",
"set",
"__annotations__",
"__class__",
"__delattr__",
"__dict__",
"__dir__",
"__eq__",
"__format__",
"__getattribute__",
"__hash__",
"__init_subclass__",
"__ne__",
"__new__",
"__reduce__",
"__reduce_ex__",
"__repr__",
"__setattr__",
"__sizeof__",
"__str__",
"__subclasshook__",
"__doc__",
"__module__"
] |
[
{
"name": "base_duration",
"type": "statement"
},
{
"name": "initial_value",
"type": "statement"
},
{
"name": "label",
"type": "statement"
},
{
"name": "name",
"type": "statement"
},
{
"name": "ro_pulse",
"type": "statement"
},
{
"name": "set",
"type": "function"
},
{
"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 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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.t1_fit(dataset)
utils.plot(smooth_dataset, dataset, "t1", 1)
print(f'\nT1 = {t1}')
return t1, smooth_dataset, dataset
def callibrate_qubit_states(self):
platform = self.platform
platform.reload_settings()
ps = platform.settings['settings']
niter=10
nshots=1
#create exc and gnd pulses
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.add(qc_pi_pulse)
gnd_sequence.add(ro_pulse)
gnd_sequence = PulseSequence()
#ro_pulse.start=0
gnd_sequence.add(ro_pulse)
platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency)
platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency)
platform.start()
#Exectue niter single gnd shots
platform.LO_qcm.off()
all_gnd_states = []
for i in range(niter):
qubit_state = platform.execute(gnd_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_gnd_states.add(point)
#Exectue niter single exc shots
platform.LO_qcm.on()
all_exc_states = []
for i in range(niter):
qubit_state = platform.execute(exc_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_exc_states.add(point)
platform.stop()
return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states)
def auto_calibrate_plaform(self):
platform = self.platform
#backup latest platform runcard
utils.backup_config_file(platform)
#run and save cavity spectroscopy calibration
resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy()
print(utils.get_config_parameter("settings", "", "resonator_freq"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage"))
print(utils.get_config_parameter("LO_QRM_settings", "", "frequency"))
# utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage))
# utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000))
#run and save qubit spectroscopy calibration
qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy()
print(utils.get_config_parameter("settings", "", "qubit_freq"))
print(utils.get_config_parameter("LO_QCM_settings", "", "frequency"))
print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage"))
# utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq))
# utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000))
# utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage))
# #run Rabi and save Pi pulse params from calibration
dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length()
print(utils.get_config_parameter("settings", "", "pi_pulse_duration"))
print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude"))
print(utils.get_config_parameter("settings", "", "pi_pulse_gain"))
print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage"))
# utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration))
# utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude))
# utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain))
# utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage))
# #run calibration_qubit_states
all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states()
# #TODO: save in runcard mean_gnd_states and mean_exc_states
print(all_gnd_states)
print(mean_gnd_states)
print(all_exc_states)
print(mean_exc_states)
# #TODO: Remove plot qubit states results when tested
utils.plot_qubit_states(all_gnd_states, all_exc_states)
#TODO: Remove 0 and 1 classification from auto calibration when tested
#Classify all points into 0 and 1
classified_gnd_results = []
for point in all_gnd_states:
classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
classified_exc_results = []
for point in all_exc_states:
classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
print(classified_gnd_results)
print(classified_exc_results)
# help classes
class QCPulseLengthParameter():
label = 'Qubit Control Pulse Length'
unit = 'ns'
name = 'qc_pulse_length'
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.qc_pulse = qc_pulse
def set(self, value):
self.qc_pulse.duration = value
self.ro_pulse.start = value + 4
class T1WaitParameter():
label = 'Time'
unit = 'ns'
name = 't1_wait'
initial_value = 0
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.base_duration = qc_pulse.duration
def set(self, value):
# TODO: implement following condition
#must be >= 4ns <= 65535
#platform.delay_before_readout = value
self.ro_pulse.start = self.
|
[
"ro_pulse",
"base_duration",
"name",
"unit",
"label",
"initial_value",
"set"
] |
)
# utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage))
# #run calibration_qubit_states
all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states()
# #TODO: save in runcard mean_gnd_states and mean_exc_states
print(all_gnd_states)
print(mean_gnd_states)
print(all_exc_states)
print(mean_exc_states)
# #TODO: Remove plot qubit states results when tested
utils.plot_qubit_states(all_gnd_states, all_exc_states)
#TODO: Remove 0 and 1 classification from auto calibration when tested
#Classify all points into 0 and 1
classified_gnd_results = []
for point in all_gnd_states:
classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
classified_exc_results = []
for point in all_exc_states:
classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
print(classified_gnd_results)
print(classified_exc_results)
# help classes
class QCPulseLengthParameter():
label = 'Qubit Control Pulse Length'
unit = 'ns'
name = 'qc_pulse_length'
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.qc_pulse = qc_pulse
def set(self, value):
self.qc_pulse.duration = value
self.ro_pulse.start = value + 4
class T1WaitParameter():
label = 'Time'
unit = 'ns'
name = 't1_wait'
initial_value = 0
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.base_duration = qc_pulse.duration
def set(self, value):
# TODO: implement following condition
#must be >= 4ns <= 65535
#platform.delay_before_readout = value
self.ro_pulse.start = self.
| 5,528
|
7,853
| 223
| 17,383
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
common
|
platform
| true
|
statement
| 6
| 6
| false
| false
|
[
"platform",
"sequence",
"name",
"unit",
"label",
"__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 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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.t1_fit(dataset)
utils.plot(smooth_dataset, dataset, "t1", 1)
print(f'\nT1 = {t1}')
return t1, smooth_dataset, dataset
def callibrate_qubit_states(self):
platform = self.platform
platform.reload_settings()
ps = platform.settings['settings']
niter=10
nshots=1
#create exc and gnd pulses
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.add(qc_pi_pulse)
gnd_sequence.add(ro_pulse)
gnd_sequence = PulseSequence()
#ro_pulse.start=0
gnd_sequence.add(ro_pulse)
platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency)
platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency)
platform.start()
#Exectue niter single gnd shots
platform.LO_qcm.off()
all_gnd_states = []
for i in range(niter):
qubit_state = platform.execute(gnd_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_gnd_states.add(point)
#Exectue niter single exc shots
platform.LO_qcm.on()
all_exc_states = []
for i in range(niter):
qubit_state = platform.execute(exc_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_exc_states.add(point)
platform.stop()
return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states)
def auto_calibrate_plaform(self):
platform = self.platform
#backup latest platform runcard
utils.backup_config_file(platform)
#run and save cavity spectroscopy calibration
resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy()
print(utils.get_config_parameter("settings", "", "resonator_freq"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage"))
print(utils.get_config_parameter("LO_QRM_settings", "", "frequency"))
# utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage))
# utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000))
#run and save qubit spectroscopy calibration
qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy()
print(utils.get_config_parameter("settings", "", "qubit_freq"))
print(utils.get_config_parameter("LO_QCM_settings", "", "frequency"))
print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage"))
# utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq))
# utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000))
# utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage))
# #run Rabi and save Pi pulse params from calibration
dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length()
print(utils.get_config_parameter("settings", "", "pi_pulse_duration"))
print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude"))
print(utils.get_config_parameter("settings", "", "pi_pulse_gain"))
print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage"))
# utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration))
# utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude))
# utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain))
# utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage))
# #run calibration_qubit_states
all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states()
# #TODO: save in runcard mean_gnd_states and mean_exc_states
print(all_gnd_states)
print(mean_gnd_states)
print(all_exc_states)
print(mean_exc_states)
# #TODO: Remove plot qubit states results when tested
utils.plot_qubit_states(all_gnd_states, all_exc_states)
#TODO: Remove 0 and 1 classification from auto calibration when tested
#Classify all points into 0 and 1
classified_gnd_results = []
for point in all_gnd_states:
classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
classified_exc_results = []
for point in all_exc_states:
classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
print(classified_gnd_results)
print(classified_exc_results)
# help classes
class QCPulseLengthParameter():
label = 'Qubit Control Pulse Length'
unit = 'ns'
name = 'qc_pulse_length'
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.qc_pulse = qc_pulse
def set(self, value):
self.qc_pulse.duration = value
self.ro_pulse.start = value + 4
class T1WaitParameter():
label = 'Time'
unit = 'ns'
name = 't1_wait'
initial_value = 0
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.base_duration = qc_pulse.duration
def set(self, value):
# TODO: implement following condition
#must be >= 4ns <= 65535
#platform.delay_before_readout = value
self.ro_pulse.start = self.base_duration + 4 + value
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",
"sequence",
"name",
"unit",
"label",
"get"
] |
print(all_gnd_states)
print(mean_gnd_states)
print(all_exc_states)
print(mean_exc_states)
# #TODO: Remove plot qubit states results when tested
utils.plot_qubit_states(all_gnd_states, all_exc_states)
#TODO: Remove 0 and 1 classification from auto calibration when tested
#Classify all points into 0 and 1
classified_gnd_results = []
for point in all_gnd_states:
classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
classified_exc_results = []
for point in all_exc_states:
classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
print(classified_gnd_results)
print(classified_exc_results)
# help classes
class QCPulseLengthParameter():
label = 'Qubit Control Pulse Length'
unit = 'ns'
name = 'qc_pulse_length'
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.qc_pulse = qc_pulse
def set(self, value):
self.qc_pulse.duration = value
self.ro_pulse.start = value + 4
class T1WaitParameter():
label = 'Time'
unit = 'ns'
name = 't1_wait'
initial_value = 0
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.base_duration = qc_pulse.duration
def set(self, value):
# TODO: implement following condition
#must be >= 4ns <= 65535
#platform.delay_before_readout = value
self.ro_pulse.start = self.base_duration + 4 + value
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.
| 5,529
|
7,854
| 223
| 17,405
|
qiboteam__qibolab
|
e4b0e8e6dd612e696a161da9972f4bb9b6bf8cd0
|
src/qibolab/calibration/calibration.py
|
common
|
sequence
| true
|
statement
| 6
| 6
| false
| true
|
[
"platform",
"sequence",
"name",
"unit",
"label",
"__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 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.add(ro_pulse)
ds = self.load_settings()
self.pl.tuids_max_num(ds['max_num_plots'])
software_averages = ds['software_averages']
ds = ds['qubit_spectroscopy']
fast_start = ds['fast_start']
fast_end = ds['fast_end']
fast_step = ds['fast_step']
precision_start = ds['precision_start']
precision_end = ds['precision_end']
precision_step = ds['precision_step']
# Fast Sweep
fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1)
platform.stop()
# Precision Sweep
platform.software_averages = 1
precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step)
mc.settables(platform.LO_qcm.device.frequency)
mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency())
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages)
platform.stop()
# Fitting
smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2)
qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency
min_ro_voltage = smooth_dataset.min() * 1e6
print(f"\nQubit Frequency = {qubit_freq}")
utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1)
print("Qubit freq ontained from MC results: ", qubit_freq)
f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy")
qubit_freq = (f0*1e9 - qc_pulse.frequency)
print("Qubit freq ontained from fitting: ", qubit_freq)
return qubit_freq, min_ro_voltage, smooth_dataset, dataset
def run_rabi_pulse_length(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['rabi_pulse_length']
pulse_duration_start = ds['pulse_duration_start']
pulse_duration_end = ds['pulse_duration_end']
pulse_duration_step = ds['pulse_duration_step']
mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)))
mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages)
platform.stop()
# Fitting
pi_pulse_amplitude = qc_pulse.amplitude
smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset)
pi_pulse_gain = platform.qcm.gain
utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1)
print(f"\nPi pulse duration = {pi_pulse_duration}")
print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct.
print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi.
print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}")
print(f"\nT1 = {t1}")
return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1
# T1: RX(pi) - wait t(rotates z) - readout
def run_t1(self):
platform = self.platform
platform.reload_settings()
mc = self.mc
ps = platform.settings['settings']
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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_pi_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['t1']
delay_before_readout_start = ds['delay_before_readout_start']
delay_before_readout_end = ds['delay_before_readout_end']
delay_before_readout_step = ds['delay_before_readout_step']
mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse)))
mc.setpoints(np.arange(delay_before_readout_start,
delay_before_readout_end,
delay_before_readout_step))
mc.gettables(Gettable(ROController(platform, sequence)))
platform.start()
dataset = mc.run('T1', soft_avg = software_averages)
platform.stop()
# Fitting
smooth_dataset, t1 = fitting.t1_fit(dataset)
utils.plot(smooth_dataset, dataset, "t1", 1)
print(f'\nT1 = {t1}')
return t1, smooth_dataset, dataset
def callibrate_qubit_states(self):
platform = self.platform
platform.reload_settings()
ps = platform.settings['settings']
niter=10
nshots=1
#create exc and gnd pulses
start = 0
frequency = ps['pi_pulse_frequency']
amplitude = ps['pi_pulse_amplitude']
duration = ps['pi_pulse_duration']
phase = 0
shape = eval(ps['pi_pulse_shape'])
qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, 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)
exc_sequence = PulseSequence()
exc_sequence.add(qc_pi_pulse)
gnd_sequence.add(ro_pulse)
gnd_sequence = PulseSequence()
#ro_pulse.start=0
gnd_sequence.add(ro_pulse)
platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency)
platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency)
platform.start()
#Exectue niter single gnd shots
platform.LO_qcm.off()
all_gnd_states = []
for i in range(niter):
qubit_state = platform.execute(gnd_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_gnd_states.add(point)
#Exectue niter single exc shots
platform.LO_qcm.on()
all_exc_states = []
for i in range(niter):
qubit_state = platform.execute(exc_sequence, nshots)
#Compose complex point from i, q obtained from execution
point = complex(qubit_state[2], qubit_state[3])
all_exc_states.add(point)
platform.stop()
return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states)
def auto_calibrate_plaform(self):
platform = self.platform
#backup latest platform runcard
utils.backup_config_file(platform)
#run and save cavity spectroscopy calibration
resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy()
print(utils.get_config_parameter("settings", "", "resonator_freq"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage"))
print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage"))
print(utils.get_config_parameter("LO_QRM_settings", "", "frequency"))
# utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage))
# utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage))
# utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000))
#run and save qubit spectroscopy calibration
qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy()
print(utils.get_config_parameter("settings", "", "qubit_freq"))
print(utils.get_config_parameter("LO_QCM_settings", "", "frequency"))
print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage"))
# utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq))
# utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000))
# utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage))
# #run Rabi and save Pi pulse params from calibration
dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length()
print(utils.get_config_parameter("settings", "", "pi_pulse_duration"))
print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude"))
print(utils.get_config_parameter("settings", "", "pi_pulse_gain"))
print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage"))
# utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration))
# utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude))
# utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain))
# utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage))
# #run calibration_qubit_states
all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states()
# #TODO: save in runcard mean_gnd_states and mean_exc_states
print(all_gnd_states)
print(mean_gnd_states)
print(all_exc_states)
print(mean_exc_states)
# #TODO: Remove plot qubit states results when tested
utils.plot_qubit_states(all_gnd_states, all_exc_states)
#TODO: Remove 0 and 1 classification from auto calibration when tested
#Classify all points into 0 and 1
classified_gnd_results = []
for point in all_gnd_states:
classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
classified_exc_results = []
for point in all_exc_states:
classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
print(classified_gnd_results)
print(classified_exc_results)
# help classes
class QCPulseLengthParameter():
label = 'Qubit Control Pulse Length'
unit = 'ns'
name = 'qc_pulse_length'
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.qc_pulse = qc_pulse
def set(self, value):
self.qc_pulse.duration = value
self.ro_pulse.start = value + 4
class T1WaitParameter():
label = 'Time'
unit = 'ns'
name = 't1_wait'
initial_value = 0
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.base_duration = qc_pulse.duration
def set(self, value):
# TODO: implement following condition
#must be >= 4ns <= 65535
#platform.delay_before_readout = value
self.ro_pulse.start = self.base_duration + 4 + value
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.
|
[
"platform",
"sequence",
"name",
"unit",
"label",
"get"
] |
_states)
print(mean_gnd_states)
print(all_exc_states)
print(mean_exc_states)
# #TODO: Remove plot qubit states results when tested
utils.plot_qubit_states(all_gnd_states, all_exc_states)
#TODO: Remove 0 and 1 classification from auto calibration when tested
#Classify all points into 0 and 1
classified_gnd_results = []
for point in all_gnd_states:
classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
classified_exc_results = []
for point in all_exc_states:
classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states))
print(classified_gnd_results)
print(classified_exc_results)
# help classes
class QCPulseLengthParameter():
label = 'Qubit Control Pulse Length'
unit = 'ns'
name = 'qc_pulse_length'
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.qc_pulse = qc_pulse
def set(self, value):
self.qc_pulse.duration = value
self.ro_pulse.start = value + 4
class T1WaitParameter():
label = 'Time'
unit = 'ns'
name = 't1_wait'
initial_value = 0
def __init__(self, ro_pulse, qc_pulse):
self.ro_pulse = ro_pulse
self.base_duration = qc_pulse.duration
def set(self, value):
# TODO: implement following condition
#must be >= 4ns <= 65535
#platform.delay_before_readout = value
self.ro_pulse.start = self.base_duration + 4 + value
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.
| 5,530
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.