Skip to content

Commit deb015d

Browse files
feat: Add Series.keys() (#1342)
1 parent 05f83d1 commit deb015d

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

bigframes/series.py

+4
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ def values(self) -> numpy.ndarray:
168168
def index(self) -> indexes.Index:
169169
return indexes.Index.from_frame(self)
170170

171+
@validations.requires_index
172+
def keys(self) -> indexes.Index:
173+
return self.index
174+
171175
@property
172176
def query_job(self) -> Optional[bigquery.QueryJob]:
173177
"""BigQuery job metadata for the most recent query.

tests/system/small/test_series.py

+7
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ def test_series_construct_geodata():
228228
)
229229

230230

231+
def test_series_keys(scalars_dfs):
232+
scalars_df, scalars_pandas_df = scalars_dfs
233+
bf_result = scalars_df["int64_col"].keys().to_pandas()
234+
pd_result = scalars_pandas_df["int64_col"].keys()
235+
pd.testing.assert_index_equal(bf_result, pd_result)
236+
237+
231238
@pytest.mark.parametrize(
232239
["data", "index"],
233240
[

third_party/bigframes_vendored/pandas/core/series.py

+19
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,25 @@ def __repr__(self) -> str:
424424
"""
425425
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
426426

427+
def keys(self):
428+
"""
429+
Return alias for index.
430+
431+
**Examples:**
432+
433+
>>> import bigframes.pandas as bpd
434+
>>> bpd.options.display.progress_bar = None
435+
436+
>>> s = bpd.Series([1, 2, 3], index=[0, 1, 2])
437+
>>> s.keys()
438+
Index([0, 1, 2], dtype='Int64')
439+
440+
Returns:
441+
Index:
442+
Index of the Series.
443+
"""
444+
return self.index
445+
427446
# ----------------------------------------------------------------------
428447
# IO methods (to / from other formats)
429448

0 commit comments

Comments
 (0)