Skip to content

Conversation

@ueshin
Copy link
Member

@ueshin ueshin commented Jul 26, 2024

What changes were proposed in this pull request?

Make Column APIs and functions accept Enums.

Why are the changes needed?

Enums can be accepted in Column APIs and functions using its value.

>>> from pyspark.sql import functions as F
>>> from enum import Enum
>>> class A(Enum):
...   X = "x"
...   Y = "y"
...
>>> F.lit(A.X)
Column<'x'>
>>> F.lit(A.X) + A.Y
Column<'`+`(x, y)'>

Does this PR introduce any user-facing change?

Yes, Python's Enums will be used as literal values.

How was this patch tested?

Added the related tests.

Was this patch authored or co-authored using generative AI tooling?

No.

@ueshin
Copy link
Member Author

ueshin commented Jul 26, 2024

The failure seems not related to this PR.

@ueshin
Copy link
Member Author

ueshin commented Jul 26, 2024

Thanks! merging to master.

@ueshin ueshin closed this in 7e678a0 Jul 26, 2024
ilicmarkodb pushed a commit to ilicmarkodb/spark that referenced this pull request Jul 29, 2024
### What changes were proposed in this pull request?

Make Column APIs and functions accept `Enum`s.

### Why are the changes needed?

`Enum`s can be accepted in Column APIs and functions using its `value`.

```py
>>> from pyspark.sql import functions as F
>>> from enum import Enum
>>> class A(Enum):
...   X = "x"
...   Y = "y"
...
>>> F.lit(A.X)
Column<'x'>
>>> F.lit(A.X) + A.Y
Column<'`+`(x, y)'>
```
### Does this PR introduce _any_ user-facing change?

Yes, Python's `Enum`s will be used as literal values.

### How was this patch tested?

Added the related tests.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes apache#47495 from ueshin/issues/SPARK-49009/enum.

Authored-by: Takuya Ueshin <ueshin@databricks.com>
Signed-off-by: Takuya Ueshin <ueshin@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants