Skip to content

Commit d896e65

Browse files
improve persist example (#322)
* improve persist example * use scalar.persist * Update spec/API_specification/dataframe_api/dataframe_object.py Co-authored-by: Keith Kraus <[email protected]> * remove unnecessary scalar.persist --------- Co-authored-by: Keith Kraus <[email protected]>
1 parent 1f81476 commit d896e65

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

spec/API_specification/dataframe_api/dataframe_object.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -995,10 +995,11 @@ def persist(self) -> Self:
995995
.. code-block:: python
996996
997997
df: DataFrame
998-
df = df.persist()
999998
features = []
999+
result = df.std() > 0
1000+
result = result.persist()
10001001
for column_name in df.column_names:
1001-
if df.col(column_name).std() > 0:
1002+
if result.col(column_name).get_value(0):
10021003
features.append(column_name)
10031004
10041005
instead of this:
@@ -1008,7 +1009,8 @@ def persist(self) -> Self:
10081009
df: DataFrame
10091010
features = []
10101011
for column_name in df.column_names:
1011-
# Do NOT do this!
1012+
# Do NOT call `persist` on a `DataFrame` within a for-loop!
1013+
# This may re-trigger the same computation multiple times
10121014
if df.persist().col(column_name).std() > 0:
10131015
features.append(column_name)
10141016
"""

0 commit comments

Comments
 (0)