-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(loader): renames _load_from_source to _load_from_local_sourc…
…e removes unreachable code and adds tests for _load_from_local_source (#1514) * refactor(loader): renames _load_from_source to _load_from_local_source, removes unreachable code and adds tests for _load_from_local_source * chore: fixing ruff formatting * Update pandasai/data_loader/loader.py Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
- Loading branch information
1 parent
9fe0d32
commit 5030471
Showing
2 changed files
with
43 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
from pandasai.data_loader.loader import DatasetLoader | ||
from pandasai.dataframe.base import DataFrame | ||
from pandasai.exceptions import InvalidDataSourceType | ||
|
||
|
||
class TestDatasetLoader: | ||
|
@@ -109,8 +110,8 @@ def test_load_from_cache(self, sample_schema): | |
) as mock_read_cache, patch( | ||
"builtins.open", mock_open(read_data=str(sample_schema)) | ||
), patch( | ||
"pandasai.data_loader.loader.DatasetLoader._load_from_source" | ||
) as mock_load_source, patch( | ||
"pandasai.data_loader.loader.DatasetLoader._load_from_local_source" | ||
) as mock_load_local_source, patch( | ||
"pandasai.data_loader.loader.DatasetLoader.load_head" | ||
) as mock_load_head: | ||
loader = DatasetLoader() | ||
|
@@ -126,7 +127,34 @@ def test_load_from_cache(self, sample_schema): | |
assert isinstance(result, DataFrame) | ||
assert "email" in result.columns | ||
mock_read_cache.assert_called_once() | ||
mock_load_source.assert_not_called() | ||
mock_load_local_source.assert_not_called() | ||
|
||
def test_load_from_local_source_valid(self, sample_schema): | ||
with patch("os.path.exists", return_value=True), patch( | ||
"pandasai.data_loader.loader.DatasetLoader._read_csv_or_parquet" | ||
) as mock_read_csv_or_parquet: | ||
loader = DatasetLoader() | ||
loader.dataset_path = "test" | ||
loader.schema = sample_schema | ||
|
||
mock_read_csv_or_parquet.return_value = DataFrame( | ||
{"email": ["[email protected]"]} | ||
) | ||
|
||
result = loader._load_from_local_source() | ||
|
||
assert isinstance(result, DataFrame) | ||
assert "email" in result.columns | ||
|
||
def test_load_from_local_source_invalid_source_type(self, sample_schema): | ||
loader = DatasetLoader() | ||
sample_schema["source"]["type"] = "mysql" | ||
loader.schema = sample_schema | ||
|
||
with pytest.raises( | ||
InvalidDataSourceType, match="Unsupported local source type" | ||
): | ||
loader._load_from_local_source() | ||
|
||
def test_anonymize_method(self): | ||
loader = DatasetLoader() | ||
|