Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bigframes/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,9 @@ def to_numpy(self, dtype=None, *, allow_large_results=None, **kwargs) -> np.ndar

__array__ = to_numpy

def to_list(self, *, allow_large_results: Optional[bool] = None) -> list:
return self.to_pandas(allow_large_results=allow_large_results).to_list()

def __len__(self):
return self.shape[0]

Expand Down
6 changes: 6 additions & 0 deletions tests/system/small/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,12 @@ def test_index_item_with_empty(session):
bf_idx_empty.item()


def test_index_to_list(scalars_df_index, scalars_pandas_df_index):
bf_result = scalars_df_index.index.to_list()
pd_result = scalars_pandas_df_index.index.to_list()
assert bf_result == pd_result


@pytest.mark.parametrize(
("key", "value"),
[
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pandas as pd
import pytest

from bigframes.testing import mocks
Expand All @@ -38,3 +39,13 @@ def test_index_rename_inplace_returns_none(monkeypatch: pytest.MonkeyPatch):
# Make sure the linked DataFrame is updated, too.
assert dataframe.index.name == "my_index_name"
assert index.name == "my_index_name"


def test_index_to_list(monkeypatch: pytest.MonkeyPatch):
pd_index = pd.Index([1, 2, 3], name="my_index")
df = mocks.create_dataframe(
monkeypatch,
data={"my_index": [1, 2, 3]},
).set_index("my_index")
bf_index = df.index
assert bf_index.to_list() == pd_index.to_list()