Wrapped json strings with StringIO to address deprecation warnings

This commit is contained in:
HowToSD
2025-02-13 16:59:46 -08:00
parent 9755ed6aac
commit 9aec9f2b6b
13 changed files with 25 additions and 14 deletions
+2 -1
View File
@@ -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()
+2 -1
View File
@@ -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()
+2 -1
View File
@@ -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()
+2 -1
View File
@@ -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(),)
+3 -2
View File
@@ -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(),)
+1
View File
@@ -1,4 +1,5 @@
from typing import Any, Dict
from io import StringIO
import pandas as pd
+2 -1
View File
@@ -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(",")]
+2 -2
View File
@@ -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)
+2 -1
View File
@@ -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(
+2 -1
View File
@@ -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)
+2 -1
View File
@@ -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()
+2 -1
View File
@@ -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),)
+1 -1
View File
@@ -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]