You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by gu...@apache.org on 2022/07/06 23:54:07 UTC
[spark] branch master updated: [SPARK-39648][PYTHON][PS][DOC] Fix type hints of `like`, `rlike`, `ilike` of Column
This is an automated email from the ASF dual-hosted git repository.
gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new be7dab12677 [SPARK-39648][PYTHON][PS][DOC] Fix type hints of `like`, `rlike`, `ilike` of Column
be7dab12677 is described below
commit be7dab12677a180908b6ce37847abdda12adeb9b
Author: Xinrong Meng <xi...@databricks.com>
AuthorDate: Thu Jul 7 08:53:50 2022 +0900
[SPARK-39648][PYTHON][PS][DOC] Fix type hints of `like`, `rlike`, `ilike` of Column
### What changes were proposed in this pull request?
Fix type hints of `like`, `rlike`, `ilike` of Column.
### Why are the changes needed?
Current type hints are incorrect so the doc is confusing: `Union["Column", "LiteralType", "DecimalLiteral", "DateTimeLiteral"]]` is hinted whereas only `str` is accepted.
The PR is proposed to adjust the above issue by introducing `_bin_op_other_str`.
### Does this PR introduce _any_ user-facing change?
No. Doc change only.
### How was this patch tested?
Manual tests.
Closes #37038 from xinrong-databricks/like_rlike.
Authored-by: Xinrong Meng <xi...@databricks.com>
Signed-off-by: Hyukjin Kwon <gu...@apache.org>
---
python/pyspark/pandas/series.py | 2 +-
python/pyspark/sql/column.py | 117 +++++++++++++++++++++-------------------
2 files changed, 64 insertions(+), 55 deletions(-)
diff --git a/python/pyspark/pandas/series.py b/python/pyspark/pandas/series.py
index a7852c110f7..838077ed7cd 100644
--- a/python/pyspark/pandas/series.py
+++ b/python/pyspark/pandas/series.py
@@ -5024,7 +5024,7 @@ class Series(Frame, IndexOpsMixin, Generic[T]):
else:
if regex:
# to_replace must be a string
- cond = self.spark.column.rlike(to_replace)
+ cond = self.spark.column.rlike(cast(str, to_replace))
else:
cond = self.spark.column.isin(to_replace)
# to_replace may be a scalar
diff --git a/python/pyspark/sql/column.py b/python/pyspark/sql/column.py
index 04458d560ee..31954a95690 100644
--- a/python/pyspark/sql/column.py
+++ b/python/pyspark/sql/column.py
@@ -573,57 +573,6 @@ class Column:
>>> df.filter(df.name.contains('o')).collect()
[Row(age=5, name='Bob')]
"""
- _rlike_doc = """
- SQL RLIKE expression (LIKE with Regex). Returns a boolean :class:`Column` based on a regex
- match.
-
- Parameters
- ----------
- other : str
- an extended regex expression
-
- Examples
- --------
- >>> df.filter(df.name.rlike('ice$')).collect()
- [Row(age=2, name='Alice')]
- """
- _like_doc = """
- SQL like expression. Returns a boolean :class:`Column` based on a SQL LIKE match.
-
- Parameters
- ----------
- other : str
- a SQL LIKE pattern
-
- See Also
- --------
- pyspark.sql.Column.rlike
-
- Examples
- --------
- >>> df.filter(df.name.like('Al%')).collect()
- [Row(age=2, name='Alice')]
- """
- _ilike_doc = """
- SQL ILIKE expression (case insensitive LIKE). Returns a boolean :class:`Column`
- based on a case insensitive match.
-
- .. versionadded:: 3.3.0
-
- Parameters
- ----------
- other : str
- a SQL LIKE pattern
-
- See Also
- --------
- pyspark.sql.Column.rlike
-
- Examples
- --------
- >>> df.filter(df.name.ilike('%Ice')).collect()
- [Row(age=2, name='Alice')]
- """
_startswith_doc = """
String starts with. Returns a boolean :class:`Column` based on a string match.
@@ -656,12 +605,72 @@ class Column:
"""
contains = _bin_op("contains", _contains_doc)
- rlike = _bin_op("rlike", _rlike_doc)
- like = _bin_op("like", _like_doc)
- ilike = _bin_op("ilike", _ilike_doc)
startswith = _bin_op("startsWith", _startswith_doc)
endswith = _bin_op("endsWith", _endswith_doc)
+ def like(self: "Column", other: str) -> "Column":
+ """
+ SQL like expression. Returns a boolean :class:`Column` based on a SQL LIKE match.
+
+ Parameters
+ ----------
+ other : str
+ a SQL LIKE pattern
+
+ See Also
+ --------
+ pyspark.sql.Column.rlike
+
+ Examples
+ --------
+ >>> df.filter(df.name.like('Al%')).collect()
+ [Row(age=2, name='Alice')]
+ """
+ njc = getattr(self._jc, "like")(other)
+ return Column(njc)
+
+ def rlike(self: "Column", other: str) -> "Column":
+ """
+ SQL RLIKE expression (LIKE with Regex). Returns a boolean :class:`Column` based on a regex
+ match.
+
+ Parameters
+ ----------
+ other : str
+ an extended regex expression
+
+ Examples
+ --------
+ >>> df.filter(df.name.rlike('ice$')).collect()
+ [Row(age=2, name='Alice')]
+ """
+ njc = getattr(self._jc, "rlike")(other)
+ return Column(njc)
+
+ def ilike(self: "Column", other: str) -> "Column":
+ """
+ SQL ILIKE expression (case insensitive LIKE). Returns a boolean :class:`Column`
+ based on a case insensitive match.
+
+ .. versionadded:: 3.3.0
+
+ Parameters
+ ----------
+ other : str
+ a SQL LIKE pattern
+
+ See Also
+ --------
+ pyspark.sql.Column.rlike
+
+ Examples
+ --------
+ >>> df.filter(df.name.ilike('%Ice')).collect()
+ [Row(age=2, name='Alice')]
+ """
+ njc = getattr(self._jc, "ilike")(other)
+ return Column(njc)
+
@overload
def substr(self, startPos: int, length: int) -> "Column":
...
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org