Skip to content

Commit

Permalink
fix: cache dir when 'enable_cache' is False (#838) (#845)
Browse files Browse the repository at this point in the history
* (fix): suppress creating cache dir ('Cache' object essentially) when
  'enable_cache' is False in 'PipelineContext' __init__() method
* (refactor): add 'Optional' type for lots of methods parameters in
  'PipelineContext' methods and 'SmartDatalake' methods as well
  • Loading branch information
nautics889 authored Jan 2, 2024
1 parent a6c3a3f commit bbebc3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
15 changes: 9 additions & 6 deletions pandasai/pipelines/pipeline_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PipelineContext:
_dfs: List[Union[DataFrameType, Any]]
_memory: Memory
_skills: SkillsManager
_cache: Cache
_cache: Optional[Cache]
_config: Config
_query_exec_tracker: QueryExecTracker
_intermediate_values: dict
Expand All @@ -25,10 +25,10 @@ def __init__(
self,
dfs: List[Union[DataFrameType, Any]],
config: Optional[Union[Config, dict]] = None,
memory: Memory = None,
skills: SkillsManager = None,
cache: Cache = None,
query_exec_tracker: QueryExecTracker = None,
memory: Optional[Memory] = None,
skills: Optional[SkillsManager] = None,
cache: Optional[Cache] = None,
query_exec_tracker: Optional[QueryExecTracker] = None,
) -> None:
from pandasai.smart_dataframe import load_smartdataframes

Expand All @@ -38,7 +38,10 @@ def __init__(
self._dfs = load_smartdataframes(dfs, config)
self._memory = memory if memory is not None else Memory()
self._skills = skills if skills is not None else SkillsManager()
self._cache = cache if cache is not None else Cache()
if config.enable_cache:
self._cache = cache if cache is not None else Cache()
else:
self._cache = None
self._config = config
self._query_exec_tracker = query_exec_tracker
self._intermediate_values = {}
Expand Down
10 changes: 5 additions & 5 deletions pandasai/smart_datalake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
```python
from pandasai.smart_dataframe import SmartDataframe
from pandasai.llm.openai import OpenAI
df = pd.read_csv("examples/data/Loan payments data.csv")
llm = OpenAI()
df = SmartDataframe(df, config={"llm": llm})
response = df.chat("What is the average loan amount?")
print(response)
Expand Down Expand Up @@ -73,9 +73,9 @@ def __init__(
self,
dfs: List[Union[DataFrameType, Any]],
config: Optional[Union[Config, dict]] = None,
logger: Logger = None,
memory: Memory = None,
cache: Cache = None,
logger: Optional[Logger] = None,
memory: Optional[Memory] = None,
cache: Optional[Cache] = None,
):
"""
Args:
Expand Down

0 comments on commit bbebc3c

Please sign in to comment.