From c411d95431e22c903eb3a4664e935b3aed6d8034 Mon Sep 17 00:00:00 2001 From: HowToSD Date: Fri, 21 Feb 2025 20:46:14 -0800 Subject: [PATCH] Added Pandas Cov and Corr nodes --- __init__.py | 6 ++++ docs/reference/node_reference.md | 2 ++ docs/reference/pandas_corr.md | 18 ++++++++++++ docs/reference/pandas_cov.md | 17 +++++++++++ modules/pandas_wrapper/pandas_corr.py | 41 +++++++++++++++++++++++++++ modules/pandas_wrapper/pandas_cov.py | 40 ++++++++++++++++++++++++++ pyproject.toml | 2 +- 7 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 docs/reference/pandas_corr.md create mode 100644 docs/reference/pandas_cov.md create mode 100644 modules/pandas_wrapper/pandas_corr.py create mode 100644 modules/pandas_wrapper/pandas_cov.py diff --git a/__init__.py b/__init__.py index 2c2583b..afab70e 100644 --- a/__init__.py +++ b/__init__.py @@ -18,8 +18,10 @@ from .modules.pandas_wrapper.pandas_as_float import PandasAsFloat from .modules.pandas_wrapper.pandas_as_int import PandasAsInt from .modules.pandas_wrapper.pandas_as_string import PandasAsString from .modules.pandas_wrapper.pandas_columns import PandasColumns +from .modules.pandas_wrapper.pandas_corr import PandasCorr from .modules.pandas_wrapper.pandas_cos import PandasCos from .modules.pandas_wrapper.pandas_count import PandasCount +from .modules.pandas_wrapper.pandas_cov import PandasCov 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 @@ -123,8 +125,10 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = { "PandasAsInt": PandasAsInt, "PandasAsString": PandasAsString, "PandasColumns": PandasColumns, + "PandasCorr": PandasCorr, "PandasCos": PandasCos, "PandasCount": PandasCount, + "PandasCov": PandasCov, "PandasCreate": PandasCreate, "PandasCreateWithIndex": PandasCreateWithIndex, "PandasCummax": PandasCummax, @@ -228,8 +232,10 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = { "PandasAsInt": "Pandas As Int", "PandasAsString": "Pandas As String", "PandasColumns": "Pandas Columns", + "PandasCorr": "Pandas Corr", "PandasCos": "Pandas Cos", "PandasCount": "Pandas Count", + "PandasCov": "Pandas Cov", "PandasCreate": "Pandas Create", "PandasCreateWithIndex": "Pandas Create With Index", "PandasCummax": "Pandas Cummax", diff --git a/docs/reference/node_reference.md b/docs/reference/node_reference.md index e60bcea..38f9dee 100644 --- a/docs/reference/node_reference.md +++ b/docs/reference/node_reference.md @@ -111,7 +111,9 @@ ## Summary statistics | Node | Description | | --- | --- | +| [Pandas Corr](pandas_corr.md) | Computes the correlation of the DataFrame. You can select from the Pearson, Kendall or Spearman methods. | | [Pandas Count](pandas_count.md) | Computes the count of a pandas DataFrame. | +| [Pandas Cov](pandas_cov.md) | Computes the covariance of the DataFrame. | | [Pandas Max](pandas_max.md) | Computes the max of a pandas DataFrame. | | [Pandas Mean](pandas_mean.md) | Computes the mean of a pandas DataFrame. | | [Pandas Median](pandas_median.md) | Computes the median of a pandas DataFrame. | diff --git a/docs/reference/pandas_corr.md b/docs/reference/pandas_corr.md new file mode 100644 index 0000000..1c45d3f --- /dev/null +++ b/docs/reference/pandas_corr.md @@ -0,0 +1,18 @@ +# Pandas Corr +Computes the correlation of the DataFrame. You can select from the Pearson, Kendall or Spearman methods. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| method | | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Summary statistics + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_cov.md b/docs/reference/pandas_cov.md new file mode 100644 index 0000000..9022fa3 --- /dev/null +++ b/docs/reference/pandas_cov.md @@ -0,0 +1,17 @@ +# Pandas Cov +Computes the covariance of the DataFrame. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Summary statistics + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/modules/pandas_wrapper/pandas_corr.py b/modules/pandas_wrapper/pandas_corr.py new file mode 100644 index 0000000..4b15b23 --- /dev/null +++ b/modules/pandas_wrapper/pandas_corr.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import pandas as pd + + +class PandasCorr: + """ + Computes the correlation of the DataFrame. You can select from the Pearson, Kendall or Spearman methods. + + category: Summary statistics + """ + + @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", {}), + "method": (("pearson", "kendall", "spearman"),) + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, method: str) -> tuple: + """ + Computes the correlation of the DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + + Returns: + tuple: A tuple containing the result. + """ + return (dataframe.corr(method),) diff --git a/modules/pandas_wrapper/pandas_cov.py b/modules/pandas_wrapper/pandas_cov.py new file mode 100644 index 0000000..52e8613 --- /dev/null +++ b/modules/pandas_wrapper/pandas_cov.py @@ -0,0 +1,40 @@ +from typing import Any, Dict +import pandas as pd + + +class PandasCov: + """ + Computes the covariance of the DataFrame. + + category: Summary statistics + """ + + @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", {}) + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame) -> tuple: + """ + Computes the covariance of the DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + + Returns: + tuple: A tuple containing the result. + """ + return (dataframe.cov(),) diff --git a/pyproject.toml b/pyproject.toml index 4cd4f41..303e620 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.18" +version = "1.1.19" license = {file = "LICENSE"} [project.urls]