Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1842841, SNOW-1875014: Add support for DataFrame.pop and Series.pop #2833

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
- %X: Locale’s appropriate time representation.
- %%: A literal '%' character.
- Added support for `Series.between`.
- Added support for `DataFrame.pop` and `Series.pop`.

#### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion docs/source/modin/supported/dataframe_supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Methods
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``plot`` | D | | Performed locally on the client |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``pop`` | N | | |
| ``pop`` | Y | | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``pow`` | P | ``level`` | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/source/modin/supported/series_supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ Methods
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``plot`` | D | | Performed locally on the client |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``pop`` | N | | |
| ``pop`` | Y | | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``pow`` | P | ``level`` | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
Expand Down
37 changes: 37 additions & 0 deletions src/snowflake/snowpark/modin/plugin/docstrings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,43 @@ def pipe():
def pop():
"""
Return item and drop from frame. Raise KeyError if not found.

Parameters
----------
item : label
Label of column to be popped.

Returns
-------
Series

Examples
--------
>>> df = pd.DataFrame([('falcon', 'bird', 389.0),
... ('parrot', 'bird', 24.0),
... ('lion', 'mammal', 80.5),
... ('monkey', 'mammal', np.nan)],
... columns=('name', 'class', 'max_speed'))
>>> df
name class max_speed
0 falcon bird 389.0
1 parrot bird 24.0
2 lion mammal 80.5
3 monkey mammal NaN

>>> df.pop('class')
0 bird
1 bird
2 mammal
3 mammal
Name: class, dtype: object

>>> df
name max_speed
0 falcon 389.0
1 parrot 24.0
2 lion 80.5
3 monkey NaN
"""

def pow():
Expand Down
26 changes: 26 additions & 0 deletions src/snowflake/snowpark/modin/plugin/docstrings/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,32 @@ def plot():
Make plot of Series.
"""

def pop():
"""
Return item and drops from series. Raise KeyError if not found.

Parameters
----------
item : label
Index of the element that needs to be removed.

Returns
-------
Value that is popped from series.

Examples
--------
>>> ser = pd.Series([1, 2, 3])

>>> ser.pop(0)
1

>>> ser
1 2
2 3
dtype: int64
"""

@_create_operator_docstring(pandas.core.series.Series.pow, overwrite_existing=True)
def pow():
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,6 @@ def pipe(self, func, *args, **kwargs): # noqa: PR01, RT01, D200
pass # pragma: no cover


@register_base_not_implemented()
def pop(self, item): # noqa: PR01, RT01, D200
pass # pragma: no cover


@register_base_not_implemented()
def reindex_like(
self, other, method=None, copy=True, limit=None, tolerance=None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,6 @@ def to_xml(
pass # pragma: no cover


@register_dataframe_not_implemented()
def __delitem__(self, key):
pass # pragma: no cover


@register_dataframe_accessor("style")
@property
def style(self): # noqa: RT01, D200
Expand Down
34 changes: 34 additions & 0 deletions tests/integ/modin/frame/test_pop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
#

#
# Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved.
#

import numpy as np
import modin.pandas as pd
import pandas as native_pd

from tests.integ.modin.utils import assert_frame_equal, assert_series_equal
from tests.integ.utils.sql_counter import sql_count_checker


@sql_count_checker(query_count=2)
def test_pop():
native_df = native_pd.DataFrame(
[
("falcon", "bird", 389.0),
("parrot", "bird", 24.0),
("lion", "mammal", 80.5),
("monkey", "mammal", np.nan),
],
columns=("name", "class", "max_speed"),
)
snow_df = pd.DataFrame(native_df)

native_popped_ser = native_df.pop("class")
snow_popped_ser = snow_df.pop("class")

assert_series_equal(snow_popped_ser, native_popped_ser)
assert_frame_equal(snow_df, native_df)
26 changes: 26 additions & 0 deletions tests/integ/modin/series/test_pop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
#

#
# Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved.
#

import modin.pandas as pd
import pandas as native_pd

from tests.integ.modin.utils import assert_series_equal
from tests.integ.utils.sql_counter import sql_count_checker


@sql_count_checker(query_count=5, join_count=2)
def test_pop():
native_ser = native_pd.Series([1, 2, 3])
snow_ser = pd.Series(native_ser)
assert isinstance(snow_ser, pd.Series)

native_popped_val = native_ser.pop(0)
snow_popped_val = snow_ser.pop(0)

assert snow_popped_val == native_popped_val
assert_series_equal(snow_ser, native_ser)
Loading