From 74398e16302f16226dca762cbebf3502809f7616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Mon, 28 Aug 2023 19:09:03 +0200 Subject: [PATCH] Fix pandas related tests --- holonote/annotate/table.py | 4 ++-- holonote/tests/test_connectors.py | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/holonote/annotate/table.py b/holonote/annotate/table.py index fb7d348..c418438 100644 --- a/holonote/annotate/table.py +++ b/holonote/annotate/table.py @@ -243,7 +243,7 @@ def delete_annotation(self, index): def update_annotation_fields(self, index, **fields): for column, value in fields.items(): - self._field_df.loc[index][column] = value + self._field_df.loc[index, column] = value self._edits.append({'operation':'update', 'id':index, 'fields' : [c for c in fields.keys()], @@ -303,7 +303,7 @@ def define_points(self, dims, posx, posy=None): raise KeyError(f'Keys {mismatches} do not match any fields entries') dim2 = None if len(dims)==1 else dims[1] - value = zip(posx, pd.Series([None for el in range(len(posx))])) if len(dims)==1 else zip(posx, posy) + value = zip(posx, [None] * len(posx)) if len(dims)==1 else zip(posx, posy) additions = pd.DataFrame({"region_type":'Point', "dim1":dims[0], "dim2":dim2, diff --git a/holonote/tests/test_connectors.py b/holonote/tests/test_connectors.py index 5047488..32f1d9b 100644 --- a/holonote/tests/test_connectors.py +++ b/holonote/tests/test_connectors.py @@ -78,7 +78,7 @@ def test_add_row(self, database, request): end = pd.Timestamp('2022-06-03') description = 'A description' insertion = {"uuid": id1, 'description':description, 'start':start, 'end':end} - df = pd.DataFrame({"uuid":pd.Series([id1], dtype=object), + df = pd.DataFrame({"uuid":[database.primary_key.cast(id1)], 'description':[description], 'start':[start], 'end':[end]}).set_index("uuid") database.add_row(**insertion) pd.testing.assert_frame_equal(database.load_dataframe(), df) @@ -102,10 +102,12 @@ def test_add_three_rows_delete_one(self, database): 'start':pd.Timestamp('2026-06-01'), 'end':pd.Timestamp('2026-06-03')} - df_data = {'uuid': pd.Series([insertion1['uuid'], insertion3['uuid']], dtype=object), - 'description':[insertion1['description'], insertion3['description']], - 'start':[insertion1['start'], insertion3['start']], - 'end':[insertion1['end'], insertion3['end']]} + df_data = { + 'uuid': map(database.primary_key.cast, [insertion1['uuid'], insertion3['uuid']]), + 'description':[insertion1['description'], insertion3['description']], + 'start':[insertion1['start'], insertion3['start']], + 'end':[insertion1['end'], insertion3['end']] + } df = pd.DataFrame(df_data).set_index('uuid') database.add_row(**insertion1) database.add_row(**insertion2)