Skip to content

Commit

Permalink
[SPARK-37207][SQL][PYTHON] Add isEmpty method for the Python DataFram…
Browse files Browse the repository at this point in the history
…e API

### What changes were proposed in this pull request?
Add isEmpty method for the Python DataFrame API

### Why are the changes needed?
Python Scala compatibility

### Does this PR introduce _any_ user-facing change?
Is Empty method would in in data frame api

### How was this patch tested?
Doctests for isEmpty

Closes #34484 from dhirennavani/master.

Authored-by: Dhiren Navani <navanidhiren@gmail.com>
Signed-off-by: Sean Owen <srowen@gmail.com>
  • Loading branch information
dhirennavani authored and srowen committed Nov 7, 2021
1 parent ddf27bd commit 1047708
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/docs/source/reference/pyspark.sql.rst
Expand Up @@ -171,6 +171,7 @@ DataFrame APIs
DataFrame.inputFiles
DataFrame.intersect
DataFrame.intersectAll
DataFrame.isEmpty
DataFrame.isLocal
DataFrame.isStreaming
DataFrame.join
Expand Down
16 changes: 16 additions & 0 deletions python/pyspark/sql/dataframe.py
Expand Up @@ -473,6 +473,22 @@ def isStreaming(self) -> bool:
"""
return self._jdf.isStreaming()

def isEmpty(self) -> bool:
"""Returns ``True`` if this :class:`DataFrame` is empty.
.. versionadded:: 3.3.0
Examples
--------
>>> df_empty = spark.createDataFrame([], 'a STRING')
>>> df_non_empty = spark.createDataFrame([("a")], 'STRING')
>>> df_empty.isEmpty()
True
>>> df_non_empty.isEmpty()
False
"""
return self._jdf.isEmpty()

def show(self, n: int = 20, truncate: Union[bool, int] = True, vertical: bool = False) -> None:
"""Prints the first ``n`` rows to the console.
Expand Down

0 comments on commit 1047708

Please sign in to comment.