Skip to content

Commit 803c6dd

Browse files
chelsea-linsycai
andauthored
chore: include source columns in semantics.top_k (#1531)
Co-authored-by: Shenyang Cai <sycai@users.noreply.github.com>
1 parent 4b0cf57 commit 803c6dd

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

bigframes/operations/semantics.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -807,13 +807,17 @@ def top_k(
807807
>>> import bigframes.ml.llm as llm
808808
>>> model = llm.GeminiTextGenerator(model_name="gemini-1.5-flash-001")
809809
810-
>>> df = bpd.DataFrame({"Animals": ["Dog", "Bird", "Cat", "Horse"]})
810+
>>> df = bpd.DataFrame(
811+
... {
812+
... "Animals": ["Dog", "Bird", "Cat", "Horse"],
813+
... "Sounds": ["Woof", "Chirp", "Meow", "Neigh"],
814+
... })
811815
>>> df.semantics.top_k("{Animals} are more popular as pets", model=model, k=2)
812-
Animals
813-
0 Dog
814-
2 Cat
816+
Animals Sounds
817+
0 Dog Woof
818+
2 Cat Meow
815819
<BLANKLINE>
816-
[2 rows x 1 columns]
820+
[2 rows x 2 columns]
817821
818822
Args:
819823
instruction (str):
@@ -911,14 +915,8 @@ def top_k(
911915
)
912916
num_selected += num_new_selected
913917

914-
df = (
915-
df[df[status_column] > 0]
916-
.drop(["index", status_column], axis=1)
917-
.rename(columns={"old_index": "index"})
918-
.set_index("index")
919-
)
920-
df.index.name = None
921-
return df
918+
result_df: bigframes.dataframe.DataFrame = self._df.copy()
919+
return result_df[df.set_index("old_index")[status_column] > 0.0]
922920

923921
@staticmethod
924922
def _topk_partition(

0 commit comments

Comments
 (0)