From 1b8d4a7387df08914f7dd7ce671ec5558f7e7e11 Mon Sep 17 00:00:00 2001 From: Ruslan Alsherov Date: Tue, 5 Nov 2024 19:32:12 +0300 Subject: [PATCH] update __getitem__ (change cell values) --- hypex/dataset/dataset.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hypex/dataset/dataset.py b/hypex/dataset/dataset.py index 14dc6080..4603734a 100644 --- a/hypex/dataset/dataset.py +++ b/hypex/dataset/dataset.py @@ -54,6 +54,13 @@ def __getitem__(self, item) -> "Dataset": data=t_data, roles={k: v for k, v in self.roles.items() if k in t_data.columns}, ) + + def __setitem__(self, item, value): + column_name = item[1] + if column_name not in self.backend.data.columns: + raise KeyError("Column must be added by using add_column method.") + else: + self.backend.data.loc[item] = value class ILocker: def __init__(self, backend, roles): @@ -66,6 +73,13 @@ def __getitem__(self, item) -> "Dataset": data=t_data, roles={k: v for k, v in self.roles.items() if k in t_data.columns}, ) + + def __setitem__(self, item, value): + column_index = item[1] + if column_index >= len(self.backend.data.columns): + raise IndexError("Column must be added by using add_column method.") + else: + self.backend.data.iloc[item] = value def __init__( self,