From 731436837f560d181e456529b961d444da896ae8 Mon Sep 17 00:00:00 2001 From: HowToSD Date: Thu, 20 Feb 2025 07:46:43 -0800 Subject: [PATCH] Added Pandas Cummax, Cummin, Cumprod, Cumsum nodes. --- __init__.py | 12 ++++++ docs/reference/node_reference.md | 7 ++++ docs/reference/pandas_cummax.md | 18 +++++++++ docs/reference/pandas_cummin.md | 18 +++++++++ docs/reference/pandas_cumprod.md | 18 +++++++++ docs/reference/pandas_cumsum.md | 18 +++++++++ modules/pandas_wrapper/pandas_cummax.py | 48 ++++++++++++++++++++++++ modules/pandas_wrapper/pandas_cummin.py | 48 ++++++++++++++++++++++++ modules/pandas_wrapper/pandas_cumprod.py | 48 ++++++++++++++++++++++++ modules/pandas_wrapper/pandas_cumsum.py | 48 ++++++++++++++++++++++++ pyproject.toml | 2 +- 11 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 docs/reference/pandas_cummax.md create mode 100644 docs/reference/pandas_cummin.md create mode 100644 docs/reference/pandas_cumprod.md create mode 100644 docs/reference/pandas_cumsum.md create mode 100644 modules/pandas_wrapper/pandas_cummax.py create mode 100644 modules/pandas_wrapper/pandas_cummin.py create mode 100644 modules/pandas_wrapper/pandas_cumprod.py create mode 100644 modules/pandas_wrapper/pandas_cumsum.py diff --git a/__init__.py b/__init__.py index a144df1..fd25f16 100644 --- a/__init__.py +++ b/__init__.py @@ -18,6 +18,10 @@ from .modules.pandas_wrapper.pandas_columns import PandasColumns from .modules.pandas_wrapper.pandas_count import PandasCount from .modules.pandas_wrapper.pandas_create import PandasCreate from .modules.pandas_wrapper.pandas_create_with_index import PandasCreateWithIndex +from .modules.pandas_wrapper.pandas_cummax import PandasCummax +from .modules.pandas_wrapper.pandas_cummin import PandasCummin +from .modules.pandas_wrapper.pandas_cumprod import PandasCumprod +from .modules.pandas_wrapper.pandas_cumsum import PandasCumsum from .modules.pandas_wrapper.pandas_div import PandasDiv from .modules.pandas_wrapper.pandas_div_series import PandasDivSeries from .modules.pandas_wrapper.pandas_dropna import PandasDropNA @@ -98,6 +102,10 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = { "PandasCount": PandasCount, "PandasCreate": PandasCreate, "PandasCreateWithIndex": PandasCreateWithIndex, + "PandasCummax": PandasCummax, + "PandasCummin": PandasCummin, + "PandasCumprod": PandasCumprod, + "PandasCumsum": PandasCumsum, "PandasDiv": PandasDiv, "PandasDivSeries": PandasDivSeries, "PandasDropNA": PandasDropNA, @@ -181,6 +189,10 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = { "PandasCount": "Pandas Count", "PandasCreate": "Pandas Create", "PandasCreateWithIndex": "Pandas Create With Index", + "PandasCummax": "Pandas Cummax", + "PandasCummin": "Pandas Cummin", + "PandasCumprod": "Pandas Cumprod", + "PandasCumsum": "Pandas Cumsum", "PandasDiv": "Pandas Div", "PandasDivSeries": "Pandas Div Series", "PandasDropNA": "Pandas Drop NA", diff --git a/docs/reference/node_reference.md b/docs/reference/node_reference.md index f763f28..97b065e 100644 --- a/docs/reference/node_reference.md +++ b/docs/reference/node_reference.md @@ -16,6 +16,13 @@ | [Pandas Pow Series](pandas_pow_series.md) | Raises a Pandas DataFrame to the power of a Pandas Series. | | [Pandas Sub](pandas_sub.md) | Subtracts a Pandas DataFrame from another DataFrame. | | [Pandas Sub Series](pandas_sub_series.md) | Subtracts a Pandas Series from a Pandas DataFrame. | +## Cumulative calculations +| Node | Description | +| --- | --- | +| [Pandas Cummax](pandas_cummax.md) | Computes the cummax (cumulative max) of the DataFrame. | +| [Pandas Cummin](pandas_cummin.md) | Computes the cummin (cumulative minimum) of the DataFrame. | +| [Pandas Cumprod](pandas_cumprod.md) | Computes the cumprod (cumulative product) of the DataFrame. | +| [Pandas Cumsum](pandas_cumsum.md) | Computes the cumsum (cumulative sum) of the DataFrame. | ## Data cleansing | Node | Description | | --- | --- | diff --git a/docs/reference/pandas_cummax.md b/docs/reference/pandas_cummax.md new file mode 100644 index 0000000..4328bb1 --- /dev/null +++ b/docs/reference/pandas_cummax.md @@ -0,0 +1,18 @@ +# Pandas Cummax +Computes the cummax (cumulative max) of the DataFrame. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| axis | | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Cumulative calculations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_cummin.md b/docs/reference/pandas_cummin.md new file mode 100644 index 0000000..d5447b7 --- /dev/null +++ b/docs/reference/pandas_cummin.md @@ -0,0 +1,18 @@ +# Pandas Cummin +Computes the cummin (cumulative minimum) of the DataFrame. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| axis | | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Cumulative calculations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_cumprod.md b/docs/reference/pandas_cumprod.md new file mode 100644 index 0000000..146a370 --- /dev/null +++ b/docs/reference/pandas_cumprod.md @@ -0,0 +1,18 @@ +# Pandas Cumprod +Computes the cumprod (cumulative product) of the DataFrame. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| axis | | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Cumulative calculations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_cumsum.md b/docs/reference/pandas_cumsum.md new file mode 100644 index 0000000..0da682e --- /dev/null +++ b/docs/reference/pandas_cumsum.md @@ -0,0 +1,18 @@ +# Pandas Cumsum +Computes the cumsum (cumulative sum) of the DataFrame. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| axis | | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Cumulative calculations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/modules/pandas_wrapper/pandas_cummax.py b/modules/pandas_wrapper/pandas_cummax.py new file mode 100644 index 0000000..255bdad --- /dev/null +++ b/modules/pandas_wrapper/pandas_cummax.py @@ -0,0 +1,48 @@ +from typing import Any, Dict +import pandas as pd + + +class PandasCummax: + """ + Computes the cummax (cumulative max) of the DataFrame. + + category: Cumulative calculations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "axis": (("index", "columns"),), + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, axis: str) -> tuple: + """ + Computes the cummax (cumulative max) of the DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + axis (str): Specify the direction to compute: Index (row label) or column label. + + Returns: + tuple: A tuple containing a JSON string of the renamed DataFrame. + """ + if axis=="index": + df_out = dataframe.cummax(axis=0) + elif axis=="columns": + df_out = dataframe.cummax(axis=1) + else: + raise ValueError("Invalid axis. Only index or columns are supported.") + return (df_out,) diff --git a/modules/pandas_wrapper/pandas_cummin.py b/modules/pandas_wrapper/pandas_cummin.py new file mode 100644 index 0000000..eafacb7 --- /dev/null +++ b/modules/pandas_wrapper/pandas_cummin.py @@ -0,0 +1,48 @@ +from typing import Any, Dict +import pandas as pd + + +class PandasCummin: + """ + Computes the cummin (cumulative minimum) of the DataFrame. + + category: Cumulative calculations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "axis": (("index", "columns"),), + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, axis: str) -> tuple: + """ + Computes the cummin (cumulative minimum) of the DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + axis (str): Specify the direction to compute: Index (row label) or column label. + + Returns: + tuple: A tuple containing a JSON string of the renamed DataFrame. + """ + if axis=="index": + df_out = dataframe.cummin(axis=0) + elif axis=="columns": + df_out = dataframe.cummin(axis=1) + else: + raise ValueError("Invalid axis. Only index or columns are supported.") + return (df_out,) diff --git a/modules/pandas_wrapper/pandas_cumprod.py b/modules/pandas_wrapper/pandas_cumprod.py new file mode 100644 index 0000000..6053e9c --- /dev/null +++ b/modules/pandas_wrapper/pandas_cumprod.py @@ -0,0 +1,48 @@ +from typing import Any, Dict +import pandas as pd + + +class PandasCumprod: + """ + Computes the cumprod (cumulative product) of the DataFrame. + + category: Cumulative calculations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "axis": (("index", "columns"),), + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, axis: str) -> tuple: + """ + Computes the cumprod (cumulative product) of the DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + axis (str): Specify the direction to compute: Index (row label) or column label. + + Returns: + tuple: A tuple containing a JSON string of the renamed DataFrame. + """ + if axis=="index": + df_out = dataframe.cumprod(axis=0) + elif axis=="columns": + df_out = dataframe.cumprod(axis=1) + else: + raise ValueError("Invalid axis. Only index or columns are supported.") + return (df_out,) diff --git a/modules/pandas_wrapper/pandas_cumsum.py b/modules/pandas_wrapper/pandas_cumsum.py new file mode 100644 index 0000000..c0714b4 --- /dev/null +++ b/modules/pandas_wrapper/pandas_cumsum.py @@ -0,0 +1,48 @@ +from typing import Any, Dict +import pandas as pd + + +class PandasCumsum: + """ + Computes the cumsum (cumulative sum) of the DataFrame. + + category: Cumulative calculations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "axis": (("index", "columns"),), + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, axis: str) -> tuple: + """ + Computes the cumsum (cumulative sum) of the DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + axis (str): Specify the direction to compute: Index (row label) or column label. + + Returns: + tuple: A tuple containing a JSON string of the renamed DataFrame. + """ + if axis=="index": + df_out = dataframe.cumsum(axis=0) + elif axis=="columns": + df_out = dataframe.cumsum(axis=1) + else: + raise ValueError("Invalid axis. Only index or columns are supported.") + return (df_out,) diff --git a/pyproject.toml b/pyproject.toml index 87fb4bf..268b811 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "data-analysis" description = "Data analysis custom modules for ComfyUI - Use Pandas & Matplotlib within ComfyUI" -version = "1.1.10" +version = "1.1.11" license = {file = "LICENSE"} [project.urls]