diff --git a/modules/matplotlib/mpl_bar.py b/modules/matplotlib/mpl_bar.py index 4cd8bb6..607b2d7 100644 --- a/modules/matplotlib/mpl_bar.py +++ b/modules/matplotlib/mpl_bar.py @@ -1,5 +1,6 @@ from typing import Any, Dict from matplotlib import pyplot as plt +from io import StringIO import pandas as pd from .common import common_input_types from .util import plot_post_steps @@ -49,7 +50,7 @@ class MPLBar: tuple: A tuple containing the image tensor representation of the plot. """ # Deserialize JSON string to DataFrame - df = pd.read_json(dataframe_json) + df = pd.read_json(StringIO(dataframe_json)) # Create the plot fig, ax = plt.subplots() diff --git a/modules/matplotlib/mpl_line.py b/modules/matplotlib/mpl_line.py index c351752..8ea5c3a 100644 --- a/modules/matplotlib/mpl_line.py +++ b/modules/matplotlib/mpl_line.py @@ -1,5 +1,6 @@ from typing import Any, Dict from matplotlib import pyplot as plt +from io import StringIO import pandas as pd from .common import common_input_types from .util import plot_post_steps @@ -49,7 +50,7 @@ class MPLLine: tuple: A tuple containing the image tensor representation of the plot. """ # Deserialize JSON string to DataFrame - df = pd.read_json(dataframe_json) + df = pd.read_json(StringIO(dataframe_json)) # Create the plot fig, ax = plt.subplots() diff --git a/modules/matplotlib/mpl_scatter.py b/modules/matplotlib/mpl_scatter.py index 1078199..6c9b3bf 100644 --- a/modules/matplotlib/mpl_scatter.py +++ b/modules/matplotlib/mpl_scatter.py @@ -1,5 +1,6 @@ from typing import Any, Dict from matplotlib import pyplot as plt +from io import StringIO import pandas as pd from .common import common_input_types from .util import plot_post_steps @@ -49,7 +50,7 @@ class MPLScatter: tuple: A tuple containing the image tensor representation of the plot. """ # Deserialize JSON string to DataFrame - df = pd.read_json(dataframe_json) + df = pd.read_json(StringIO(dataframe_json)) # Create the plot fig, ax = plt.subplots() diff --git a/modules/pandas/pandas_head.py b/modules/pandas/pandas_head.py index 10df91d..a2bf95a 100644 --- a/modules/pandas/pandas_head.py +++ b/modules/pandas/pandas_head.py @@ -1,4 +1,5 @@ from typing import Any, Dict +from io import StringIO import pandas as pd @@ -39,6 +40,6 @@ class PandasHead: tuple: A tuple containing a JSON string of the resulting DataFrame. """ # Deserialize JSON string to DataFrame - df = pd.read_json(dataframe_json) + df = pd.read_json(StringIO(dataframe_json)) df2 = df.head(rows) return (df2.to_json(),) diff --git a/modules/pandas/pandas_join.py b/modules/pandas/pandas_join.py index 1c2afde..423cd0f 100644 --- a/modules/pandas/pandas_join.py +++ b/modules/pandas/pandas_join.py @@ -1,4 +1,5 @@ from typing import Any, Dict +from io import StringIO import pandas as pd @@ -43,8 +44,8 @@ class PandasJoin: tuple: A tuple containing a JSON string of the merged DataFrame. """ # Deserialize JSON string to DataFrame - df_left = pd.read_json(left_dataframe_json) - df_right = pd.read_json(right_dataframe_json) + df_left = pd.read_json(StringIO(left_dataframe_json)) + df_right = pd.read_json(StringIO(right_dataframe_json)) df_out = pd.merge(df_left, df_right, on=on_column_name, how=join_method) return (df_out.to_json(),) diff --git a/modules/pandas/pandas_load_csv.py b/modules/pandas/pandas_load_csv.py index fdf76eb..969f28c 100644 --- a/modules/pandas/pandas_load_csv.py +++ b/modules/pandas/pandas_load_csv.py @@ -1,4 +1,5 @@ from typing import Any, Dict +from io import StringIO import pandas as pd diff --git a/modules/pandas/pandas_select_columns.py b/modules/pandas/pandas_select_columns.py index da6ce0a..06be67e 100644 --- a/modules/pandas/pandas_select_columns.py +++ b/modules/pandas/pandas_select_columns.py @@ -1,4 +1,5 @@ from typing import Any, Dict +from io import StringIO import pandas as pd class PandasSelectColumns: @@ -38,7 +39,7 @@ class PandasSelectColumns: tuple: A tuple containing a JSON string of the DataFrame with selected columns. """ # Deserialize JSON string to DataFrame - df = pd.read_json(dataframe_json) + df = pd.read_json(StringIO(dataframe_json)) # Process column names selected_columns = [col.strip() for col in column_names.split(",")] diff --git a/modules/pandas/pandas_select_rows.py b/modules/pandas/pandas_select_rows.py index 7d945fd..30abc7d 100644 --- a/modules/pandas/pandas_select_rows.py +++ b/modules/pandas/pandas_select_rows.py @@ -1,5 +1,5 @@ -import ast from typing import Any, Dict +from io import StringIO import pandas as pd class PandasSelectRows: @@ -39,7 +39,7 @@ class PandasSelectRows: tuple: A tuple containing a JSON string of the filtered DataFrame. """ # Deserialize JSON string to DataFrame - df = pd.read_json(dataframe_json) + df = pd.read_json(StringIO(dataframe_json)) # Apply condition df2 = df.query(condition) diff --git a/modules/pandas/pandas_show_dataframe.py b/modules/pandas/pandas_show_dataframe.py index c798152..d72c199 100644 --- a/modules/pandas/pandas_show_dataframe.py +++ b/modules/pandas/pandas_show_dataframe.py @@ -4,6 +4,7 @@ https://github.com/pythongosssss/ComfyUI-Custom-Scripts/blob/main/py/show_text.p See credit/credit.md for the full license. """ +from io import StringIO import pandas as pd class PandasShowDataFrame: @@ -39,7 +40,7 @@ class PandasShowDataFrame: print("Error: extra_pnginfo[0] is not a dict or missing 'workflow' key") else: # Deserialize JSON string to DataFrame - df = pd.read_json(dataframe_json[0]) + df = pd.read_json(StringIO(dataframe_json[0])) text = [str(df)] # wrap in list workflow = extra_pnginfo[0]["workflow"] node = next( diff --git a/modules/pandas/pandas_sort.py b/modules/pandas/pandas_sort.py index 5a4cbb4..376df0a 100644 --- a/modules/pandas/pandas_sort.py +++ b/modules/pandas/pandas_sort.py @@ -1,4 +1,5 @@ from typing import Any, Dict +from io import StringIO import pandas as pd class PandasSort: @@ -40,7 +41,7 @@ class PandasSort: tuple: A tuple containing a JSON string of the sorted DataFrame. """ # Deserialize JSON string to DataFrame - df = pd.read_json(dataframe_json) + df = pd.read_json(StringIO(dataframe_json)) # Sort DataFrame df2 = df.sort_values(by=column_name, ascending=ascending) diff --git a/modules/pandas/pandas_summary.py b/modules/pandas/pandas_summary.py index eec9f9c..ebecc01 100644 --- a/modules/pandas/pandas_summary.py +++ b/modules/pandas/pandas_summary.py @@ -1,4 +1,5 @@ from typing import Any, Dict +from io import StringIO import pandas as pd class PandasSummary: @@ -36,7 +37,7 @@ class PandasSummary: tuple: A tuple containing a string representation of the DataFrame summary. """ # Deserialize JSON string to DataFrame - df = pd.read_json(dataframe_json) + df = pd.read_json(StringIO(dataframe_json)) # Perform summary operation summary = df.describe() diff --git a/modules/pandas/pandas_to_string.py b/modules/pandas/pandas_to_string.py index 8349fad..3c28fc2 100644 --- a/modules/pandas/pandas_to_string.py +++ b/modules/pandas/pandas_to_string.py @@ -1,4 +1,5 @@ from typing import Any, Dict +from io import StringIO import pandas as pd class PandasToString: @@ -36,5 +37,5 @@ class PandasToString: tuple: A tuple containing the string representation of the DataFrame. """ # Deserialize JSON string to DataFrame - df = pd.read_json(dataframe_json) + df = pd.read_json(StringIO(dataframe_json)) return (str(df),) diff --git a/pyproject.toml b/pyproject.toml index 58d320f..f7f0965 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.0.3" +version = "1.0.4" license = {file = "LICENSE"} [project.urls]