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

Unify implementation of fillna and isna in Pyspark backend #2882

Merged
merged 5 commits into from
Jul 31, 2021

Conversation

emilyreff7
Copy link
Contributor

Proposed Change

Unify the Pyspark backend's treatment of fillna and isna to match the Pandas backend.

Before this PR:

method input Pyspark Pandas Matches?
fillna np.nan does not fill does fill
fillna None does fill does fill ✔️
isna np.nan True True ✔️
isna None False True

After this PR, the Pyspark behavior for fillna with np.nan, and isna with nulls, will match the Pandas behavior.

Testing

Added tests for Pyspark in test_null.py to assert this new behavior.

@@ -1742,7 +1742,9 @@ def compile_if_null(t, expr, scope, timecontext, **kwargs):
op = expr.op()
col = t.translate(op.arg, scope, timecontext)
ifnull_col = t.translate(op.ifnull_expr, scope, timecontext)
return F.when(col.isNull(), ifnull_col).otherwise(col)
return F.when(col.isNull(), ifnull_col).otherwise(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F.when(col.isNull() | F.isnan(col), ifnull_col).otherwise(col)

Does this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, updated

drop=True
)
tm.assert_frame_equal(result, expected)


def test_fillna(client):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this test to the shared test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to test_generic.py

tm.assert_frame_equal(result, expected)


def test_notnull(client):
table = client.table('nan_table')
def test_isna(client):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to the shared test to ensure same behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to test_generic.py

Copy link
Contributor

@icexelloss icexelloss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Small comments

@datapythonista datapythonista added the pyspark The Apache PySpark backend label Jul 29, 2021
@jreback jreback added this to the Next release milestone Jul 30, 2021
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a release note

@@ -30,6 +30,43 @@ def test_fillna_nullif(backend, con, expr, expected):
assert con.execute(expr) == expected


@pytest.mark.only_on_backends(['pandas', 'dask', 'pyspark'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do these work on other backends?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They error out in SQL, impala, etc. https://github.com/ibis-project/ibis/runs/3196422295

Copy link
Contributor

@icexelloss icexelloss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jreback jreback merged commit 335411e into ibis-project:master Jul 31, 2021
@jreback
Copy link
Contributor

jreback commented Jul 31, 2021

thanks @emilyreff7

@cpcloud cpcloud removed this from the Next release milestone Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pyspark The Apache PySpark backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants