From be88fd6caa14463d06731e12f80e5591965c8022 Mon Sep 17 00:00:00 2001 From: HowToSD Date: Wed, 5 Mar 2025 18:25:21 -0800 Subject: [PATCH] Added Pandas at, iat getter and setter nodes. --- __init__.py | 72 ++++++++++++++++++- docs/reference/node_reference.md | 24 ++++++- docs/reference/pandas_at_datetime.md | 21 ++++++ docs/reference/pandas_at_float.md | 21 ++++++ docs/reference/pandas_at_int.md | 21 ++++++ docs/reference/pandas_at_set_datetime.md | 24 +++++++ docs/reference/pandas_at_set_float.md | 24 +++++++ docs/reference/pandas_at_set_int.md | 24 +++++++ docs/reference/pandas_at_set_string.md | 24 +++++++ ...as_loc_cell_str.md => pandas_at_string.md} | 2 +- docs/reference/pandas_iat_datetime.md | 19 +++++ docs/reference/pandas_iat_float.md | 19 +++++ docs/reference/pandas_iat_int.md | 19 +++++ docs/reference/pandas_iat_set_datetime.md | 22 ++++++ docs/reference/pandas_iat_set_float.md | 22 ++++++ docs/reference/pandas_iat_set_int.md | 22 ++++++ docs/reference/pandas_iat_set_string.md | 22 ++++++ docs/reference/pandas_iat_string.md | 19 +++++ docs/reference/pandas_loc_cell_string.md | 21 ++++++ docs/reference/ptn_conv_model_def.md | 17 ----- docs/reference/ptn_linear_model_def.md | 20 ------ docs/reference/py_datetime_to_string.md | 20 ++++++ docs/reference/py_float_to_string.md | 17 +++++ docs/reference/py_int_to_string.md | 17 +++++ docs/reference/py_string_to_datetime.md | 20 ++++++ docs/reference/py_string_to_float.md | 17 +++++ docs/reference/py_string_to_int.md | 17 +++++ modules/cda/py_datetime_to_string.py | 43 +++++++++++ modules/cda/py_float_to_string.py | 40 +++++++++++ modules/cda/py_int_to_string.py | 40 +++++++++++ modules/cda/py_string_to_datetime.py | 43 +++++++++++ modules/cda/py_string_to_float.py | 40 +++++++++++ modules/cda/py_string_to_int.py | 40 +++++++++++ modules/pandas_wrapper/pandas_at_datetime.py | 57 +++++++++++++++ modules/pandas_wrapper/pandas_at_float.py | 56 +++++++++++++++ modules/pandas_wrapper/pandas_at_int.py | 56 +++++++++++++++ .../pandas_wrapper/pandas_at_set_datetime.py | 62 ++++++++++++++++ modules/pandas_wrapper/pandas_at_set_float.py | 61 ++++++++++++++++ modules/pandas_wrapper/pandas_at_set_int.py | 61 ++++++++++++++++ .../pandas_wrapper/pandas_at_set_string.py | 61 ++++++++++++++++ modules/pandas_wrapper/pandas_at_string.py | 56 +++++++++++++++ modules/pandas_wrapper/pandas_iat_datetime.py | 48 +++++++++++++ modules/pandas_wrapper/pandas_iat_float.py | 46 ++++++++++++ modules/pandas_wrapper/pandas_iat_int.py | 47 ++++++++++++ .../pandas_wrapper/pandas_iat_set_datetime.py | 52 ++++++++++++++ .../pandas_wrapper/pandas_iat_set_float.py | 52 ++++++++++++++ modules/pandas_wrapper/pandas_iat_set_int.py | 52 ++++++++++++++ .../pandas_wrapper/pandas_iat_set_string.py | 52 ++++++++++++++ modules/pandas_wrapper/pandas_iat_string.py | 47 ++++++++++++ ..._cell_str.py => pandas_loc_cell_string.py} | 6 +- pyproject.toml | 2 +- tests/cda/py_datetime_to_string_test.py | 30 ++++++++ tests/cda/py_float_to_string_test.py | 29 ++++++++ tests/cda/py_int_to_string_test.py | 29 ++++++++ tests/cda/py_string_to_datetime_test.py | 30 ++++++++ tests/cda/py_string_to_float_test.py | 29 ++++++++ tests/cda/py_string_to_int_test.py | 29 ++++++++ .../pandas_wrapper/pandas_at_datetime_test.py | 69 ++++++++++++++++++ tests/pandas_wrapper/pandas_at_float_test.py | 68 ++++++++++++++++++ tests/pandas_wrapper/pandas_at_int_test.py | 68 ++++++++++++++++++ .../pandas_at_set_datetime_test.py | 62 ++++++++++++++++ .../pandas_at_set_float_test.py | 61 ++++++++++++++++ .../pandas_wrapper/pandas_at_set_int_test.py | 61 ++++++++++++++++ .../pandas_at_set_string_test.py | 61 ++++++++++++++++ tests/pandas_wrapper/pandas_at_string_test.py | 68 ++++++++++++++++++ .../pandas_iat_datetime_test.py | 55 ++++++++++++++ tests/pandas_wrapper/pandas_iat_float_test.py | 54 ++++++++++++++ tests/pandas_wrapper/pandas_iat_int_test.py | 54 ++++++++++++++ .../pandas_iat_set_datetime_test.py | 47 ++++++++++++ .../pandas_iat_set_float_test.py | 46 ++++++++++++ .../pandas_wrapper/pandas_iat_set_int_test.py | 46 ++++++++++++ .../pandas_iat_set_string_test.py | 46 ++++++++++++ .../pandas_wrapper/pandas_iat_string_test.py | 54 ++++++++++++++ .../pandas_loc_cell_string_test.py | 68 ++++++++++++++++++ ...evaluate_classification_conv_model_test.py | 2 +- 75 files changed, 2826 insertions(+), 47 deletions(-) create mode 100644 docs/reference/pandas_at_datetime.md create mode 100644 docs/reference/pandas_at_float.md create mode 100644 docs/reference/pandas_at_int.md create mode 100644 docs/reference/pandas_at_set_datetime.md create mode 100644 docs/reference/pandas_at_set_float.md create mode 100644 docs/reference/pandas_at_set_int.md create mode 100644 docs/reference/pandas_at_set_string.md rename docs/reference/{pandas_loc_cell_str.md => pandas_at_string.md} (94%) create mode 100644 docs/reference/pandas_iat_datetime.md create mode 100644 docs/reference/pandas_iat_float.md create mode 100644 docs/reference/pandas_iat_int.md create mode 100644 docs/reference/pandas_iat_set_datetime.md create mode 100644 docs/reference/pandas_iat_set_float.md create mode 100644 docs/reference/pandas_iat_set_int.md create mode 100644 docs/reference/pandas_iat_set_string.md create mode 100644 docs/reference/pandas_iat_string.md create mode 100644 docs/reference/pandas_loc_cell_string.md delete mode 100644 docs/reference/ptn_conv_model_def.md delete mode 100644 docs/reference/ptn_linear_model_def.md create mode 100644 docs/reference/py_datetime_to_string.md create mode 100644 docs/reference/py_float_to_string.md create mode 100644 docs/reference/py_int_to_string.md create mode 100644 docs/reference/py_string_to_datetime.md create mode 100644 docs/reference/py_string_to_float.md create mode 100644 docs/reference/py_string_to_int.md create mode 100644 modules/cda/py_datetime_to_string.py create mode 100644 modules/cda/py_float_to_string.py create mode 100644 modules/cda/py_int_to_string.py create mode 100644 modules/cda/py_string_to_datetime.py create mode 100644 modules/cda/py_string_to_float.py create mode 100644 modules/cda/py_string_to_int.py create mode 100644 modules/pandas_wrapper/pandas_at_datetime.py create mode 100644 modules/pandas_wrapper/pandas_at_float.py create mode 100644 modules/pandas_wrapper/pandas_at_int.py create mode 100644 modules/pandas_wrapper/pandas_at_set_datetime.py create mode 100644 modules/pandas_wrapper/pandas_at_set_float.py create mode 100644 modules/pandas_wrapper/pandas_at_set_int.py create mode 100644 modules/pandas_wrapper/pandas_at_set_string.py create mode 100644 modules/pandas_wrapper/pandas_at_string.py create mode 100644 modules/pandas_wrapper/pandas_iat_datetime.py create mode 100644 modules/pandas_wrapper/pandas_iat_float.py create mode 100644 modules/pandas_wrapper/pandas_iat_int.py create mode 100644 modules/pandas_wrapper/pandas_iat_set_datetime.py create mode 100644 modules/pandas_wrapper/pandas_iat_set_float.py create mode 100644 modules/pandas_wrapper/pandas_iat_set_int.py create mode 100644 modules/pandas_wrapper/pandas_iat_set_string.py create mode 100644 modules/pandas_wrapper/pandas_iat_string.py rename modules/pandas_wrapper/{pandas_loc_cell_str.py => pandas_loc_cell_string.py} (94%) create mode 100644 tests/cda/py_datetime_to_string_test.py create mode 100644 tests/cda/py_float_to_string_test.py create mode 100644 tests/cda/py_int_to_string_test.py create mode 100644 tests/cda/py_string_to_datetime_test.py create mode 100644 tests/cda/py_string_to_float_test.py create mode 100644 tests/cda/py_string_to_int_test.py create mode 100644 tests/pandas_wrapper/pandas_at_datetime_test.py create mode 100644 tests/pandas_wrapper/pandas_at_float_test.py create mode 100644 tests/pandas_wrapper/pandas_at_int_test.py create mode 100644 tests/pandas_wrapper/pandas_at_set_datetime_test.py create mode 100644 tests/pandas_wrapper/pandas_at_set_float_test.py create mode 100644 tests/pandas_wrapper/pandas_at_set_int_test.py create mode 100644 tests/pandas_wrapper/pandas_at_set_string_test.py create mode 100644 tests/pandas_wrapper/pandas_at_string_test.py create mode 100644 tests/pandas_wrapper/pandas_iat_datetime_test.py create mode 100644 tests/pandas_wrapper/pandas_iat_float_test.py create mode 100644 tests/pandas_wrapper/pandas_iat_int_test.py create mode 100644 tests/pandas_wrapper/pandas_iat_set_datetime_test.py create mode 100644 tests/pandas_wrapper/pandas_iat_set_float_test.py create mode 100644 tests/pandas_wrapper/pandas_iat_set_int_test.py create mode 100644 tests/pandas_wrapper/pandas_iat_set_string_test.py create mode 100644 tests/pandas_wrapper/pandas_iat_string_test.py create mode 100644 tests/pandas_wrapper/pandas_loc_cell_string_test.py diff --git a/__init__.py b/__init__.py index 8d8af09..716e733 100644 --- a/__init__.py +++ b/__init__.py @@ -7,9 +7,15 @@ from .modules.cda.cda_show_float import CDAShowFloat from .modules.cda.cda_show_int import CDAShowInt from .modules.cda.cda_string_create import CDAStringCreate from .modules.cda.cda_text_create import CDATextCreate +from .modules.cda.py_datetime_to_string import PyDatetimeToString +from .modules.cda.py_float_to_string import PyFloatToString +from .modules.cda.py_int_to_string import PyIntToString from .modules.cda.py_kv_float_create import PyKvFloatCreate from .modules.cda.py_kv_int_create import PyKvIntCreate from .modules.cda.py_kv_string_create import PyKvStringCreate +from .modules.cda.py_string_to_datetime import PyStringToDatetime +from .modules.cda.py_string_to_float import PyStringToFloat +from .modules.cda.py_string_to_int import PyStringToInt from .modules.matplotlib.mpl_bar import MPLBar from .modules.matplotlib.mpl_line import MPLLine from .modules.matplotlib.mpl_pie_chart import MPLPieChart @@ -25,6 +31,14 @@ from .modules.pandas_wrapper.pandas_add_series import PandasAddSeries 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_at_datetime import PandasAtDatetime +from .modules.pandas_wrapper.pandas_at_float import PandasAtFloat +from .modules.pandas_wrapper.pandas_at_int import PandasAtInt +from .modules.pandas_wrapper.pandas_at_set_datetime import PandasAtSetDatetime +from .modules.pandas_wrapper.pandas_at_set_float import PandasAtSetFloat +from .modules.pandas_wrapper.pandas_at_set_int import PandasAtSetInt +from .modules.pandas_wrapper.pandas_at_set_string import PandasAtSetString +from .modules.pandas_wrapper.pandas_at_string import PandasAtString from .modules.pandas_wrapper.pandas_columns import PandasColumns from .modules.pandas_wrapper.pandas_corr import PandasCorr from .modules.pandas_wrapper.pandas_cos import PandasCos @@ -56,6 +70,14 @@ from .modules.pandas_wrapper.pandas_group_by import PandasGroupBy from .modules.pandas_wrapper.pandas_head import PandasHead from .modules.pandas_wrapper.pandas_horizontal_concat import PandasHorizontalConcat from .modules.pandas_wrapper.pandas_horizontal_split import PandasHorizontalSplit +from .modules.pandas_wrapper.pandas_iat_datetime import PandasIatDatetime +from .modules.pandas_wrapper.pandas_iat_float import PandasIatFloat +from .modules.pandas_wrapper.pandas_iat_int import PandasIatInt +from .modules.pandas_wrapper.pandas_iat_set_datetime import PandasIatSetDatetime +from .modules.pandas_wrapper.pandas_iat_set_float import PandasIatSetFloat +from .modules.pandas_wrapper.pandas_iat_set_int import PandasIatSetInt +from .modules.pandas_wrapper.pandas_iat_set_string import PandasIatSetString +from .modules.pandas_wrapper.pandas_iat_string import PandasIatString from .modules.pandas_wrapper.pandas_iloc_row_series import PandasIlocRowSeries from .modules.pandas_wrapper.pandas_iloc_rows_dataframe import PandasIlocRowsDataFrame from .modules.pandas_wrapper.pandas_iloc_rows_slice_dataframe import PandasIlocRowsSliceDataFrame @@ -70,7 +92,7 @@ from .modules.pandas_wrapper.pandas_load_csv_with_index import PandasLoadCSVWith from .modules.pandas_wrapper.pandas_load_excel import PandasLoadExcel from .modules.pandas_wrapper.pandas_load_html import PandasLoadHTML from .modules.pandas_wrapper.pandas_load_json import PandasLoadJSON -from .modules.pandas_wrapper.pandas_loc_cell_str import PandasLocCellStr +from .modules.pandas_wrapper.pandas_loc_cell_string import PandasLocCellString from .modules.pandas_wrapper.pandas_loc_row_multiindex_dataframe import PandasLocRowMultiIndexDataFrame from .modules.pandas_wrapper.pandas_loc_row_series import PandasLocRowSeries from .modules.pandas_wrapper.pandas_log import PandasLog @@ -259,6 +281,14 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = { "PandasAsFloat": PandasAsFloat, "PandasAsInt": PandasAsInt, "PandasAsString": PandasAsString, + "PandasAtDatetime": PandasAtDatetime, + "PandasAtFloat": PandasAtFloat, + "PandasAtInt": PandasAtInt, + "PandasAtSetDatetime": PandasAtSetDatetime, + "PandasAtSetFloat": PandasAtSetFloat, + "PandasAtSetInt": PandasAtSetInt, + "PandasAtSetString": PandasAtSetString, + "PandasAtString": PandasAtString, "PandasColumns": PandasColumns, "PandasCorr": PandasCorr, "PandasCos": PandasCos, @@ -290,6 +320,14 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = { "PandasHead": PandasHead, "PandasHorizontalConcat": PandasHorizontalConcat, "PandasHorizontalSplit": PandasHorizontalSplit, + "PandasIatDatetime": PandasIatDatetime, + "PandasIatFloat": PandasIatFloat, + "PandasIatInt": PandasIatInt, + "PandasIatSetDatetime": PandasIatSetDatetime, + "PandasIatSetFloat": PandasIatSetFloat, + "PandasIatSetInt": PandasIatSetInt, + "PandasIatSetString": PandasIatSetString, + "PandasIatString": PandasIatString, "PandasIlocRowSeries": PandasIlocRowSeries, "PandasIlocRowsDataFrame": PandasIlocRowsDataFrame, "PandasIlocRowsSliceDataFrame": PandasIlocRowsSliceDataFrame, @@ -304,7 +342,7 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = { "PandasLoadExcel": PandasLoadExcel, "PandasLoadHTML": PandasLoadHTML, "PandasLoadJSON": PandasLoadJSON, - "PandasLocCellStr": PandasLocCellStr, + "PandasLocCellString": PandasLocCellString, "PandasLocRowMultiIndexDataFrame": PandasLocRowMultiIndexDataFrame, "PandasLocRowSeries": PandasLocRowSeries, "PandasLog": PandasLog, @@ -455,9 +493,15 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = { "PtvDataset": PtvDataset, "PtvDatasetLoader": PtvDatasetLoader, "PtvTransformsToTensor": PtvTransformsToTensor, + "PyDatetimeToString": PyDatetimeToString, + "PyFloatToString": PyFloatToString, + "PyIntToString": PyIntToString, "PyKvFloatCreate": PyKvFloatCreate, "PyKvIntCreate": PyKvIntCreate, "PyKvStringCreate": PyKvStringCreate, + "PyStringToDatetime": PyStringToDatetime, + "PyStringToFloat": PyStringToFloat, + "PyStringToInt": PyStringToInt, "SNSBar": SNSBar, "SNSBoxplot": SNSBoxplot, "SNSHeatmap": SNSHeatmap, @@ -496,6 +540,14 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = { "PandasAsFloat": "Pandas As Float", "PandasAsInt": "Pandas As Int", "PandasAsString": "Pandas As String", + "PandasAtDatetime": "Pandas At Datetime", + "PandasAtFloat": "Pandas At Float", + "PandasAtInt": "Pandas At Int", + "PandasAtSetDatetime": "Pandas At Set Datetime", + "PandasAtSetFloat": "Pandas At Set Float", + "PandasAtSetInt": "Pandas At Set Int", + "PandasAtSetString": "Pandas At Set String", + "PandasAtString": "Pandas At String", "PandasColumns": "Pandas Columns", "PandasCorr": "Pandas Corr", "PandasCos": "Pandas Cos", @@ -527,6 +579,14 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = { "PandasHead": "Pandas Head", "PandasHorizontalConcat": "Pandas Horizontal Concat", "PandasHorizontalSplit": "Pandas Horizontal Split", + "PandasIatDatetime": "Pandas Iat Datetime", + "PandasIatFloat": "Pandas Iat Float", + "PandasIatInt": "Pandas Iat Int", + "PandasIatSetDatetime": "Pandas Iat Set Datetime", + "PandasIatSetFloat": "Pandas Iat Set Float", + "PandasIatSetInt": "Pandas Iat Set Int", + "PandasIatSetString": "Pandas Iat Set String", + "PandasIatString": "Pandas Iat String", "PandasIlocRowSeries": "Pandas Iloc Row Series", "PandasIlocRowsDataFrame": "Pandas Iloc Rows DataFrame", "PandasIlocRowsSliceDataFrame": "Pandas Iloc Rows Slice DataFrame", @@ -541,7 +601,7 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = { "PandasLoadExcel": "Pandas Load Excel", "PandasLoadHTML": "Pandas Load HTML", "PandasLoadJSON": "Pandas Load JSON", - "PandasLocCellStr": "Pandas Loc Cell Str", + "PandasLocCellString": "Pandas Loc Cell String", "PandasLocRowMultiIndexDataFrame": "Pandas Loc Row MultiIndex DataFrame", "PandasLocRowSeries": "Pandas Loc Row Series", "PandasLog": "Pandas Log", @@ -692,9 +752,15 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = { "PtvDataset": "Ptv Dataset", "PtvDatasetLoader": "Ptv Dataset Loader", "PtvTransformsToTensor": "Ptv Transforms To Tensor", + "PyDatetimeToString": "Py Datetime To String", + "PyFloatToString": "Py Float To String", + "PyIntToString": "Py Int To String", "PyKvFloatCreate": "Py Kv Float Create", "PyKvIntCreate": "Py Kv Int Create", "PyKvStringCreate": "Py Kv String Create", + "PyStringToDatetime": "Py String To Datetime", + "PyStringToFloat": "Py String To Float", + "PyStringToInt": "Py String To Int", "SNSBar": "SNS Bar Chart", "SNSBoxplot": "SNS Boxplot", "SNSHeatmap": "SNS Heatmap", diff --git a/docs/reference/node_reference.md b/docs/reference/node_reference.md index 6bc1a96..de32f1b 100644 --- a/docs/reference/node_reference.md +++ b/docs/reference/node_reference.md @@ -50,11 +50,19 @@ ## Data subset selection | Node | Description | | --- | --- | +| [Pandas At Datetime](pandas_at_datetime.md) | Selects a cell from a pandas DataFrame and output as a Python datetime.datetime data. | +| [Pandas At Float](pandas_at_float.md) | Selects a cell from a pandas DataFrame and output as a Python float. | +| [Pandas At Int](pandas_at_int.md) | Selects a cell from a pandas DataFrame and output as a Python int. | +| [Pandas At String](pandas_at_string.md) | Selects a cell from a pandas DataFrame and output as a string. | | [Pandas Head](pandas_head.md) | Retrieves the first few rows of a pandas DataFrame. | +| [Pandas Iat Datetime](pandas_iat_datetime.md) | Selects a cell from a pandas DataFrame and output as a Python datetime.datetime data. | +| [Pandas Iat Float](pandas_iat_float.md) | Selects a cell from a pandas DataFrame and output as a Python float. | +| [Pandas Iat Int](pandas_iat_int.md) | Selects a cell from a pandas DataFrame and output as a Python int. | +| [Pandas Iat String](pandas_iat_string.md) | Selects a cell from a pandas DataFrame and output as a string. | | [Pandas Iloc Row Series](pandas_iloc_row_series.md) | Selects a row from a pandas DataFrame and returning it as a Series. | | [Pandas Iloc Rows Data Frame](pandas_iloc_rows_dataframe.md) | Selects rows from a pandas DataFrame and returning it as a DataFrame. | | [Pandas Iloc Rows Slice Data Frame](pandas_iloc_rows_slice_dataframe.md) | Selects rows from a pandas DataFrame using a slice defined by a start and end integer position. The start position is inclusive, while the end position is exclusive. Returns the selected rows as a DataFrame. | -| [Pandas Loc Cell Str](pandas_loc_cell_str.md) | Selects a cell from a pandas DataFrame and output as a string. | +| [Pandas Loc Cell String](pandas_loc_cell_string.md) | Selects a cell from a pandas DataFrame and output as a string. | | [Pandas Loc Row MultiIndex DataFrame](pandas_loc_row_multiindex_dataframe.md) | Selects a row or rows from a pandas DataFrame with MultiIndex and output as a DataFrame. | | [Pandas Loc Row Series](pandas_loc_row_series.md) | Selects a row from a pandas DataFrame and output as a Series. | | [Pandas Select Columns](pandas_select_columns.md) | Selects specific columns from a pandas DataFrame. | @@ -280,9 +288,15 @@ ## Python wrapper | Node | Description | | --- | --- | +| [Py Datetime To String](py_datetime_to_string.md) | Converts a Python datetime.datetime value to a Python string | +| [Py Float To String](py_float_to_string.md) | Converts a Python float value to a Python string | +| [Py Int To String](py_int_to_string.md) | Converts a Python int value to a Python string | | [Py Kv Float Create](py_kv_float_create.md) | Creates a Python dictionary with a string key and a float value. | | [Py Kv Int Create](py_kv_int_create.md) | Creates a Python dictionary with an string key and an integer value. | | [Py Kv String Create](py_kv_string_create.md) | Creates a Python dictionary with a string key and a string value. | +| [Py String To Datetime](py_string_to_datetime.md) | Converts a Python string to a Python datetime.datetime. | +| [Py String To Float](py_string_to_float.md) | Converts a Python string to a float. | +| [Py String To Int](py_string_to_int.md) | Converts a Python string to an int. | ## Summary statistics | Node | Description | | --- | --- | @@ -303,9 +317,17 @@ ## Transformation | Node | Description | | --- | --- | +| [Pandas At Set Datetime](pandas_at_set_datetime.md) | Sets a Python datetime.datetime data in a cell in a pandas DataFrame. | +| [Pandas At Set Float](pandas_at_set_float.md) | Sets a Python float data in a cell in a pandas DataFrame. | +| [Pandas At Set Int](pandas_at_set_int.md) | Sets a Python int data in a cell in a pandas DataFrame. | +| [Pandas At Set String](pandas_at_set_string.md) | Sets a Python string data in a cell in a pandas DataFrame. | | [Pandas Feature Split To Numpy](pandas_feature_split_to_numpy.md) | Splits a Pandas DataFrame into feature Numpy ndarray and label Numpy ndarray. | | [Pandas Horizontal Concat](pandas_horizontal_concat.md) | Horizontally concatenates two pandas DataFrames. | | [Pandas Horizontal Split](pandas_horizontal_split.md) | Horizontally splits a Pandas DataFrame into two pandas DataFrames. | +| [Pandas Iat Set Datetime](pandas_iat_set_datetime.md) | Sets a Python datetime.datetime data in a cell in a pandas DataFrame. | +| [Pandas Iat Set Float](pandas_iat_set_float.md) | Sets a Python float data in a cell from a pandas DataFrame. | +| [Pandas Iat Set Int](pandas_iat_set_int.md) | Sets a Python int data in a cell from a pandas DataFrame. | +| [Pandas Iat Set String](pandas_iat_set_string.md) | Sets a Python string in a cell in a pandas DataFrame. | | [Pandas Join](pandas_join.md) | Merges two pandas DataFrames based on a common column. | | [Pandas Melt](pandas_melt.md) | Performs an unpivot operation (melt) on a pandas DataFrame. | | [Pandas Pivot](pandas_pivot.md) | Computes a pivot table from a pandas DataFrame. | diff --git a/docs/reference/pandas_at_datetime.md b/docs/reference/pandas_at_datetime.md new file mode 100644 index 0000000..6a039cf --- /dev/null +++ b/docs/reference/pandas_at_datetime.md @@ -0,0 +1,21 @@ +# Pandas At Datetime +Selects a cell from a pandas DataFrame and output as a Python datetime.datetime data. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_index | String | +| row_index_type | | +| column_label | String | +| column_label_type | | + +## Output +| Data type | +|---| +| Pydatetime | + +
+Category: Data subset selection + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_at_float.md b/docs/reference/pandas_at_float.md new file mode 100644 index 0000000..5c94ebe --- /dev/null +++ b/docs/reference/pandas_at_float.md @@ -0,0 +1,21 @@ +# Pandas At Float +Selects a cell from a pandas DataFrame and output as a Python float. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_index | String | +| row_index_type | | +| column_label | String | +| column_label_type | | + +## Output +| Data type | +|---| +| Float | + +
+Category: Data subset selection + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_at_int.md b/docs/reference/pandas_at_int.md new file mode 100644 index 0000000..95489ab --- /dev/null +++ b/docs/reference/pandas_at_int.md @@ -0,0 +1,21 @@ +# Pandas At Int +Selects a cell from a pandas DataFrame and output as a Python int. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_index | String | +| row_index_type | | +| column_label | String | +| column_label_type | | + +## Output +| Data type | +|---| +| Int | + +
+Category: Data subset selection + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_at_set_datetime.md b/docs/reference/pandas_at_set_datetime.md new file mode 100644 index 0000000..2dedd96 --- /dev/null +++ b/docs/reference/pandas_at_set_datetime.md @@ -0,0 +1,24 @@ +# Pandas At Set Datetime +Sets a Python datetime.datetime data in a cell in a pandas DataFrame. + +This modifies the input DataFrame in place. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_index | String | +| row_index_type | | +| column_label | String | +| column_label_type | | +| data | Pydatetime | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Transformation + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_at_set_float.md b/docs/reference/pandas_at_set_float.md new file mode 100644 index 0000000..2fce7c7 --- /dev/null +++ b/docs/reference/pandas_at_set_float.md @@ -0,0 +1,24 @@ +# Pandas At Set Float +Sets a Python float data in a cell in a pandas DataFrame. + +This modifies the input DataFrame in place. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_index | String | +| row_index_type | | +| column_label | String | +| column_label_type | | +| data | Float | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Transformation + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_at_set_int.md b/docs/reference/pandas_at_set_int.md new file mode 100644 index 0000000..4f2d96a --- /dev/null +++ b/docs/reference/pandas_at_set_int.md @@ -0,0 +1,24 @@ +# Pandas At Set Int +Sets a Python int data in a cell in a pandas DataFrame. + +This modifies the input DataFrame in place. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_index | String | +| row_index_type | | +| column_label | String | +| column_label_type | | +| data | Int | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Transformation + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_at_set_string.md b/docs/reference/pandas_at_set_string.md new file mode 100644 index 0000000..382069e --- /dev/null +++ b/docs/reference/pandas_at_set_string.md @@ -0,0 +1,24 @@ +# Pandas At Set String +Sets a Python string data in a cell in a pandas DataFrame. + +This modifies the input DataFrame in place. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_index | String | +| row_index_type | | +| column_label | String | +| column_label_type | | +| data | String | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Transformation + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_loc_cell_str.md b/docs/reference/pandas_at_string.md similarity index 94% rename from docs/reference/pandas_loc_cell_str.md rename to docs/reference/pandas_at_string.md index 803d4f3..2fa8771 100644 --- a/docs/reference/pandas_loc_cell_str.md +++ b/docs/reference/pandas_at_string.md @@ -1,4 +1,4 @@ -# Pandas Loc Cell Str +# Pandas At String Selects a cell from a pandas DataFrame and output as a string. ## Input diff --git a/docs/reference/pandas_iat_datetime.md b/docs/reference/pandas_iat_datetime.md new file mode 100644 index 0000000..49b8b8f --- /dev/null +++ b/docs/reference/pandas_iat_datetime.md @@ -0,0 +1,19 @@ +# Pandas Iat Datetime +Selects a cell from a pandas DataFrame and output as a Python datetime.datetime data. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_integer_position | Int | +| column_integer_position | Int | + +## Output +| Data type | +|---| +| Pydatetime | + +
+Category: Data subset selection + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_iat_float.md b/docs/reference/pandas_iat_float.md new file mode 100644 index 0000000..9db4a32 --- /dev/null +++ b/docs/reference/pandas_iat_float.md @@ -0,0 +1,19 @@ +# Pandas Iat Float +Selects a cell from a pandas DataFrame and output as a Python float. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_integer_position | Int | +| column_integer_position | Int | + +## Output +| Data type | +|---| +| Float | + +
+Category: Data subset selection + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_iat_int.md b/docs/reference/pandas_iat_int.md new file mode 100644 index 0000000..66dac7b --- /dev/null +++ b/docs/reference/pandas_iat_int.md @@ -0,0 +1,19 @@ +# Pandas Iat Int +Selects a cell from a pandas DataFrame and output as a Python int. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_integer_position | Int | +| column_integer_position | Int | + +## Output +| Data type | +|---| +| Int | + +
+Category: Data subset selection + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_iat_set_datetime.md b/docs/reference/pandas_iat_set_datetime.md new file mode 100644 index 0000000..2d8d908 --- /dev/null +++ b/docs/reference/pandas_iat_set_datetime.md @@ -0,0 +1,22 @@ +# Pandas Iat Set Datetime +Sets a Python datetime.datetime data in a cell in a pandas DataFrame. + +This modifies the input DataFrame in place. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_integer_position | Int | +| column_integer_position | Int | +| data | Pydatetime | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Transformation + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_iat_set_float.md b/docs/reference/pandas_iat_set_float.md new file mode 100644 index 0000000..3cdfbd6 --- /dev/null +++ b/docs/reference/pandas_iat_set_float.md @@ -0,0 +1,22 @@ +# Pandas Iat Set Float +Sets a Python float data in a cell from a pandas DataFrame. + +This modifies the input DataFrame in place. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_integer_position | Int | +| column_integer_position | Int | +| data | Float | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Transformation + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_iat_set_int.md b/docs/reference/pandas_iat_set_int.md new file mode 100644 index 0000000..e43c89d --- /dev/null +++ b/docs/reference/pandas_iat_set_int.md @@ -0,0 +1,22 @@ +# Pandas Iat Set Int +Sets a Python int data in a cell from a pandas DataFrame. + +This modifies the input DataFrame in place. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_integer_position | Int | +| column_integer_position | Int | +| data | Int | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Transformation + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_iat_set_string.md b/docs/reference/pandas_iat_set_string.md new file mode 100644 index 0000000..f08e416 --- /dev/null +++ b/docs/reference/pandas_iat_set_string.md @@ -0,0 +1,22 @@ +# Pandas Iat Set String +Sets a Python string in a cell in a pandas DataFrame. + +This modifies the input DataFrame in place. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_integer_position | Int | +| column_integer_position | Int | +| data | String | + +## Output +| Data type | +|---| +| DataFrame | + +
+Category: Transformation + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_iat_string.md b/docs/reference/pandas_iat_string.md new file mode 100644 index 0000000..65f09bc --- /dev/null +++ b/docs/reference/pandas_iat_string.md @@ -0,0 +1,19 @@ +# Pandas Iat String +Selects a cell from a pandas DataFrame and output as a string. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_integer_position | Int | +| column_integer_position | Int | + +## Output +| Data type | +|---| +| String | + +
+Category: Data subset selection + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pandas_loc_cell_string.md b/docs/reference/pandas_loc_cell_string.md new file mode 100644 index 0000000..b19efdb --- /dev/null +++ b/docs/reference/pandas_loc_cell_string.md @@ -0,0 +1,21 @@ +# Pandas Loc Cell String +Selects a cell from a pandas DataFrame and output as a string. + +## Input +| Name | Data type | +|---|---| +| dataframe | DataFrame | +| row_index | String | +| row_index_type | | +| column_label | String | +| column_label_type | | + +## Output +| Data type | +|---| +| String | + +
+Category: Data subset selection + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/ptn_conv_model_def.md b/docs/reference/ptn_conv_model_def.md deleted file mode 100644 index 3a253f6..0000000 --- a/docs/reference/ptn_conv_model_def.md +++ /dev/null @@ -1,17 +0,0 @@ -# Conv Single Layer -A single convolutional layer followed by an optional ReLU activation and optional downsampling. - -Shape is tensor of shape `(batch_size, in_channels, height, width)`. - -Args: - in_channels (int): Number of input channels. - out_channels (int): Number of output channels. - kernel_size (int): Size of the convolutional kernel. - padding (int): Padding size for convolution. - downsample (bool): If True, applies a 2x2 MaxPooling layer. - apply_activation (bool, optional): If True, applies ReLU activation. Defaults to True. - -
-Category: Miscellaneous - -ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/ptn_linear_model_def.md b/docs/reference/ptn_linear_model_def.md deleted file mode 100644 index 1841a98..0000000 --- a/docs/reference/ptn_linear_model_def.md +++ /dev/null @@ -1,20 +0,0 @@ -# Dense Model -A multi-layer dense neural network with ReLU activation after each dense layer, except for the final layer. - -Args: - dim_list (List[int]): List of feature dimensions. Should be of length `num_layers + 1`. - bias_list (List[bool]): List indicating whether each layer should have a bias. - num_layers (int): Number of layers in the model. - -Example: - For a three-layer network: - - Layer 1: input -> output1 - - Layer 2: output1 -> output2 - - Layer 3: output2 -> output3 - - `dim_list = [input_dim, output1_dim, output2_dim, output3_dim]` - -
-Category: Miscellaneous - -ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/py_datetime_to_string.md b/docs/reference/py_datetime_to_string.md new file mode 100644 index 0000000..4fa0422 --- /dev/null +++ b/docs/reference/py_datetime_to_string.md @@ -0,0 +1,20 @@ +# Py Datetime To String +Converts a Python datetime.datetime value to a Python string + +Refer to [the Python documentation](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior) for date/time format strings. + +## Input +| Name | Data type | +|---|---| +| value | Pydatetime | +| date_format | String | + +## Output +| Data type | +|---| +| String | + +
+Category: Python wrapper + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/py_float_to_string.md b/docs/reference/py_float_to_string.md new file mode 100644 index 0000000..fc2d8ab --- /dev/null +++ b/docs/reference/py_float_to_string.md @@ -0,0 +1,17 @@ +# Py Float To String +Converts a Python float value to a Python string + +## Input +| Name | Data type | +|---|---| +| value | Float | + +## Output +| Data type | +|---| +| String | + +
+Category: Python wrapper + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/py_int_to_string.md b/docs/reference/py_int_to_string.md new file mode 100644 index 0000000..8d31293 --- /dev/null +++ b/docs/reference/py_int_to_string.md @@ -0,0 +1,17 @@ +# Py Int To String +Converts a Python int value to a Python string + +## Input +| Name | Data type | +|---|---| +| value | Int | + +## Output +| Data type | +|---| +| String | + +
+Category: Python wrapper + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/py_string_to_datetime.md b/docs/reference/py_string_to_datetime.md new file mode 100644 index 0000000..17980e0 --- /dev/null +++ b/docs/reference/py_string_to_datetime.md @@ -0,0 +1,20 @@ +# Py String To Datetime +Converts a Python string to a Python datetime.datetime. + +Refer to [the Python documentation](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior) for date/time format strings. + +## Input +| Name | Data type | +|---|---| +| value | String | +| date_format | String | + +## Output +| Data type | +|---| +| Pydatetime | + +
+Category: Python wrapper + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/py_string_to_float.md b/docs/reference/py_string_to_float.md new file mode 100644 index 0000000..cd008fe --- /dev/null +++ b/docs/reference/py_string_to_float.md @@ -0,0 +1,17 @@ +# Py String To Float +Converts a Python string to a float. + +## Input +| Name | Data type | +|---|---| +| value | String | + +## Output +| Data type | +|---| +| Float | + +
+Category: Python wrapper + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/py_string_to_int.md b/docs/reference/py_string_to_int.md new file mode 100644 index 0000000..130b48f --- /dev/null +++ b/docs/reference/py_string_to_int.md @@ -0,0 +1,17 @@ +# Py String To Int +Converts a Python string to an int. + +## Input +| Name | Data type | +|---|---| +| value | String | + +## Output +| Data type | +|---| +| Int | + +
+Category: Python wrapper + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/modules/cda/py_datetime_to_string.py b/modules/cda/py_datetime_to_string.py new file mode 100644 index 0000000..f0302dd --- /dev/null +++ b/modules/cda/py_datetime_to_string.py @@ -0,0 +1,43 @@ +from typing import Any, Dict +from datetime import datetime + +class PyDatetimeToString: + """ + Converts a Python datetime.datetime value to a Python string + + Refer to [the Python documentation](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior) for date/time format strings. + + category: Python wrapper + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `create` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "value": ("PYDATETIME", {}), + "date_format": ("STRING", {"default":"%Y-%m-%d %H:%M:%S", "multiline": False}), + } + } + + RETURN_TYPES: tuple = ("STRING",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, value: datetime, date_format: str) -> tuple: + """ + Converts a Python datetime.datetime value to a Python string + + Args: + value (str): String value to convert. + + Returns: + tuple: A tuple containing the converted value. + """ + return (datetime.strftime(value, date_format),) + \ No newline at end of file diff --git a/modules/cda/py_float_to_string.py b/modules/cda/py_float_to_string.py new file mode 100644 index 0000000..b19118e --- /dev/null +++ b/modules/cda/py_float_to_string.py @@ -0,0 +1,40 @@ +from typing import Any, Dict +import datetime + +class PyFloatToString: + """ + Converts a Python float value to a Python string + + category: Python wrapper + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `create` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "value": ("FLOAT", {"default": 0, "min": -2**63, "max": 2**63, "step": 0.00000001}) + } + } + + RETURN_TYPES: tuple = ("STRING",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, value: float) -> tuple: + """ + Converts a Python float value to a Python string + + Args: + value (float): Float value to convert. + + Returns: + tuple: A tuple containing the converted value. + """ + return (str(value),) + \ No newline at end of file diff --git a/modules/cda/py_int_to_string.py b/modules/cda/py_int_to_string.py new file mode 100644 index 0000000..e4b46b0 --- /dev/null +++ b/modules/cda/py_int_to_string.py @@ -0,0 +1,40 @@ +from typing import Any, Dict + + +class PyIntToString: + """ + Converts a Python int value to a Python string + + category: Python wrapper + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `create` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "value": ("INT", {"default": 0, "min": -2**31, "max": 2**31}) + } + } + + RETURN_TYPES: tuple = ("STRING",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, value: int) -> tuple: + """ + Converts a Python int value to a Python string + + Args: + value (int): Int value to convert. + + Returns: + tuple: A tuple containing the converted value. + """ + return (str(value),) + \ No newline at end of file diff --git a/modules/cda/py_string_to_datetime.py b/modules/cda/py_string_to_datetime.py new file mode 100644 index 0000000..472f2c7 --- /dev/null +++ b/modules/cda/py_string_to_datetime.py @@ -0,0 +1,43 @@ +from typing import Any, Dict +from datetime import datetime + +class PyStringToDatetime: + """ + Converts a Python string to a Python datetime.datetime. + + Refer to [the Python documentation](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior) for date/time format strings. + + category: Python wrapper + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `create` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "value": ("STRING", {"default":"", "multiline": False}), + "date_format": ("STRING", {"default":"%Y-%m-%d %H:%M:%S", "multiline": False}), + } + } + + RETURN_TYPES: tuple = ("PYDATETIME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, value: str, date_format: str) -> tuple: + """ + Converts a Python string to Python datetime.datetime. + + Args: + value (str): String value to convert. + + Returns: + tuple: A tuple containing the dictionary. + """ + return (datetime.strptime(value, date_format),) + \ No newline at end of file diff --git a/modules/cda/py_string_to_float.py b/modules/cda/py_string_to_float.py new file mode 100644 index 0000000..8b982ca --- /dev/null +++ b/modules/cda/py_string_to_float.py @@ -0,0 +1,40 @@ +from typing import Any, Dict + + +class PyStringToFloat: + """ + Converts a Python string to a float. + + category: Python wrapper + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `create` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "value": ("STRING", {"default":"", "multiline": False}) + } + } + + RETURN_TYPES: tuple = ("FLOAT",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, value: str) -> tuple: + """ + Converts a Python string to a float. + + Args: + value (str): String value to convert. + + Returns: + tuple: A tuple containing the dictionary. + """ + return (float(value),) + \ No newline at end of file diff --git a/modules/cda/py_string_to_int.py b/modules/cda/py_string_to_int.py new file mode 100644 index 0000000..bf8679d --- /dev/null +++ b/modules/cda/py_string_to_int.py @@ -0,0 +1,40 @@ +from typing import Any, Dict + + +class PyStringToInt: + """ + Converts a Python string to an int. + + category: Python wrapper + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `create` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "value": ("STRING", {"default":"", "multiline": False}) + } + } + + RETURN_TYPES: tuple = ("INT",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, value: str) -> tuple: + """ + Converts a Python string to an int. + + Args: + value (str): String value to convert. + + Returns: + tuple: A tuple containing the dictionary. + """ + return (int(value),) + \ No newline at end of file diff --git a/modules/pandas_wrapper/pandas_at_datetime.py b/modules/pandas_wrapper/pandas_at_datetime.py new file mode 100644 index 0000000..5de8179 --- /dev/null +++ b/modules/pandas_wrapper/pandas_at_datetime.py @@ -0,0 +1,57 @@ +from typing import Any, Dict +import pandas as pd +import datetime + + +class PandasAtDatetime: + """ + Selects a cell from a pandas DataFrame and output as a Python datetime.datetime data. + + category: Data subset selection + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_index": ("STRING", {"default": ""}), + "row_index_type":(("string", "int"),), + "column_label": ("STRING", {"default": ""}), + "column_label_type":(("string", "int"),) + } + } + + RETURN_TYPES: tuple = ("PYDATETIME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_index: str, + row_index_type: str, + column_label: str, + column_label_type: str) -> tuple: + """ + Selects specific cell from a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_index (str): The row index (row label) for the cell. + row_index_type (str): The data type of the row index. + column_label (str): The column label for the cell. + column_label_type (str): The data type of the column label. + + Returns: + tuple: A tuple containing the value of the cell in string. + """ + row_index = int(row_index) if row_index_type == "int" else row_index + column_label = int(column_label) if column_label_type == "int" else column_label + + value = dataframe.at[row_index, column_label] + return (value.to_pydatetime(),) diff --git a/modules/pandas_wrapper/pandas_at_float.py b/modules/pandas_wrapper/pandas_at_float.py new file mode 100644 index 0000000..dbc67c9 --- /dev/null +++ b/modules/pandas_wrapper/pandas_at_float.py @@ -0,0 +1,56 @@ +from typing import Any, Dict +from io import StringIO +import pandas as pd + +class PandasAtFloat: + """ + Selects a cell from a pandas DataFrame and output as a Python float. + + category: Data subset selection + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_index": ("STRING", {"default": ""}), + "row_index_type":(("string", "int"),), + "column_label": ("STRING", {"default": ""}), + "column_label_type":(("string", "int"),) + } + } + + RETURN_TYPES: tuple = ("FLOAT",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_index: str, + row_index_type: str, + column_label: str, + column_label_type: str) -> tuple: + """ + Selects specific cell from a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_index (str): The row index (row label) for the cell. + row_index_type (str): The data type of the row index. + column_label (str): The column label for the cell. + column_label_type (str): The data type of the column label. + + Returns: + tuple: A tuple containing the value of the cell in string. + """ + row_index = int(row_index) if row_index_type == "int" else row_index + column_label = int(column_label) if column_label_type == "int" else column_label + + value = dataframe.at[row_index, column_label] + return (float(value),) diff --git a/modules/pandas_wrapper/pandas_at_int.py b/modules/pandas_wrapper/pandas_at_int.py new file mode 100644 index 0000000..0320769 --- /dev/null +++ b/modules/pandas_wrapper/pandas_at_int.py @@ -0,0 +1,56 @@ +from typing import Any, Dict +from io import StringIO +import pandas as pd + +class PandasAtInt: + """ + Selects a cell from a pandas DataFrame and output as a Python int. + + category: Data subset selection + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_index": ("STRING", {"default": ""}), + "row_index_type":(("string", "int"),), + "column_label": ("STRING", {"default": ""}), + "column_label_type":(("string", "int"),) + } + } + + RETURN_TYPES: tuple = ("INT",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_index: str, + row_index_type: str, + column_label: str, + column_label_type: str) -> tuple: + """ + Selects specific cell from a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_index (str): The row index (row label) for the cell. + row_index_type (str): The data type of the row index. + column_label (str): The column label for the cell. + column_label_type (str): The data type of the column label. + + Returns: + tuple: A tuple containing the value of the cell in string. + """ + row_index = int(row_index) if row_index_type == "int" else row_index + column_label = int(column_label) if column_label_type == "int" else column_label + + value = dataframe.at[row_index, column_label] + return (int(value),) diff --git a/modules/pandas_wrapper/pandas_at_set_datetime.py b/modules/pandas_wrapper/pandas_at_set_datetime.py new file mode 100644 index 0000000..8a460b1 --- /dev/null +++ b/modules/pandas_wrapper/pandas_at_set_datetime.py @@ -0,0 +1,62 @@ +from typing import Any, Dict +import pandas as pd +import datetime + + +class PandasAtSetDatetime: + """ + Sets a Python datetime.datetime data in a cell in a pandas DataFrame. + + This modifies the input DataFrame in place. + + category: Transformation + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_index": ("STRING", {"default": ""}), + "row_index_type":(("string", "int"),), + "column_label": ("STRING", {"default": ""}), + "column_label_type":(("string", "int"),), + "data": ("PYDATETIME", {}) + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_index: str, + row_index_type: str, + column_label: str, + column_label_type: str, + data: datetime.datetime) -> tuple: + """ + Selects specific cell from a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_index (str): The row index (row label) for the cell. + row_index_type (str): The data type of the row index. + column_label (str): The column label for the cell. + column_label_type (str): The data type of the column label. + data: datetime.datetime (datetime.datetime): The value to set in the cell. + + Returns: + tuple: A tuple containing the value of the cell in string. + """ + row_index = int(row_index) if row_index_type == "int" else row_index + column_label = int(column_label) if column_label_type == "int" else column_label + + dataframe.at[row_index, column_label] = data + return (dataframe,) diff --git a/modules/pandas_wrapper/pandas_at_set_float.py b/modules/pandas_wrapper/pandas_at_set_float.py new file mode 100644 index 0000000..6e13794 --- /dev/null +++ b/modules/pandas_wrapper/pandas_at_set_float.py @@ -0,0 +1,61 @@ +from typing import Any, Dict +import pandas as pd + + +class PandasAtSetFloat: + """ + Sets a Python float data in a cell in a pandas DataFrame. + + This modifies the input DataFrame in place. + + category: Transformation + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_index": ("STRING", {"default": ""}), + "row_index_type":(("string", "int"),), + "column_label": ("STRING", {"default": ""}), + "column_label_type":(("string", "int"),), + "data": ("FLOAT", {"default": 0, "min": -2**63, "max": 2**63, "step": 0.00000001}) + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_index: str, + row_index_type: str, + column_label: str, + column_label_type: str, + data: float) -> tuple: + """ + Selects specific cell from a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_index (str): The row index (row label) for the cell. + row_index_type (str): The data type of the row index. + column_label (str): The column label for the cell. + column_label_type (str): The data type of the column label. + data: float (float): The value to set in the cell. + + Returns: + tuple: A tuple containing the value of the cell in string. + """ + row_index = int(row_index) if row_index_type == "int" else row_index + column_label = int(column_label) if column_label_type == "int" else column_label + + dataframe.at[row_index, column_label] = data + return (dataframe,) diff --git a/modules/pandas_wrapper/pandas_at_set_int.py b/modules/pandas_wrapper/pandas_at_set_int.py new file mode 100644 index 0000000..c72d2dd --- /dev/null +++ b/modules/pandas_wrapper/pandas_at_set_int.py @@ -0,0 +1,61 @@ +from typing import Any, Dict +import pandas as pd + + +class PandasAtSetInt: + """ + Sets a Python int data in a cell in a pandas DataFrame. + + This modifies the input DataFrame in place. + + category: Transformation + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_index": ("STRING", {"default": ""}), + "row_index_type":(("string", "int"),), + "column_label": ("STRING", {"default": ""}), + "column_label_type":(("string", "int"),), + "data": ("INT", {"default": 0, "min": -2**31, "max": 2**31}) + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_index: str, + row_index_type: str, + column_label: str, + column_label_type: str, + data: int) -> tuple: + """ + Selects specific cell from a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_index (str): The row index (row label) for the cell. + row_index_type (str): The data type of the row index. + column_label (str): The column label for the cell. + column_label_type (str): The data type of the column label. + data: int (int): The value to set in the cell. + + Returns: + tuple: A tuple containing the value of the cell in string. + """ + row_index = int(row_index) if row_index_type == "int" else row_index + column_label = int(column_label) if column_label_type == "int" else column_label + + dataframe.at[row_index, column_label] = data + return (dataframe,) diff --git a/modules/pandas_wrapper/pandas_at_set_string.py b/modules/pandas_wrapper/pandas_at_set_string.py new file mode 100644 index 0000000..3e7536c --- /dev/null +++ b/modules/pandas_wrapper/pandas_at_set_string.py @@ -0,0 +1,61 @@ +from typing import Any, Dict +import pandas as pd + + +class PandasAtSetString: + """ + Sets a Python string data in a cell in a pandas DataFrame. + + This modifies the input DataFrame in place. + + category: Transformation + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_index": ("STRING", {"default": ""}), + "row_index_type":(("string", "int"),), + "column_label": ("STRING", {"default": ""}), + "column_label_type":(("string", "int"),), + "data": ("STRING", {}) + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_index: str, + row_index_type: str, + column_label: str, + column_label_type: str, + data: str) -> tuple: + """ + Selects specific cell from a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_index (str): The row index (row label) for the cell. + row_index_type (str): The data type of the row index. + column_label (str): The column label for the cell. + column_label_type (str): The data type of the column label. + data: string (str): The value to set in the cell. + + Returns: + tuple: A tuple containing the value of the cell in string. + """ + row_index = int(row_index) if row_index_type == "int" else row_index + column_label = int(column_label) if column_label_type == "int" else column_label + + dataframe.at[row_index, column_label] = data + return (dataframe,) diff --git a/modules/pandas_wrapper/pandas_at_string.py b/modules/pandas_wrapper/pandas_at_string.py new file mode 100644 index 0000000..0d9067d --- /dev/null +++ b/modules/pandas_wrapper/pandas_at_string.py @@ -0,0 +1,56 @@ +from typing import Any, Dict +from io import StringIO +import pandas as pd + +class PandasAtString: + """ + Selects a cell from a pandas DataFrame and output as a string. + + category: Data subset selection + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_index": ("STRING", {"default": ""}), + "row_index_type":(("string", "int"),), + "column_label": ("STRING", {"default": ""}), + "column_label_type":(("string", "int"),) + } + } + + RETURN_TYPES: tuple = ("STRING",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_index: str, + row_index_type: str, + column_label: str, + column_label_type: str) -> tuple: + """ + Selects specific cell from a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_index (str): The row index (row label) for the cell. + row_index_type (str): The data type of the row index. + column_label (str): The column label for the cell. + column_label_type (str): The data type of the column label. + + Returns: + tuple: A tuple containing the value of the cell in string. + """ + row_index = int(row_index) if row_index_type == "int" else row_index + column_label = int(column_label) if column_label_type == "int" else column_label + + value = dataframe.at[row_index, column_label] + return (value,) diff --git a/modules/pandas_wrapper/pandas_iat_datetime.py b/modules/pandas_wrapper/pandas_iat_datetime.py new file mode 100644 index 0000000..243b968 --- /dev/null +++ b/modules/pandas_wrapper/pandas_iat_datetime.py @@ -0,0 +1,48 @@ +from typing import Any, Dict +import pandas as pd +import datetime + + +class PandasIatDatetime: + """ + Selects a cell from a pandas DataFrame and output as a Python datetime.datetime data. + + category: Data subset selection + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}), + "column_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}) + } + } + + RETURN_TYPES: tuple = ("PYDATETIME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_integer_position: int, + column_integer_position: int) -> tuple: + """ + Selects specific cell from a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_integer_position (int): The row integer position for the cell. + column_integer_position (int): The row integer position for the cell. + + Returns: + tuple: A tuple containing the value of the cell. + """ + value = dataframe.iat[row_integer_position, column_integer_position] + return (value.to_pydatetime(),) diff --git a/modules/pandas_wrapper/pandas_iat_float.py b/modules/pandas_wrapper/pandas_iat_float.py new file mode 100644 index 0000000..fcc11b4 --- /dev/null +++ b/modules/pandas_wrapper/pandas_iat_float.py @@ -0,0 +1,46 @@ +from typing import Any, Dict +import pandas as pd + +class PandasIatFloat: + """ + Selects a cell from a pandas DataFrame and output as a Python float. + + category: Data subset selection + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}), + "column_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}) + } + } + + RETURN_TYPES: tuple = ("FLOAT",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_integer_position: int, + column_integer_position: int) -> tuple: + """ + Selects specific cell from a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_integer_position (int): The row integer position for the cell. + column_integer_position (int): The row integer position for the cell. + + Returns: + tuple: A tuple containing the value of the cell. + """ + value = dataframe.iat[row_integer_position, column_integer_position] + return (float(value),) diff --git a/modules/pandas_wrapper/pandas_iat_int.py b/modules/pandas_wrapper/pandas_iat_int.py new file mode 100644 index 0000000..e180a21 --- /dev/null +++ b/modules/pandas_wrapper/pandas_iat_int.py @@ -0,0 +1,47 @@ +from typing import Any, Dict +from io import StringIO +import pandas as pd + +class PandasIatInt: + """ + Selects a cell from a pandas DataFrame and output as a Python int. + + category: Data subset selection + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}), + "column_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}) + } + } + + RETURN_TYPES: tuple = ("INT",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_integer_position: int, + column_integer_position: int) -> tuple: + """ + Selects specific cell from a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_integer_position (int): The row integer position for the cell. + column_integer_position (int): The row integer position for the cell. + + Returns: + tuple: A tuple containing the value of the cell. + """ + value = dataframe.iat[row_integer_position, column_integer_position] + return (int(value),) diff --git a/modules/pandas_wrapper/pandas_iat_set_datetime.py b/modules/pandas_wrapper/pandas_iat_set_datetime.py new file mode 100644 index 0000000..a2fa3c5 --- /dev/null +++ b/modules/pandas_wrapper/pandas_iat_set_datetime.py @@ -0,0 +1,52 @@ +from typing import Any, Dict +import pandas as pd +import datetime + +class PandasIatSetDatetime: + """ + Sets a Python datetime.datetime data in a cell in a pandas DataFrame. + + This modifies the input DataFrame in place. + + category: Transformation + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}), + "column_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}), + "data": ("PYDATETIME", {}) + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_integer_position: int, + column_integer_position: int, + data: datetime.datetime) -> tuple: + """ + Sets a Python datetime.datetime data in a cell in a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_integer_position (int): The row integer position for the cell. + column_integer_position (int): The row integer position for the cell. + data: datetime.datetime (datetime.datetime): The value to set in the cell. + + Returns: + tuple: A tuple containing the updated DataFrame. + """ + dataframe.iat[row_integer_position, column_integer_position] = data + return (dataframe,) diff --git a/modules/pandas_wrapper/pandas_iat_set_float.py b/modules/pandas_wrapper/pandas_iat_set_float.py new file mode 100644 index 0000000..40fcaf1 --- /dev/null +++ b/modules/pandas_wrapper/pandas_iat_set_float.py @@ -0,0 +1,52 @@ +from typing import Any, Dict +import pandas as pd + + +class PandasIatSetFloat: + """ + Sets a Python float data in a cell from a pandas DataFrame. + + This modifies the input DataFrame in place. + + category: Transformation + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}), + "column_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}), + "data": ("FLOAT", {"default": 0, "min": -2**63, "max": 2**63, "step": 0.00000001}) + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_integer_position: int, + column_integer_position: int, + data: float) -> tuple: + """ + Sets a Python float data in a cell in a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_integer_position (int): The row integer position for the cell. + column_integer_position (int): The row integer position for the cell. + data (float): The value to set in the cell. + + Returns: + tuple: A tuple containing the updated DataFrame. + """ + dataframe.iat[row_integer_position, column_integer_position] = data + return (dataframe,) diff --git a/modules/pandas_wrapper/pandas_iat_set_int.py b/modules/pandas_wrapper/pandas_iat_set_int.py new file mode 100644 index 0000000..5bdfbd5 --- /dev/null +++ b/modules/pandas_wrapper/pandas_iat_set_int.py @@ -0,0 +1,52 @@ +from typing import Any, Dict +import pandas as pd + + +class PandasIatSetInt: + """ + Sets a Python int data in a cell from a pandas DataFrame. + + This modifies the input DataFrame in place. + + category: Transformation + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}), + "column_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}), + "data": ("INT", {"default": 0, "min": -2**31, "max": 2**31}) + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_integer_position: int, + column_integer_position: int, + data: int) -> tuple: + """ + Sets a Python int data in a cell in a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_integer_position (int): The row integer position for the cell. + column_integer_position (int): The row integer position for the cell. + data (int): The value to set in the cell. + + Returns: + tuple: A tuple containing the updated DataFrame. + """ + dataframe.iat[row_integer_position, column_integer_position] = data + return (dataframe,) diff --git a/modules/pandas_wrapper/pandas_iat_set_string.py b/modules/pandas_wrapper/pandas_iat_set_string.py new file mode 100644 index 0000000..2b85369 --- /dev/null +++ b/modules/pandas_wrapper/pandas_iat_set_string.py @@ -0,0 +1,52 @@ +from typing import Any, Dict +import pandas as pd +import datetime + +class PandasIatSetString: + """ + Sets a Python string in a cell in a pandas DataFrame. + + This modifies the input DataFrame in place. + + category: Transformation + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}), + "column_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}), + "data": ("STRING", {"default": ""}) + } + } + + RETURN_TYPES: tuple = ("DATAFRAME",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_integer_position: int, + column_integer_position: int, + data: str) -> tuple: + """ + Sets a Python string data in a cell in a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_integer_position (int): The row integer position for the cell. + column_integer_position (int): The row integer position for the cell. + data: string (str): The value to set in the cell. + + Returns: + tuple: A tuple containing the updated DataFrame. + """ + dataframe.iat[row_integer_position, column_integer_position] = data + return (dataframe,) diff --git a/modules/pandas_wrapper/pandas_iat_string.py b/modules/pandas_wrapper/pandas_iat_string.py new file mode 100644 index 0000000..d9a1ba8 --- /dev/null +++ b/modules/pandas_wrapper/pandas_iat_string.py @@ -0,0 +1,47 @@ +from typing import Any, Dict +from io import StringIO +import pandas as pd + +class PandasIatString: + """ + Selects a cell from a pandas DataFrame and output as a string. + + category: Data subset selection + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the `cell` function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "dataframe": ("DATAFRAME", {}), + "row_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}), + "column_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}) + } + } + + RETURN_TYPES: tuple = ("STRING",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, dataframe: pd.DataFrame, + row_integer_position: int, + column_integer_position: int) -> tuple: + """ + Selects specific cell from a pandas DataFrame. + + Args: + dataframe (DataFrame): The DataFrame. + row_integer_position (int): The row integer position for the cell. + column_integer_position (int): The row integer position for the cell. + + Returns: + tuple: A tuple containing the value of the cell. + """ + value = dataframe.iat[row_integer_position, column_integer_position] + return (value,) diff --git a/modules/pandas_wrapper/pandas_loc_cell_str.py b/modules/pandas_wrapper/pandas_loc_cell_string.py similarity index 94% rename from modules/pandas_wrapper/pandas_loc_cell_str.py rename to modules/pandas_wrapper/pandas_loc_cell_string.py index 9858474..40afb43 100644 --- a/modules/pandas_wrapper/pandas_loc_cell_str.py +++ b/modules/pandas_wrapper/pandas_loc_cell_string.py @@ -2,7 +2,7 @@ from typing import Any, Dict from io import StringIO import pandas as pd -class PandasLocCellStr: +class PandasLocCellString: """ Selects a cell from a pandas DataFrame and output as a string. @@ -28,10 +28,10 @@ class PandasLocCellStr: } RETURN_TYPES: tuple = ("STRING",) - FUNCTION: str = "cell" + FUNCTION: str = "f" CATEGORY: str = "Data Analysis" - def cell(self, dataframe: pd.DataFrame, + def f(self, dataframe: pd.DataFrame, row_index: str, row_index_type: str, column_label: str, diff --git a/pyproject.toml b/pyproject.toml index bd99782..8558c08 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "data-analysis" description = "Data analysis custom modules for ComfyUI – Integrates Pandas, Seaborn and Matplotlib into ComfyUI, featuring extensive PyTorch wrapper nodes for seamless tensor operations. Experimental PyTorch model training was added in v2.0." -version = "2.0.5" +version = "2.0.6" license = {file = "LICENSE"} [project.urls] diff --git a/tests/cda/py_datetime_to_string_test.py b/tests/cda/py_datetime_to_string_test.py new file mode 100644 index 0000000..f9cfcab --- /dev/null +++ b/tests/cda/py_datetime_to_string_test.py @@ -0,0 +1,30 @@ +import os +import sys +import unittest +from datetime import datetime + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from cda.py_datetime_to_string import PyDatetimeToString + +class TestPyDatetimeToString(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PyDatetimeToString() + self.test_cases = [ + (datetime(2023, 3, 15, 12, 0, 0), "%Y-%m-%d %H:%M:%S", "2023-03-15 12:00:00"), + (datetime(2024, 6, 1, 9, 30, 0), "%Y-%m-%d %H:%M:%S", "2024-06-01 09:30:00"), + (datetime(2023, 3, 15, 12, 0), "%d/%m/%Y %H:%M", "15/03/2023 12:00"), + (datetime(2024, 6, 1), "%d-%m-%Y", "01-06-2024") + ] + + def test_datetime_to_string(self): + """Test converting a datetime to string.""" + for value, date_format, expected in self.test_cases: + with self.subTest(value=value, date_format=date_format): + retval = self.node.f(value=value, date_format=date_format)[0] + self.assertEqual(retval, expected, f"Mismatch for value={value} with format={date_format}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/cda/py_float_to_string_test.py b/tests/cda/py_float_to_string_test.py new file mode 100644 index 0000000..2ad8a8c --- /dev/null +++ b/tests/cda/py_float_to_string_test.py @@ -0,0 +1,29 @@ +import os +import sys +import unittest + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from cda.py_float_to_string import PyFloatToString + +class TestPyFloatToString(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PyFloatToString() + self.test_cases = [ + (3.14, "3.14"), + (2.71, "2.71"), + (0.577, "0.577"), + (1.618, "1.618") + ] + + def test_float_to_string(self): + """Test converting a float to string.""" + for value, expected in self.test_cases: + with self.subTest(value=value): + retval = self.node.f(value=value)[0] + self.assertEqual(retval, expected, f"Mismatch for value={value}") + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/tests/cda/py_int_to_string_test.py b/tests/cda/py_int_to_string_test.py new file mode 100644 index 0000000..765e768 --- /dev/null +++ b/tests/cda/py_int_to_string_test.py @@ -0,0 +1,29 @@ +import os +import sys +import unittest + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from cda.py_int_to_string import PyIntToString + +class TestPyIntToString(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PyIntToString() + self.test_cases = [ + (3, "3"), + (27, "27"), + (100, "100"), + (-42, "-42") + ] + + def test_int_to_string(self): + """Test converting an integer to string.""" + for value, expected in self.test_cases: + with self.subTest(value=value): + retval = self.node.f(value=value)[0] + self.assertEqual(retval, expected, f"Mismatch for value={value}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/cda/py_string_to_datetime_test.py b/tests/cda/py_string_to_datetime_test.py new file mode 100644 index 0000000..458134e --- /dev/null +++ b/tests/cda/py_string_to_datetime_test.py @@ -0,0 +1,30 @@ +import os +import sys +import unittest +from datetime import datetime + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from cda.py_string_to_datetime import PyStringToDatetime + +class TestPyStringToDatetime(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PyStringToDatetime() + self.test_cases = [ + ("2023-03-15 12:00:00", "%Y-%m-%d %H:%M:%S", datetime(2023, 3, 15, 12, 0, 0)), + ("2024-06-01 09:30:00", "%Y-%m-%d %H:%M:%S", datetime(2024, 6, 1, 9, 30, 0)), + ("15/03/2023 12:00", "%d/%m/%Y %H:%M", datetime(2023, 3, 15, 12, 0)), + ("01-06-2024", "%d-%m-%Y", datetime(2024, 6, 1)) + ] + + def test_string_to_datetime(self): + """Test converting a string to datetime.""" + for value, date_format, expected in self.test_cases: + with self.subTest(value=value, date_format=date_format): + retval = self.node.f(value=value, date_format=date_format)[0] + self.assertEqual(retval, expected, f"Mismatch for value={value} with format={date_format}") + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/tests/cda/py_string_to_float_test.py b/tests/cda/py_string_to_float_test.py new file mode 100644 index 0000000..7a8c096 --- /dev/null +++ b/tests/cda/py_string_to_float_test.py @@ -0,0 +1,29 @@ +import os +import sys +import unittest + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from cda.py_string_to_float import PyStringToFloat + +class TestPyStringToFloat(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PyStringToFloat() + self.test_cases = [ + ("3.14", 3.14), + ("2.71", 2.71), + ("0.577", 0.577), + ("1.618", 1.618) + ] + + def test_string_to_float(self): + """Test converting a string to float.""" + for value, expected in self.test_cases: + with self.subTest(value=value): + retval = self.node.f(value=value)[0] + self.assertEqual(retval, expected, f"Mismatch for value={value}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/cda/py_string_to_int_test.py b/tests/cda/py_string_to_int_test.py new file mode 100644 index 0000000..929bb6b --- /dev/null +++ b/tests/cda/py_string_to_int_test.py @@ -0,0 +1,29 @@ +import os +import sys +import unittest + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from cda.py_string_to_int import PyStringToInt + +class TestPyStringToInt(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PyStringToInt() + self.test_cases = [ + ("3", 3), + ("27", 27), + ("100", 100), + ("-42", -42) + ] + + def test_string_to_int(self): + """Test converting a string to int.""" + for value, expected in self.test_cases: + with self.subTest(value=value): + retval = self.node.f(value=value)[0] + self.assertEqual(retval, expected, f"Mismatch for value={value}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pandas_wrapper/pandas_at_datetime_test.py b/tests/pandas_wrapper/pandas_at_datetime_test.py new file mode 100644 index 0000000..aaa54d9 --- /dev/null +++ b/tests/pandas_wrapper/pandas_at_datetime_test.py @@ -0,0 +1,69 @@ +import os +import sys +import unittest +import pandas as pd +from datetime import datetime + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_at_datetime import PandasAtDatetime + +class TestPandasAtDatetime(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasAtDatetime() + self.test_cases = [ + # Test with datetime values and string indices + ( + pd.DataFrame({"a": [datetime(2023, 3, 15, 12, 0, 0)]}, index=["row1"]), + "row1", "string", "a", "string", + (datetime(2023, 3, 15, 12, 0, 0),) + ), + ( + pd.DataFrame({"a": [datetime(2024, 6, 1, 9, 30, 0)]}, index=["row2"]), + "row2", "string", "a", "string", + (datetime(2024, 6, 1, 9, 30, 0),) + ), + + # Test with integer indices + ( + pd.DataFrame({"a": [datetime(2025, 1, 1, 0, 0, 0)]}, index=[0]), + "0", "int", "a", "string", + (datetime(2025, 1, 1, 0, 0, 0),) + ), + ( + pd.DataFrame({"a": [datetime(2022, 12, 31, 23, 59, 59)]}, index=[1]), + "1", "int", "a", "string", + (datetime(2022, 12, 31, 23, 59, 59),) + ), + + # Test with integer column labels + ( + pd.DataFrame({1: [datetime(2020, 2, 29, 14, 15, 16)]}, index=[0]), + "0", "int", 1, "int", + (datetime(2020, 2, 29, 14, 15, 16),) + ), + ( + pd.DataFrame({2: [datetime(2019, 7, 4, 18, 45, 30)]}, index=[1]), + "1", "int", 2, "int", + (datetime(2019, 7, 4, 18, 45, 30),) + ), + + # Mixed types: string index, integer column label + ( + pd.DataFrame({1: [datetime(2018, 11, 11, 11, 11, 11)]}, index=["event"]), + "event", "string", 1, "int", + (datetime(2018, 11, 11, 11, 11, 11),) + ), + ] + + def test_select_datetime_cell(self): + """Test selecting a datetime cell from a pandas DataFrame.""" + for dataframe, row_index, row_index_type, column_label, column_label_type, expected in self.test_cases: + with self.subTest(dataframe=dataframe, row_index=row_index, column_label=column_label): + retval = self.node.f(dataframe, row_index, row_index_type, column_label, column_label_type) + self.assertEqual(retval, expected, f"Mismatch for row_index={row_index}, column_label={column_label}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pandas_wrapper/pandas_at_float_test.py b/tests/pandas_wrapper/pandas_at_float_test.py new file mode 100644 index 0000000..14a2278 --- /dev/null +++ b/tests/pandas_wrapper/pandas_at_float_test.py @@ -0,0 +1,68 @@ +import os +import sys +import unittest +import pandas as pd + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_at_float import PandasAtFloat + +class TestPandasAtFloat(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasAtFloat() + self.test_cases = [ + # Test with float values and string indices + ( + pd.DataFrame({"a": [123.456]}, index=["row1"]), + "row1", "string", "a", "string", + (123.456,) + ), + ( + pd.DataFrame({"a": [789.101]}, index=["row2"]), + "row2", "string", "a", "string", + (789.101,) + ), + + # Test with integer indices + ( + pd.DataFrame({"a": [456.789]}, index=[0]), + "0", "int", "a", "string", + (456.789,) + ), + ( + pd.DataFrame({"a": [987.654]}, index=[1]), + "1", "int", "a", "string", + (987.654,) + ), + + # Test with integer column labels + ( + pd.DataFrame({1: [321.654]}, index=[0]), + "0", "int", 1, "int", + (321.654,) + ), + ( + pd.DataFrame({2: [654.321]}, index=[1]), + "1", "int", 2, "int", + (654.321,) + ), + + # Mixed types: string index, integer column label + ( + pd.DataFrame({1: [111.222]}, index=["event"]), + "event", "string", 1, "int", + (111.222,) + ), + ] + + def test_select_float_cell(self): + """Test selecting a float cell from a pandas DataFrame.""" + for dataframe, row_index, row_index_type, column_label, column_label_type, expected in self.test_cases: + with self.subTest(dataframe=dataframe, row_index=row_index, column_label=column_label): + retval = self.node.f(dataframe, row_index, row_index_type, column_label, column_label_type) + self.assertEqual(retval, expected, f"Mismatch for row_index={row_index}, column_label={column_label}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pandas_wrapper/pandas_at_int_test.py b/tests/pandas_wrapper/pandas_at_int_test.py new file mode 100644 index 0000000..716ad46 --- /dev/null +++ b/tests/pandas_wrapper/pandas_at_int_test.py @@ -0,0 +1,68 @@ +import os +import sys +import unittest +import pandas as pd + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_at_int import PandasAtInt + +class TestPandasAtInt(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasAtInt() + self.test_cases = [ + # Test with integer values and string indices + ( + pd.DataFrame({"a": [123]}, index=["row1"]), + "row1", "string", "a", "string", + (123,) + ), + ( + pd.DataFrame({"a": [789]}, index=["row2"]), + "row2", "string", "a", "string", + (789,) + ), + + # Test with integer indices + ( + pd.DataFrame({"a": [456]}, index=[0]), + "0", "int", "a", "string", + (456,) + ), + ( + pd.DataFrame({"a": [987]}, index=[1]), + "1", "int", "a", "string", + (987,) + ), + + # Test with integer column labels + ( + pd.DataFrame({1: [321]}, index=[0]), + "0", "int", 1, "int", + (321,) + ), + ( + pd.DataFrame({2: [654]}, index=[1]), + "1", "int", 2, "int", + (654,) + ), + + # Mixed types: string index, integer column label + ( + pd.DataFrame({1: [111]}, index=["event"]), + "event", "string", 1, "int", + (111,) + ), + ] + + def test_select_int_cell(self): + """Test selecting an integer cell from a pandas DataFrame.""" + for dataframe, row_index, row_index_type, column_label, column_label_type, expected in self.test_cases: + with self.subTest(dataframe=dataframe, row_index=row_index, column_label=column_label): + retval = self.node.f(dataframe, row_index, row_index_type, column_label, column_label_type) + self.assertEqual(retval, expected, f"Mismatch for row_index={row_index}, column_label={column_label}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pandas_wrapper/pandas_at_set_datetime_test.py b/tests/pandas_wrapper/pandas_at_set_datetime_test.py new file mode 100644 index 0000000..d447152 --- /dev/null +++ b/tests/pandas_wrapper/pandas_at_set_datetime_test.py @@ -0,0 +1,62 @@ +import os +import sys +import unittest +import pandas as pd +from datetime import datetime + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_at_set_datetime import PandasAtSetDatetime + +class TestPandasAtSetDatetime(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasAtSetDatetime() + self.test_cases = [ + # Test with string row index and string column label + ( + pd.DataFrame({"a": [None]}, index=["row1"]), + "row1", "string", "a", "string", datetime(2023, 3, 15, 12, 0, 0) + ), + ( + pd.DataFrame({"a": [None]}, index=["row2"]), + "row2", "string", "a", "string", datetime(2024, 6, 1, 9, 30, 0) + ), + # Test with integer row index and string column label + ( + pd.DataFrame({"a": [None]}, index=[0]), + "0", "int", "a", "string", datetime(2025, 1, 1, 0, 0, 0) + ), + ( + pd.DataFrame({"a": [None]}, index=[1]), + "1", "int", "a", "string", datetime(2022, 12, 31, 23, 59, 59) + ), + # Test with integer row index and integer column label + ( + pd.DataFrame({1: [None]}, index=[0]), + "0", "int", 1, "int", datetime(2020, 2, 29, 14, 15, 16) + ), + ( + pd.DataFrame({2: [None]}, index=[1]), + "1", "int", 2, "int", datetime(2019, 7, 4, 18, 45, 30) + ), + # Mixed types: string row index, integer column label + ( + pd.DataFrame({1: [None]}, index=["event"]), + "event", "string", 1, "int", datetime(2018, 11, 11, 11, 11, 11) + ), + ] + + def test_set_datetime_cell(self): + """Test setting a datetime cell in a pandas DataFrame.""" + for dataframe, row_index, row_index_type, column_label, column_label_type, data in self.test_cases: + with self.subTest(dataframe=dataframe, row_index=row_index, column_label=column_label): + retval = self.node.f(dataframe, row_index, row_index_type, column_label, column_label_type, data) + self.assertEqual(retval[0].at[int(row_index) if row_index_type == "int" else row_index, + int(column_label) if column_label_type == "int" else column_label], + data, + f"Mismatch for row_index={row_index}, column_label={column_label}") + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/tests/pandas_wrapper/pandas_at_set_float_test.py b/tests/pandas_wrapper/pandas_at_set_float_test.py new file mode 100644 index 0000000..4218d7f --- /dev/null +++ b/tests/pandas_wrapper/pandas_at_set_float_test.py @@ -0,0 +1,61 @@ +import os +import sys +import unittest +import pandas as pd + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_at_set_float import PandasAtSetFloat + +class TestPandasAtSetFloat(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasAtSetFloat() + self.test_cases = [ + # Test with string row index and string column label + ( + pd.DataFrame({"a": [None]}, index=["row1"]), + "row1", "string", "a", "string", 3.14 + ), + ( + pd.DataFrame({"a": [None]}, index=["row2"]), + "row2", "string", "a", "string", 2.71 + ), + # Test with integer row index and string column label + ( + pd.DataFrame({"a": [None]}, index=[0]), + "0", "int", "a", "string", 1.618 + ), + ( + pd.DataFrame({"a": [None]}, index=[1]), + "1", "int", "a", "string", 0.577 + ), + # Test with integer row index and integer column label + ( + pd.DataFrame({1: [None]}, index=[0]), + "0", "int", 1, "int", 6.28 + ), + ( + pd.DataFrame({2: [None]}, index=[1]), + "1", "int", 2, "int", 1.414 + ), + # Mixed types: string row index, integer column label + ( + pd.DataFrame({1: [None]}, index=["event"]), + "event", "string", 1, "int", 2.236 + ), + ] + + def test_set_float_cell(self): + """Test setting a float cell in a pandas DataFrame.""" + for dataframe, row_index, row_index_type, column_label, column_label_type, data in self.test_cases: + with self.subTest(dataframe=dataframe, row_index=row_index, column_label=column_label): + retval = self.node.f(dataframe, row_index, row_index_type, column_label, column_label_type, data) + self.assertEqual(retval[0].at[int(row_index) if row_index_type == "int" else row_index, + int(column_label) if column_label_type == "int" else column_label], + data, + f"Mismatch for row_index={row_index}, column_label={column_label}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pandas_wrapper/pandas_at_set_int_test.py b/tests/pandas_wrapper/pandas_at_set_int_test.py new file mode 100644 index 0000000..d7f8182 --- /dev/null +++ b/tests/pandas_wrapper/pandas_at_set_int_test.py @@ -0,0 +1,61 @@ +import os +import sys +import unittest +import pandas as pd + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_at_set_int import PandasAtSetInt + +class TestPandasAtSetInt(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasAtSetInt() + self.test_cases = [ + # Test with string row index and string column label + ( + pd.DataFrame({"a": [None]}, index=["row1"]), + "row1", "string", "a", "string", 10 + ), + ( + pd.DataFrame({"a": [None]}, index=["row2"]), + "row2", "string", "a", "string", 20 + ), + # Test with integer row index and string column label + ( + pd.DataFrame({"a": [None]}, index=[0]), + "0", "int", "a", "string", 30 + ), + ( + pd.DataFrame({"a": [None]}, index=[1]), + "1", "int", "a", "string", 40 + ), + # Test with integer row index and integer column label + ( + pd.DataFrame({1: [None]}, index=[0]), + "0", "int", 1, "int", 50 + ), + ( + pd.DataFrame({2: [None]}, index=[1]), + "1", "int", 2, "int", 60 + ), + # Mixed types: string row index, integer column label + ( + pd.DataFrame({1: [None]}, index=["event"]), + "event", "string", 1, "int", 70 + ), + ] + + def test_set_int_cell(self): + """Test setting an integer cell in a pandas DataFrame.""" + for dataframe, row_index, row_index_type, column_label, column_label_type, data in self.test_cases: + with self.subTest(dataframe=dataframe, row_index=row_index, column_label=column_label): + retval = self.node.f(dataframe, row_index, row_index_type, column_label, column_label_type, data) + self.assertEqual(retval[0].at[int(row_index) if row_index_type == "int" else row_index, + int(column_label) if column_label_type == "int" else column_label], + data, + f"Mismatch for row_index={row_index}, column_label={column_label}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pandas_wrapper/pandas_at_set_string_test.py b/tests/pandas_wrapper/pandas_at_set_string_test.py new file mode 100644 index 0000000..6c27f72 --- /dev/null +++ b/tests/pandas_wrapper/pandas_at_set_string_test.py @@ -0,0 +1,61 @@ +import os +import sys +import unittest +import pandas as pd + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_at_set_string import PandasAtSetString + +class TestPandasAtSetString(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasAtSetString() + self.test_cases = [ + # Test with string row index and string column label + ( + pd.DataFrame({"a": [None]}, index=["row1"]), + "row1", "string", "a", "string", "hello" + ), + ( + pd.DataFrame({"a": [None]}, index=["row2"]), + "row2", "string", "a", "string", "world" + ), + # Test with integer row index and string column label + ( + pd.DataFrame({"a": [None]}, index=[0]), + "0", "int", "a", "string", "foo" + ), + ( + pd.DataFrame({"a": [None]}, index=[1]), + "1", "int", "a", "string", "bar" + ), + # Test with integer row index and integer column label + ( + pd.DataFrame({1: [None]}, index=[0]), + "0", "int", 1, "int", "baz" + ), + ( + pd.DataFrame({2: [None]}, index=[1]), + "1", "int", 2, "int", "qux" + ), + # Mixed types: string row index, integer column label + ( + pd.DataFrame({1: [None]}, index=["event"]), + "event", "string", 1, "int", "alpha" + ), + ] + + def test_set_string_cell(self): + """Test setting a string cell in a pandas DataFrame.""" + for dataframe, row_index, row_index_type, column_label, column_label_type, data in self.test_cases: + with self.subTest(dataframe=dataframe, row_index=row_index, column_label=column_label): + retval = self.node.f(dataframe, row_index, row_index_type, column_label, column_label_type, data) + self.assertEqual(retval[0].at[int(row_index) if row_index_type == "int" else row_index, + int(column_label) if column_label_type == "int" else column_label], + data, + f"Mismatch for row_index={row_index}, column_label={column_label}") + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/tests/pandas_wrapper/pandas_at_string_test.py b/tests/pandas_wrapper/pandas_at_string_test.py new file mode 100644 index 0000000..78d1e61 --- /dev/null +++ b/tests/pandas_wrapper/pandas_at_string_test.py @@ -0,0 +1,68 @@ +import os +import sys +import unittest +import pandas as pd + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_at_string import PandasAtString + +class TestPandasAtString(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasAtString() + self.test_cases = [ + # Test with string values and string indices + ( + pd.DataFrame({"a": ["apple"]}, index=["row1"]), + "row1", "string", "a", "string", + ("apple",) + ), + ( + pd.DataFrame({"a": ["banana"]}, index=["row2"]), + "row2", "string", "a", "string", + ("banana",) + ), + + # Test with integer indices + ( + pd.DataFrame({"a": ["cherry"]}, index=[0]), + "0", "int", "a", "string", + ("cherry",) + ), + ( + pd.DataFrame({"a": ["date"]}, index=[1]), + "1", "int", "a", "string", + ("date",) + ), + + # Test with integer column labels + ( + pd.DataFrame({1: ["elderberry"]}, index=[0]), + "0", "int", 1, "int", + ("elderberry",) + ), + ( + pd.DataFrame({2: ["fig"]}, index=[1]), + "1", "int", 2, "int", + ("fig",) + ), + + # Mixed types: string index, integer column label + ( + pd.DataFrame({1: ["grape"]}, index=["event"]), + "event", "string", 1, "int", + ("grape",) + ), + ] + + def test_select_string_cell(self): + """Test selecting a string cell from a pandas DataFrame.""" + for dataframe, row_index, row_index_type, column_label, column_label_type, expected in self.test_cases: + with self.subTest(dataframe=dataframe, row_index=row_index, column_label=column_label): + retval = self.node.f(dataframe, row_index, row_index_type, column_label, column_label_type) + self.assertEqual(retval, expected, f"Mismatch for row_index={row_index}, column_label={column_label}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pandas_wrapper/pandas_iat_datetime_test.py b/tests/pandas_wrapper/pandas_iat_datetime_test.py new file mode 100644 index 0000000..d8aef03 --- /dev/null +++ b/tests/pandas_wrapper/pandas_iat_datetime_test.py @@ -0,0 +1,55 @@ +import os +import sys +import unittest +import pandas as pd +from datetime import datetime + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_iat_datetime import PandasIatDatetime + +class TestPandasIatDatetime(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasIatDatetime() + self.test_cases = [ + # Test with datetime values + ( + pd.DataFrame({"a": [datetime(2023, 3, 15, 12, 0, 0)]}), + 0, 0, + (datetime(2023, 3, 15, 12, 0, 0),) + ), + ( + pd.DataFrame({"a": [datetime(2024, 6, 1, 9, 30, 0)]}), + 0, 0, + (datetime(2024, 6, 1, 9, 30, 0),) + ), + # Test with multiple rows and columns + ( + pd.DataFrame({ + "a": [datetime(2025, 1, 1, 0, 0, 0), datetime(2022, 12, 31, 23, 59, 59)], + "b": [datetime(2020, 2, 29, 14, 15, 16), datetime(2019, 7, 4, 18, 45, 30)] + }), + 1, 1, + (datetime(2019, 7, 4, 18, 45, 30),) + ), + ( + pd.DataFrame({ + 1: [datetime(2018, 11, 11, 11, 11, 11)], + 2: [datetime(2017, 5, 23, 6, 30, 0)] + }), + 0, 1, + (datetime(2017, 5, 23, 6, 30, 0),) + ), + ] + + def test_select_datetime_cell(self): + """Test selecting a datetime cell from a pandas DataFrame.""" + for dataframe, row_pos, col_pos, expected in self.test_cases: + with self.subTest(dataframe=dataframe, row_pos=row_pos, col_pos=col_pos): + retval = self.node.f(dataframe, row_pos, col_pos) + self.assertEqual(retval, expected, f"Mismatch for row_pos={row_pos}, col_pos={col_pos}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pandas_wrapper/pandas_iat_float_test.py b/tests/pandas_wrapper/pandas_iat_float_test.py new file mode 100644 index 0000000..b8bd521 --- /dev/null +++ b/tests/pandas_wrapper/pandas_iat_float_test.py @@ -0,0 +1,54 @@ +import os +import sys +import unittest +import pandas as pd + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_iat_float import PandasIatFloat + +class TestPandasIatFloat(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasIatFloat() + self.test_cases = [ + # Test with float values + ( + pd.DataFrame({"a": [1.23]}), + 0, 0, + (1.23,) + ), + ( + pd.DataFrame({"a": [4.56]}), + 0, 0, + (4.56,) + ), + # Test with multiple rows and columns + ( + pd.DataFrame({ + "a": [7.89, 3.21], + "b": [6.54, 9.87] + }), + 1, 1, + (9.87,) + ), + ( + pd.DataFrame({ + 1: [2.34], + 2: [5.67] + }), + 0, 1, + (5.67,) + ), + ] + + def test_select_float_cell(self): + """Test selecting a float cell from a pandas DataFrame.""" + for dataframe, row_pos, col_pos, expected in self.test_cases: + with self.subTest(dataframe=dataframe, row_pos=row_pos, col_pos=col_pos): + retval = self.node.f(dataframe, row_pos, col_pos) + self.assertEqual(retval, expected, f"Mismatch for row_pos={row_pos}, col_pos={col_pos}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pandas_wrapper/pandas_iat_int_test.py b/tests/pandas_wrapper/pandas_iat_int_test.py new file mode 100644 index 0000000..44163b8 --- /dev/null +++ b/tests/pandas_wrapper/pandas_iat_int_test.py @@ -0,0 +1,54 @@ +import os +import sys +import unittest +import pandas as pd + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_iat_int import PandasIatInt + +class TestPandasIatInt(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasIatInt() + self.test_cases = [ + # Test with integer values + ( + pd.DataFrame({"a": [123]}), + 0, 0, + (123,) + ), + ( + pd.DataFrame({"a": [456]}), + 0, 0, + (456,) + ), + # Test with multiple rows and columns + ( + pd.DataFrame({ + "a": [789, 321], + "b": [654, 987] + }), + 1, 1, + (987,) + ), + ( + pd.DataFrame({ + 1: [234], + 2: [567] + }), + 0, 1, + (567,) + ), + ] + + def test_select_int_cell(self): + """Test selecting an integer cell from a pandas DataFrame.""" + for dataframe, row_pos, col_pos, expected in self.test_cases: + with self.subTest(dataframe=dataframe, row_pos=row_pos, col_pos=col_pos): + retval = self.node.f(dataframe, row_pos, col_pos) + self.assertEqual(retval, expected, f"Mismatch for row_pos={row_pos}, col_pos={col_pos}") + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/tests/pandas_wrapper/pandas_iat_set_datetime_test.py b/tests/pandas_wrapper/pandas_iat_set_datetime_test.py new file mode 100644 index 0000000..d5b19f7 --- /dev/null +++ b/tests/pandas_wrapper/pandas_iat_set_datetime_test.py @@ -0,0 +1,47 @@ +import os +import sys +import unittest +import pandas as pd +from datetime import datetime + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_iat_set_datetime import PandasIatSetDatetime + +class TestPandasIatSetDatetime(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasIatSetDatetime() + self.test_cases = [ + # Test with datetime values + ( + pd.DataFrame([[None]]), + 0, 0, datetime(2023, 3, 15, 12, 0, 0) + ), + ( + pd.DataFrame([[None]]), + 0, 0, datetime(2024, 6, 1, 9, 30, 0) + ), + # Test with multiple rows and columns + ( + pd.DataFrame([[None, None], [None, None]]), + 1, 1, datetime(2019, 7, 4, 18, 45, 30) + ), + ( + pd.DataFrame([[None, None]]), + 0, 1, datetime(2018, 11, 11, 11, 11, 11) + ), + ] + + def test_set_datetime_cell(self): + """Test setting a datetime cell in a pandas DataFrame.""" + for dataframe, row_pos, col_pos, data in self.test_cases: + with self.subTest(dataframe=dataframe, row_pos=row_pos, col_pos=col_pos): + retval = self.node.f(dataframe, row_pos, col_pos, data) + self.assertEqual(retval[0].iat[row_pos, col_pos], + data, + f"Mismatch for row_pos={row_pos}, col_pos={col_pos}") + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/tests/pandas_wrapper/pandas_iat_set_float_test.py b/tests/pandas_wrapper/pandas_iat_set_float_test.py new file mode 100644 index 0000000..116516e --- /dev/null +++ b/tests/pandas_wrapper/pandas_iat_set_float_test.py @@ -0,0 +1,46 @@ +import os +import sys +import unittest +import pandas as pd + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_iat_set_float import PandasIatSetFloat + +class TestPandasIatSetFloat(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasIatSetFloat() + self.test_cases = [ + # Test with float values + ( + pd.DataFrame([[None]]), + 0, 0, 3.14 + ), + ( + pd.DataFrame([[None]]), + 0, 0, 2.71 + ), + # Test with multiple rows and columns + ( + pd.DataFrame([[None, None], [None, None]]), + 1, 1, 1.618 + ), + ( + pd.DataFrame([[None, None]]), + 0, 1, 0.577 + ), + ] + + def test_set_float_cell(self): + """Test setting a float cell in a pandas DataFrame.""" + for dataframe, row_pos, col_pos, data in self.test_cases: + with self.subTest(dataframe=dataframe, row_pos=row_pos, col_pos=col_pos): + retval = self.node.f(dataframe, row_pos, col_pos, data) + self.assertEqual(retval[0].iat[row_pos, col_pos], + data, + f"Mismatch for row_pos={row_pos}, col_pos={col_pos}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pandas_wrapper/pandas_iat_set_int_test.py b/tests/pandas_wrapper/pandas_iat_set_int_test.py new file mode 100644 index 0000000..4d4c007 --- /dev/null +++ b/tests/pandas_wrapper/pandas_iat_set_int_test.py @@ -0,0 +1,46 @@ +import os +import sys +import unittest +import pandas as pd + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_iat_set_int import PandasIatSetInt + +class TestPandasIatSetInt(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasIatSetInt() + self.test_cases = [ + # Test with integer values + ( + pd.DataFrame([[None]]), + 0, 0, 10 + ), + ( + pd.DataFrame([[None]]), + 0, 0, 20 + ), + # Test with multiple rows and columns + ( + pd.DataFrame([[None, None], [None, None]]), + 1, 1, 30 + ), + ( + pd.DataFrame([[None, None]]), + 0, 1, 40 + ), + ] + + def test_set_int_cell(self): + """Test setting an integer cell in a pandas DataFrame.""" + for dataframe, row_pos, col_pos, data in self.test_cases: + with self.subTest(dataframe=dataframe, row_pos=row_pos, col_pos=col_pos): + retval = self.node.f(dataframe, row_pos, col_pos, data) + self.assertEqual(retval[0].iat[row_pos, col_pos], + data, + f"Mismatch for row_pos={row_pos}, col_pos={col_pos}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pandas_wrapper/pandas_iat_set_string_test.py b/tests/pandas_wrapper/pandas_iat_set_string_test.py new file mode 100644 index 0000000..911b7b2 --- /dev/null +++ b/tests/pandas_wrapper/pandas_iat_set_string_test.py @@ -0,0 +1,46 @@ +import os +import sys +import unittest +import pandas as pd + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_iat_set_string import PandasIatSetString + +class TestPandasIatSetString(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasIatSetString() + self.test_cases = [ + # Test with string values + ( + pd.DataFrame([[None]]), + 0, 0, "hello" + ), + ( + pd.DataFrame([[None]]), + 0, 0, "world" + ), + # Test with multiple rows and columns + ( + pd.DataFrame([[None, None], [None, None]]), + 1, 1, "foo" + ), + ( + pd.DataFrame([[None, None]]), + 0, 1, "bar" + ), + ] + + def test_set_string_cell(self): + """Test setting a string cell in a pandas DataFrame.""" + for dataframe, row_pos, col_pos, data in self.test_cases: + with self.subTest(dataframe=dataframe, row_pos=row_pos, col_pos=col_pos): + retval = self.node.f(dataframe, row_pos, col_pos, data) + self.assertEqual(retval[0].iat[row_pos, col_pos], + data, + f"Mismatch for row_pos={row_pos}, col_pos={col_pos}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pandas_wrapper/pandas_iat_string_test.py b/tests/pandas_wrapper/pandas_iat_string_test.py new file mode 100644 index 0000000..da73522 --- /dev/null +++ b/tests/pandas_wrapper/pandas_iat_string_test.py @@ -0,0 +1,54 @@ +import os +import sys +import unittest +import pandas as pd + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_iat_string import PandasIatString + +class TestPandasIatString(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasIatString() + self.test_cases = [ + # Test with string values + ( + pd.DataFrame({"a": ["hello"]}), + 0, 0, + ("hello",) + ), + ( + pd.DataFrame({"a": ["world"]}), + 0, 0, + ("world",) + ), + # Test with multiple rows and columns + ( + pd.DataFrame({ + "a": ["foo", "bar"], + "b": ["baz", "qux"] + }), + 1, 1, + ("qux",) + ), + ( + pd.DataFrame({ + 1: ["alpha"], + 2: ["beta"] + }), + 0, 1, + ("beta",) + ), + ] + + def test_select_string_cell(self): + """Test selecting a string cell from a pandas DataFrame.""" + for dataframe, row_pos, col_pos, expected in self.test_cases: + with self.subTest(dataframe=dataframe, row_pos=row_pos, col_pos=col_pos): + retval = self.node.f(dataframe, row_pos, col_pos) + self.assertEqual(retval, expected, f"Mismatch for row_pos={row_pos}, col_pos={col_pos}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pandas_wrapper/pandas_loc_cell_string_test.py b/tests/pandas_wrapper/pandas_loc_cell_string_test.py new file mode 100644 index 0000000..6296b5e --- /dev/null +++ b/tests/pandas_wrapper/pandas_loc_cell_string_test.py @@ -0,0 +1,68 @@ +import os +import sys +import unittest +import pandas as pd + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) +from pandas_wrapper.pandas_loc_cell_string import PandasLocCellString + +class TestPandasAtString(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PandasLocCellString() + self.test_cases = [ + # Test with string values and string indices + ( + pd.DataFrame({"a": ["apple"]}, index=["row1"]), + "row1", "string", "a", "string", + ("apple",) + ), + ( + pd.DataFrame({"a": ["banana"]}, index=["row2"]), + "row2", "string", "a", "string", + ("banana",) + ), + + # Test with integer indices + ( + pd.DataFrame({"a": ["cherry"]}, index=[0]), + "0", "int", "a", "string", + ("cherry",) + ), + ( + pd.DataFrame({"a": ["date"]}, index=[1]), + "1", "int", "a", "string", + ("date",) + ), + + # Test with integer column labels + ( + pd.DataFrame({1: ["elderberry"]}, index=[0]), + "0", "int", 1, "int", + ("elderberry",) + ), + ( + pd.DataFrame({2: ["fig"]}, index=[1]), + "1", "int", 2, "int", + ("fig",) + ), + + # Mixed types: string index, integer column label + ( + pd.DataFrame({1: ["grape"]}, index=["event"]), + "event", "string", 1, "int", + ("grape",) + ), + ] + + def test_select_string_cell(self): + """Test selecting a string cell from a pandas DataFrame.""" + for dataframe, row_index, row_index_type, column_label, column_label_type, expected in self.test_cases: + with self.subTest(dataframe=dataframe, row_index=row_index, column_label=column_label): + retval = self.node.f(dataframe, row_index, row_index_type, column_label, column_label_type) + self.assertEqual(retval, expected, f"Mismatch for row_index={row_index}, column_label={column_label}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_evaluate_classification_conv_model_test.py b/tests/pytorch_wrapper/pt_evaluate_classification_conv_model_test.py index b0d30cd..78e2509 100644 --- a/tests/pytorch_wrapper/pt_evaluate_classification_conv_model_test.py +++ b/tests/pytorch_wrapper/pt_evaluate_classification_conv_model_test.py @@ -55,7 +55,7 @@ class TestPtEvaluate(unittest.TestCase): epochs = 1 self.loaded_model = self.load_model.f(self.model, f"fashion_mnist_{epochs}_epochs_conv.pt") - # Instntiates evaluation node + # Instantiates evaluation node self.evaluate = PtEvaluateClassificationModel() def test_evaluation(self):