Skip to content

Commit

Permalink
Correcting the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
oualib committed Oct 3, 2024
1 parent e5f5fdd commit 6c046c2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
35 changes: 24 additions & 11 deletions verticapy/core/vdataframe/_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,27 +1317,39 @@ def store_usage(self) -> int:
)
return store_usage

def rename(self, new_name: str) -> "vDataFrame":
def rename(
self,
new_name: str,
inplace: bool = True,
) -> "vDataFrame":
"""
Renames the vDataColumn by dropping the current vDataColumn
and creating a copy with the specified name.
Renames the vDataColumn. This function is not
directly applied to the input object.
.. warning::
SQL code generation will be slower if the
vDataFrame has been transformed multiple
times, so it's better practice to use this
method when first preparing your data.
It is even recommended to use directly
``vDataFrame.``:py:meth:`~verticapy.vDataFrame.select`
method and do all the renaming within
one single operation.
Parameters
----------
new_name: str
The new vDataColumn alias.
inplace: bool, optional
If set to ``True``, the
:py:class:`~vDataFrame` is replaced
with the new relation.
Returns
-------
vDataFrame
self._parent
result.
Examples
--------
Expand Down Expand Up @@ -1385,8 +1397,7 @@ def rename(self, new_name: str) -> "vDataFrame":
.. ipython:: python
:suppress:
vdf["val"].rename("value")
result = vdf
result = vdf["val"].rename("value", inplace=False)
html_file = open("SPHINX_DIRECTORY/figures/core_vDataFrame_sys_rename.html", "w")
html_file.write(result._repr_html_())
html_file.close()
Expand All @@ -1407,9 +1418,11 @@ def rename(self, new_name: str) -> "vDataFrame":
"By changing the parameter 'new_name', you'll "
"be able to solve this issue."
)
self._parent.eval(name=new_name, expr=old_name)
parent = self.drop(add_history=False)
parent._add_to_history(
f"[Rename]: The vDataColumn {old_name} was renamed '{new_name}'."
res = self._parent.select(
self._parent.get_columns(exclude_columns=[old_name])
+ [f"{old_name} AS {new_name}"]
)
return parent
if inplace:
self._parent.__init__(res.current_relation())
return self._parent
return res
3 changes: 1 addition & 2 deletions verticapy/tests_new/core/vdataframe/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,5 @@ def test_rename(self, titanic_vd_fun):
"""
test function - rename
"""
titanic_vd_fun["sex"].rename("gender")
columns = titanic_vd_fun.get_columns()
columns = titanic_vd_fun["sex"].rename("gender", inplace=False).get_columns()
assert '"gender"' in columns and '"sex"' not in columns

0 comments on commit 6c046c2

Please sign in to comment.