Skip to content

Commit

Permalink
improve persist example (#322)
Browse files Browse the repository at this point in the history
* improve persist example

* use scalar.persist

* Update spec/API_specification/dataframe_api/dataframe_object.py

Co-authored-by: Keith Kraus <keith.j.kraus@gmail.com>

* remove unnecessary scalar.persist

---------

Co-authored-by: Keith Kraus <keith.j.kraus@gmail.com>
  • Loading branch information
MarcoGorelli and kkraus14 committed Nov 20, 2023
1 parent 1f81476 commit d896e65
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions spec/API_specification/dataframe_api/dataframe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,10 +995,11 @@ def persist(self) -> Self:
.. code-block:: python
df: DataFrame
df = df.persist()
features = []
result = df.std() > 0
result = result.persist()
for column_name in df.column_names:
if df.col(column_name).std() > 0:
if result.col(column_name).get_value(0):
features.append(column_name)
instead of this:
Expand All @@ -1008,7 +1009,8 @@ def persist(self) -> Self:
df: DataFrame
features = []
for column_name in df.column_names:
# Do NOT do this!
# Do NOT call `persist` on a `DataFrame` within a for-loop!
# This may re-trigger the same computation multiple times
if df.persist().col(column_name).std() > 0:
features.append(column_name)
"""
Expand Down

0 comments on commit d896e65

Please sign in to comment.