Skip to content

Commit 8464b87

Browse files
linting
1 parent 0f61de5 commit 8464b87

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

pandasai/core/code_generation/code_cleaning.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ def _remove_make_dirs(self, code: str) -> str:
191191
code_lines = code.splitlines()
192192
cleaned_lines = []
193193
for line in code_lines:
194-
if DEFAULT_CHART_DIRECTORY not in line and ("os.makedirs(" in line or "os.mkdir(" in line):
194+
if DEFAULT_CHART_DIRECTORY not in line and (
195+
"os.makedirs(" in line or "os.mkdir(" in line
196+
):
195197
continue
196198
cleaned_lines.append(line)
197199
return "\n".join(cleaned_lines)

pandasai/core/response/interactive_chart.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def _get_chart(self) -> dict:
2222

2323
return json.loads(self.value)
2424

25-
raise ValueError("Invalid value type for InteractiveChartResponse. Expected dict or str.")
25+
raise ValueError(
26+
"Invalid value type for InteractiveChartResponse. Expected dict or str."
27+
)
2628

2729
def save(self, path: str):
2830
img = self._get_chart()
@@ -37,7 +39,9 @@ def get_dict_image(self) -> dict:
3739

3840
def _validate(self):
3941
if not isinstance(self.value, (dict, str)):
40-
raise ValueError("InteractiveChartResponse value must be a dict or a str representing a file path.")
42+
raise ValueError(
43+
"InteractiveChartResponse value must be a dict or a str representing a file path."
44+
)
4145

4246
# if a string, it can be a path to a file or a JSON string
4347
if isinstance(self.value, str):
@@ -46,4 +50,6 @@ def _validate(self):
4650
except json.JSONDecodeError:
4751
# If it fails, check if it's a valid file path
4852
if not os.path.exists(self.value):
49-
raise ValueError("InteractiveChartResponse value must be a valid file path or a JSON string.")
53+
raise ValueError(
54+
"InteractiveChartResponse value must be a valid file path or a JSON string."
55+
)

tests/unit_tests/core/code_generation/test_code_cleaning.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ def test_replace_output_filenames_with_temp_json_chart_no_json(self):
205205

206206
result = handler._replace_output_filenames_with_temp_json_chart(code)
207207

208-
self.assertEqual(
209-
result, code, f"Expected '{code}', but got '{result}'"
210-
)
208+
self.assertEqual(result, code, f"Expected '{code}', but got '{result}'")
211209

212210
def test_remove_make_dirs(self):
213211
handler = self.cleaner
@@ -231,15 +229,11 @@ def test_do_not_remove_make_default_chart_dir(self):
231229

232230
code = f"os.makedirs({DEFAULT_CHART_DIRECTORY}')\nplt.show()\nfig.show()"
233231
result = handler._remove_make_dirs(code)
234-
self.assertEqual(
235-
result, code, f"Expected '{code}', but got '{result}'"
236-
)
232+
self.assertEqual(result, code, f"Expected '{code}', but got '{result}'")
237233

238234
code = f"os.mkdir({DEFAULT_CHART_DIRECTORY}')\nplt.show()\nfig.show()"
239235
result = handler._remove_make_dirs(code)
240-
self.assertEqual(
241-
result, code, f"Expected '{code}', but got '{result}'"
242-
)
236+
self.assertEqual(result, code, f"Expected '{code}', but got '{result}'")
243237

244238

245239
if __name__ == "__main__":

tests/unit_tests/helpers/test_responses.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
from unittest.mock import MagicMock, patch
55

66
import pandas as pd
7-
from PIL import Image
8-
97
import pytest
8+
from PIL import Image
109

1110
from pandasai.core.response import (
1211
ChartResponse,

tests/unit_tests/response/test_interactive_chart_response.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def sample_json():
3434
"width": 100,
3535
"height": 100,
3636
"format": "png",
37-
"data": base64.b64encode(io.BytesIO(b"test_image_data").getvalue()).decode("utf-8"),
37+
"data": base64.b64encode(io.BytesIO(b"test_image_data").getvalue()).decode(
38+
"utf-8"
39+
),
3840
},
3941
}
4042

0 commit comments

Comments
 (0)