diff --git a/focus_validator/rules/checks.py b/focus_validator/rules/checks.py index 58a9497..5a00e08 100644 --- a/focus_validator/rules/checks.py +++ b/focus_validator/rules/checks.py @@ -60,16 +60,14 @@ def check_sql_query(df_groups, sql_query, column_alias): # for the given indexes in false_indexes list, we are extracting the rows from the dataframe and # add column_alias value to failure_case column and index to index column - failure_cases = df[df.index.isin(false_indexes)] - failure_cases["failure_case"] = df.apply( - lambda row: {column: row[column] for column in column_alias}, axis=1 - ) - failure_cases["failure_case"] = df.apply( - lambda row: ",".join( - [f"{column}:{row[column]}" for column in column_alias] - ), - axis=1, + failure_cases = df[df.index.isin(false_indexes)].copy() + error_values = list( + [ + ",".join([f"{column}:{row[column]}" for column in column_alias]) + for _, row in failure_cases.iterrows() + ] ) + failure_cases.loc[:, "failure_case"] = error_values raise SchemaError( schema=pa.DataFrameSchema(), diff --git a/tests/data_loaders/test_null_value_loader.py b/tests/data_loaders/test_null_value_loader.py index b45c9a7..ecd0670 100644 --- a/tests/data_loaders/test_null_value_loader.py +++ b/tests/data_loaders/test_null_value_loader.py @@ -27,7 +27,7 @@ def test_null_value_from_csv_with_missing_value(self): sample_data = pd.DataFrame([{"value": None}]) buffer = io.BytesIO() - sample_data.to_csv(buffer, index=False) + sample_data.to_csv(buffer, index=False, lineterminator="\n") buffer.seek(0) self.assertEqual(buffer.read(), b'value\n""\n')