Skip to content

Commit

Permalink
fix(VirtualDataframe): fixing virtual dataframe name conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
scaliseraoul committed Jan 20, 2025
1 parent 9316e16 commit 0b838f3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
29 changes: 15 additions & 14 deletions pandasai/dataframe/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ class DataFrame(pd.DataFrame):
config (Config): Configuration settings
"""

_metadata: ClassVar[list] = [
"name",
"description",
"schema",
"path",
"config",
_metadata = [
"_agent",
"_column_hash",
"config",
"description",
"name",
"path",
"schema",
]

def __init__(
Expand All @@ -56,21 +56,22 @@ def __init__(
copy: bool | None = None,
**kwargs,
) -> None:
_name: Optional[str] = kwargs.pop("name", None)
_schema: Optional[SemanticLayerSchema] = kwargs.pop("schema", None)
_description: Optional[str] = kwargs.pop("description", None)
_path: Optional[str] = kwargs.pop("path", None)

super().__init__(
data=data, index=index, columns=columns, dtype=dtype, copy=copy
)

self.name: Optional[str] = kwargs.pop("name", None)
self._column_hash = self._calculate_column_hash()

if not self.name:
self.name = f"table_{self._column_hash}"

schema: Optional[SemanticLayerSchema] = kwargs.pop("schema", None)
self.schema = schema or DataFrame.get_default_schema(self)
self.name = _name or f"table_{self._column_hash}"
self.schema = _schema or DataFrame.get_default_schema(self)
self.description = _description
self.path = _path

self.description: Optional[str] = kwargs.pop("description", None)
self.path: Optional[str] = kwargs.pop("path", None)
self.config = pai.config.get()
self._agent: Optional[Agent] = None

Expand Down
15 changes: 9 additions & 6 deletions pandasai/dataframe/virtual_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@


class VirtualDataFrame(DataFrame):
_metadata: ClassVar[list] = [
_metadata = [
"_agent",
"_column_hash",
"_head",
"_loader",
"config",
"description",
"head",
"_head",
"name",
"path",
"schema",
"config",
"_agent",
"_column_hash",
]

def __init__(self, *args, **kwargs):
Expand All @@ -34,6 +37,7 @@ def __init__(self, *args, **kwargs):
raise VirtualizationError("Schema is required for virtualization!")

table_name = schema.source.table

description = schema.description

super().__init__(
Expand All @@ -47,7 +51,6 @@ def __init__(self, *args, **kwargs):
def head(self):
if self._head is None:
self._head = self._loader.load_head()

return self._head

@property
Expand Down

0 comments on commit 0b838f3

Please sign in to comment.