Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Allow Column type for timezone argument in pyspark.sql.functions #380

Closed
charlietsai opened this issue Mar 11, 2020 · 4 comments · Fixed by #383
Closed

Allow Column type for timezone argument in pyspark.sql.functions #380

charlietsai opened this issue Mar 11, 2020 · 4 comments · Fixed by #383

Comments

@charlietsai
Copy link
Contributor

In the functions here:

def from_utc_timestamp(timestamp: ColumnOrName, tz: str) -> Column: ...
def to_utc_timestamp(timestamp: ColumnOrName, tz: str) -> Column: ...

we currently have tz: str but this can also be specified as a Column

Example:

>>> from pyspark.sql import functions
>>> df = spark.sql("SELECT CAST(0 AS TIMESTAMP) AS timestamp, 'Asia/Tokyo' AS tz")
>>> df.select(functions.from_utc_timestamp(df.timestamp, df.tz)).collect()
[Row(from_utc_timestamp(timestamp, tz)=datetime.datetime(1970, 1, 1, 18, 0))]

I think this could be expanded to tz: ColumnOrName?

@zero323
Copy link
Owner

zero323 commented Mar 13, 2020

Thanks for reporting @charlietsai. Care to open a PR for this?

I think this could be expanded to tz: ColumnOrName?

Indeed, although in this particular case I'd prefer to have explicit Union[Column, str] to stress out that meaning is different from ColumnOrName. It won't make any difference for the type checker, but can make a big one for anyone who reads the annotation.

@charlietsai
Copy link
Contributor Author

Makes sense to me! Opening a PR

@zero323
Copy link
Owner

zero323 commented Apr 10, 2020

Thank you @charlietsai. Merged into master and backported to branch-3.0 and branch-2.4

@charlietsai
Copy link
Contributor Author

Thanks @zero323 for this work!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants