r"""Loads a file or DataFrame and returns a SmartDataframe object. args: data (Union[DataFrame, str]): The data to load. *args (Any): Additional positional arguments. **kwargs (Dict[str, Any]): Additional keyword arguments. Returns: S
(
self,
data: Union["DataFrame", str],
*args: Any,
**kwargs: Dict[str, Any],
)
| 87 | } |
| 88 | |
| 89 | def load( |
| 90 | self, |
| 91 | data: Union["DataFrame", str], |
| 92 | *args: Any, |
| 93 | **kwargs: Dict[str, Any], |
| 94 | ) -> "SmartDataframe": |
| 95 | r"""Loads a file or DataFrame and returns a SmartDataframe object. |
| 96 | |
| 97 | args: |
| 98 | data (Union[DataFrame, str]): The data to load. |
| 99 | *args (Any): Additional positional arguments. |
| 100 | **kwargs (Dict[str, Any]): Additional keyword arguments. |
| 101 | |
| 102 | Returns: |
| 103 | SmartDataframe: The SmartDataframe object. |
| 104 | """ |
| 105 | from pandas import DataFrame |
| 106 | from pandasai import SmartDataframe |
| 107 | |
| 108 | if isinstance(data, DataFrame): |
| 109 | return SmartDataframe(data, config=self.config) |
| 110 | file_path = str(data) |
| 111 | path = Path(file_path) |
| 112 | if not file_path.startswith("http") and not path.exists(): |
| 113 | raise FileNotFoundError(f"File {file_path} not found") |
| 114 | if path.suffix in self.__LOADER: |
| 115 | return SmartDataframe( |
| 116 | self.__LOADER[path.suffix](file_path, *args, **kwargs), # type: ignore[operator] |
| 117 | config=self.config, |
| 118 | ) |
| 119 | else: |
| 120 | raise ValueError(f"Unsupported file format: {path.suffix}") |
| 121 | |
| 122 | @check_suffix([".csv"]) |
| 123 | def read_csv( |