Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(VirtualDataframe): fixing virtual dataframe name conflict #1531

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading