From 41854aa52a9426ffba7ccce4877f4eea57d52199 Mon Sep 17 00:00:00 2001 From: Danil Zherebtsov Date: Fri, 30 Aug 2024 23:05:36 +0400 Subject: [PATCH 1/5] change methods names --- .../data_processing/scaler/linear_scaler.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/synnax_shared/data_processing/scaler/linear_scaler.py b/src/synnax_shared/data_processing/scaler/linear_scaler.py index 73f0924..0411e67 100644 --- a/src/synnax_shared/data_processing/scaler/linear_scaler.py +++ b/src/synnax_shared/data_processing/scaler/linear_scaler.py @@ -26,24 +26,24 @@ def __init__(self, offset: float, divisor: float) -> None: self.offset = offset self.divisor = divisor - def transform_series(self, series: Series) -> Series: + def _transform_series(self, series: Series) -> Series: float_series = series.astype(float) return (float_series + self.offset) / self.divisor - def inverse_transform_series(self, series: Series) -> Series: + def _inverse_transform_series(self, series: Series) -> Series: float_series = series.astype(float) return (float_series * self.divisor) - self.offset - def transform_dataframe(self, dataframe: DataFrame) -> DataFrame: + def transform(self, dataframe: DataFrame) -> DataFrame: dataframe_copy = dataframe.copy() for column in dataframe_copy.select_dtypes(include=[number]): - dataframe_copy[column] = self.transform_series(dataframe_copy[column]) + dataframe_copy[column] = self._transform_series(dataframe_copy[column]) return dataframe_copy - def inverse_transform_dataframe(self, dataframe: DataFrame) -> DataFrame: + def inverse_transform(self, dataframe: DataFrame) -> DataFrame: dataframe_copy = dataframe.copy() for column in dataframe_copy.select_dtypes(include=[number]): - dataframe_copy[column] = self.inverse_transform_series( + dataframe_copy[column] = self._inverse_transform_series( dataframe_copy[column] ) return dataframe_copy From 43f20f7c3d323de75fb7465a76763a4766ad3599 Mon Sep 17 00:00:00 2001 From: Danil Zherebtsov Date: Fri, 30 Aug 2024 23:24:08 +0400 Subject: [PATCH 2/5] fix args to convention --- .../data_processing/scaler/linear_scaler.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/synnax_shared/data_processing/scaler/linear_scaler.py b/src/synnax_shared/data_processing/scaler/linear_scaler.py index 0411e67..a794c7c 100644 --- a/src/synnax_shared/data_processing/scaler/linear_scaler.py +++ b/src/synnax_shared/data_processing/scaler/linear_scaler.py @@ -10,7 +10,7 @@ class LinearScalerDto(TypedDict): class LinearScaler: - def __init__(self, offset: float, divisor: float) -> None: + def __init__(self, feature_range: tuple) -> None: """ Initializes the LinearScaler. E.g. To scale data from -100 to 100 to 0 to 1, the offset would be 100.0 and the divisor would be 200.0. @@ -21,18 +21,16 @@ def __init__(self, offset: float, divisor: float) -> None: divisor (float): The divisor to be applied to the data """ - if divisor == 0: - raise ValueError("Divisor cannot be 0") - self.offset = offset - self.divisor = divisor + self.scale_range_min + self.scale_range_max def _transform_series(self, series: Series) -> Series: float_series = series.astype(float) - return (float_series + self.offset) / self.divisor + return (float_series - self.scale_range_min) / (self.scale_range_max - self.scale_range_min) def _inverse_transform_series(self, series: Series) -> Series: float_series = series.astype(float) - return (float_series * self.divisor) - self.offset + return float_series * (self.scale_range_max - self.scale_range_min) + self.scale_range_min def transform(self, dataframe: DataFrame) -> DataFrame: dataframe_copy = dataframe.copy() From db31778c8f46eeaa596b942fc2cff367b56132ea Mon Sep 17 00:00:00 2001 From: Danil Zherebtsov Date: Fri, 30 Aug 2024 23:39:38 +0400 Subject: [PATCH 3/5] put back the offset and divisor --- .../data_processing/scaler/linear_scaler.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/synnax_shared/data_processing/scaler/linear_scaler.py b/src/synnax_shared/data_processing/scaler/linear_scaler.py index a794c7c..c56efca 100644 --- a/src/synnax_shared/data_processing/scaler/linear_scaler.py +++ b/src/synnax_shared/data_processing/scaler/linear_scaler.py @@ -10,7 +10,7 @@ class LinearScalerDto(TypedDict): class LinearScaler: - def __init__(self, feature_range: tuple) -> None: + def __init__(self, offset: float, divisor: float) -> None: """ Initializes the LinearScaler. E.g. To scale data from -100 to 100 to 0 to 1, the offset would be 100.0 and the divisor would be 200.0. @@ -21,27 +21,29 @@ def __init__(self, feature_range: tuple) -> None: divisor (float): The divisor to be applied to the data """ - self.scale_range_min - self.scale_range_max + if divisor == 0: + raise ValueError("Divisor cannot be 0") + self.offset = offset + self.divisor = divisor def _transform_series(self, series: Series) -> Series: float_series = series.astype(float) - return (float_series - self.scale_range_min) / (self.scale_range_max - self.scale_range_min) + return (float_series + self.offset) / self.divisor def _inverse_transform_series(self, series: Series) -> Series: float_series = series.astype(float) - return float_series * (self.scale_range_max - self.scale_range_min) + self.scale_range_min + return (float_series * self.divisor) - self.offset def transform(self, dataframe: DataFrame) -> DataFrame: dataframe_copy = dataframe.copy() for column in dataframe_copy.select_dtypes(include=[number]): - dataframe_copy[column] = self._transform_series(dataframe_copy[column]) + dataframe_copy[column] = self.transform_series(dataframe_copy[column]) return dataframe_copy def inverse_transform(self, dataframe: DataFrame) -> DataFrame: dataframe_copy = dataframe.copy() for column in dataframe_copy.select_dtypes(include=[number]): - dataframe_copy[column] = self._inverse_transform_series( + dataframe_copy[column] = self.inverse_transform_series( dataframe_copy[column] ) return dataframe_copy From 2592cff758fd872191c00fe209551306434f0f35 Mon Sep 17 00:00:00 2001 From: Danil Zherebtsov Date: Fri, 30 Aug 2024 23:41:28 +0400 Subject: [PATCH 4/5] fix methods names --- src/synnax_shared/data_processing/scaler/linear_scaler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/synnax_shared/data_processing/scaler/linear_scaler.py b/src/synnax_shared/data_processing/scaler/linear_scaler.py index c56efca..0411e67 100644 --- a/src/synnax_shared/data_processing/scaler/linear_scaler.py +++ b/src/synnax_shared/data_processing/scaler/linear_scaler.py @@ -37,13 +37,13 @@ def _inverse_transform_series(self, series: Series) -> Series: def transform(self, dataframe: DataFrame) -> DataFrame: dataframe_copy = dataframe.copy() for column in dataframe_copy.select_dtypes(include=[number]): - dataframe_copy[column] = self.transform_series(dataframe_copy[column]) + dataframe_copy[column] = self._transform_series(dataframe_copy[column]) return dataframe_copy def inverse_transform(self, dataframe: DataFrame) -> DataFrame: dataframe_copy = dataframe.copy() for column in dataframe_copy.select_dtypes(include=[number]): - dataframe_copy[column] = self.inverse_transform_series( + dataframe_copy[column] = self._inverse_transform_series( dataframe_copy[column] ) return dataframe_copy From 059e60c340563fb707337a3c28f29e2b5ab6c714 Mon Sep 17 00:00:00 2001 From: Danil Zherebtsov Date: Fri, 30 Aug 2024 23:46:55 +0400 Subject: [PATCH 5/5] increment version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ef60196..705f75a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "synnax-shared" -version = "1.8.0" +version = "1.9.0" description = "Synnax shared Python pacakges" readme = "README.md" requires-python = ">=3.11"