def test_replace_stream_and_reset(): # Given data = pd.DataFrame({"x": [1, 2, 3, 4, 5], "y": ["a", "b", "c", "d", "e"]}) data1 = data.copy(deep=True).loc[0:1, ].reset_index(drop=True) data2 = data.copy(deep=True).loc[2:3, ].reset_index(drop=True) data3 = data.copy(deep=True).loc[4:4, ] tabulator = Tabulator(value=data1) # When replace, stream and reset tabulator.value = data2 tabulator.stream(stream_value=data3) tabulator.value = data.copy(deep=True).loc[0:1, ] # Then assert set(tabulator._source.data["x"]) == {1, 2}
def test_patch_from_partial_dataframe(): data = pd.DataFrame({"x": [1, 2, 3, 4], "y": ["a", "b", "c", "d"]}) data1 = data.loc[0:1, ] data2 = data.loc[2:4] # When tabulator = Tabulator(value=data1) tabulator.value = data2.reset_index(drop=True) patch_value = tabulator.value["x"] + 2 tabulator.patch(patch_value) # Then expected = pd.DataFrame({"x": [5, 6], "y": ["c", "d"]}) pd.testing.assert_frame_equal(tabulator.value, expected)
def test_patch_and_reset(): """I experienced some strange behaviour which I test below. The code actually worked as it should. The problem was that I patched the original data so I could never "reset" back to the original data """ # Given data = pd.DataFrame({"x": [1, 2, 3, 4], "y": ["a", "b", "c", "d"]}) data_copy = data.copy(deep=True) tabulator = Tabulator(value=data_copy) patch = tabulator.value["x"] + 2 # When patch Then tabulator.patch(patch_value=patch) assert set(tabulator._source.data["x"]) == {3, 4, 5, 6} # When reset Then tabulator.value = data assert set(tabulator._source.data["x"]) == {1, 2, 3, 4}