timsaucer commented on code in PR #908:
URL: https://github.com/apache/datafusion-python/pull/908#discussion_r1798309123
##########
python/datafusion/dataframe.py:
##########
@@ -175,7 +178,23 @@ def with_column_renamed(self, old_name: str, new_name:
str) -> DataFrame:
Returns:
DataFrame with the column renamed.
"""
- return DataFrame(self.df.with_column_renamed(old_name, new_name))
+ return DataFrame(self.df.rename({old_name: new_name}))
+
+ def rename(self, mapping: dict[str, str]) -> DataFrame:
+ r"""Rename one or multiple columns by applying a new projection.
Review Comment:
How about `with_columns_renamed` to be more clear what this is doing? I
could imagine users confusing this changing a table's name, even though the
dataframe doesn't have a `name` associated with it.
##########
python/datafusion/dataframe.py:
##########
@@ -160,6 +160,9 @@ def with_column(self, name: str, expr: Expr) -> DataFrame:
"""
return DataFrame(self.df.with_column(name, expr.expr))
+ @deprecated(
+ "with_column_renamed() is deprecated. Use :py:meth:`~DataFrame.rename`
instead"
+ )
Review Comment:
I would remove this `deprecated` marker. I think it's okay to have this kind
of alias permanently as it is useful to end users.
##########
python/datafusion/dataframe.py:
##########
@@ -175,7 +178,23 @@ def with_column_renamed(self, old_name: str, new_name:
str) -> DataFrame:
Returns:
DataFrame with the column renamed.
"""
- return DataFrame(self.df.with_column_renamed(old_name, new_name))
+ return DataFrame(self.df.rename({old_name: new_name}))
+
+ def rename(self, mapping: dict[str, str]) -> DataFrame:
+ r"""Rename one or multiple columns by applying a new projection.
+
+ This is a no-op if the column to be renamed does not exist.
+
+ The method supports case sensitive rename with wrapping column name
+ into one the following symbols (" or ' or \`).
+
+ Args:
+ mapping (dict[str, str]): mapping of old (key) to new (value) names
Review Comment:
I don't think we need to duplicate the type hints both in the args list and
in the function declaration
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]