def test_join_subset_data_inherit_variables(self, long_df): sub_df = long_df[long_df["a"] == "b"] var = "y" p1 = PlotData(long_df, {var: var}) p2 = p1.join(sub_df, None) assert_vector_equal(p2.frame.loc[sub_df.index, var], sub_df[var]) assert p2.frame.loc[long_df.index.difference(sub_df.index), var].isna().all()
def test_join_remove_variable(self, long_df): variables = {"x": "x", "y": "f"} drop_var = "y" p1 = PlotData(long_df, variables) p2 = p1.join(None, {drop_var: None}) assert drop_var in p1 assert drop_var not in p2 assert drop_var not in p2.frame assert drop_var not in p2.names
def test_join_add_variable(self, long_df): v1 = {"x": "x", "y": "f"} v2 = {"color": "a"} p1 = PlotData(long_df, v1) p2 = p1.join(None, v2) for var, key in dict(**v1, **v2).items(): assert var in p2 assert p2.names[var] == key assert_vector_equal(p2.frame[var], long_df[key])
def test_join_add_variable_new_data(self, long_df): d1 = long_df[["x", "y"]] d2 = long_df[["a", "s"]] v1 = {"x": "x", "y": "y"} v2 = {"color": "a"} p1 = PlotData(d1, v1) p2 = p1.join(d2, v2) for var, key in dict(**v1, **v2).items(): assert p2.names[var] == key assert_vector_equal(p2.frame[var], long_df[key])
def test_join_all_operations_same_data(self, long_df): v1 = {"x": "x", "y": "y", "color": "a"} v2 = {"y": "s", "size": "s", "color": None} p1 = PlotData(long_df, v1) p2 = p1.join(long_df, v2) for var, key in v2.items(): if key is None: assert var not in p2 else: assert p2.names[var] == key assert_vector_equal(p2.frame[var], long_df[key])
def test_join_replace_variable(self, long_df): v1 = {"x": "x", "y": "y"} v2 = {"y": "s"} p1 = PlotData(long_df, v1) p2 = p1.join(None, v2) variables = v1.copy() variables.update(v2) for var, key in variables.items(): assert var in p2 assert p2.names[var] == key assert_vector_equal(p2.frame[var], long_df[key])
def test_join_replace_variable_new_data(self, long_df): d1 = long_df[["x", "y"]] d2 = long_df[["a", "s"]] v1 = {"x": "x", "y": "y"} v2 = {"x": "a"} p1 = PlotData(d1, v1) p2 = p1.join(d2, v2) variables = v1.copy() variables.update(v2) for var, key in variables.items(): assert p2.names[var] == key assert_vector_equal(p2.frame[var], long_df[key])
def test_join_replace_variable_different_index(self, long_df): d1 = long_df.iloc[:70] d2 = long_df.iloc[30:] var = "x" k1, k2 = "a", "z" v1 = {var: k1} v2 = {var: k2} p1 = PlotData(d1, v1) p2 = p1.join(d2, v2) (var1, key1), = v1.items() (var2, key2), = v2.items() assert_vector_equal(p2.frame.loc[d2.index, var], d2[k2]) assert p2.frame.loc[d1.index.difference(d2.index), var].isna().all()
def test_join_add_variable_different_index(self, long_df): d1 = long_df.iloc[:70] d2 = long_df.iloc[30:] v1 = {"x": "a"} v2 = {"y": "z"} p1 = PlotData(d1, v1) p2 = p1.join(d2, v2) (var1, key1), = v1.items() (var2, key2), = v2.items() assert_vector_equal(p2.frame.loc[d1.index, var1], d1[key1]) assert_vector_equal(p2.frame.loc[d2.index, var2], d2[key2]) assert p2.frame.loc[d2.index.difference(d1.index), var1].isna().all() assert p2.frame.loc[d1.index.difference(d2.index), var2].isna().all()