Commit 64817c4
[SPARK-22395][SQL][PYTHON] Fix the behavior of timestamp values for Pandas to respect session timezone
## What changes were proposed in this pull request?
When converting Pandas DataFrame/Series from/to Spark DataFrame using `toPandas()` or pandas udfs, timestamp values behave to respect Python system timezone instead of session timezone.
For example, let's say we use `"America/Los_Angeles"` as session timezone and have a timestamp value `"1970-01-01 00:00:01"` in the timezone. Btw, I'm in Japan so Python timezone would be `"Asia/Tokyo"`.
The timestamp value from current `toPandas()` will be the following:
```
>>> spark.conf.set("spark.sql.session.timeZone", "America/Los_Angeles")
>>> df = spark.createDataFrame([28801], "long").selectExpr("timestamp(value) as ts")
>>> df.show()
+-------------------+
| ts|
+-------------------+
|1970-01-01 00:00:01|
+-------------------+
>>> df.toPandas()
ts
0 1970-01-01 17:00:01
```
As you can see, the value becomes `"1970-01-01 17:00:01"` because it respects Python timezone.
As we discussed in apache#18664, we consider this behavior is a bug and the value should be `"1970-01-01 00:00:01"`.
## How was this patch tested?
Added tests and existing tests.
Author: Takuya UESHIN <[email protected]>
Closes apache#19607 from ueshin/issues/SPARK-22395.1 parent 33d43bf commit 64817c4
File tree
12 files changed
+371
-53
lines changed- docs
- python
- pyspark
- sql
- sql
- catalyst/src/main/scala/org/apache/spark/sql/internal
- core/src/main/scala/org/apache/spark/sql/execution/python
12 files changed
+371
-53
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1716 | 1716 | | |
1717 | 1717 | | |
1718 | 1718 | | |
| 1719 | + | |
| 1720 | + | |
1719 | 1721 | | |
1720 | 1722 | | |
1721 | 1723 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | | - | |
| 209 | + | |
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| 214 | + | |
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
| |||
227 | 228 | | |
228 | 229 | | |
229 | 230 | | |
230 | | - | |
| 231 | + | |
231 | 232 | | |
232 | 233 | | |
233 | 234 | | |
| |||
253 | 254 | | |
254 | 255 | | |
255 | 256 | | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
256 | 261 | | |
257 | 262 | | |
258 | 263 | | |
| |||
262 | 267 | | |
263 | 268 | | |
264 | 269 | | |
265 | | - | |
| 270 | + | |
266 | 271 | | |
267 | 272 | | |
268 | 273 | | |
| |||
280 | 285 | | |
281 | 286 | | |
282 | 287 | | |
283 | | - | |
| 288 | + | |
284 | 289 | | |
285 | 290 | | |
286 | 291 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
1881 | 1882 | | |
1882 | 1883 | | |
1883 | 1884 | | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
1884 | 1892 | | |
1885 | 1893 | | |
1886 | 1894 | | |
| |||
1889 | 1897 | | |
1890 | 1898 | | |
1891 | 1899 | | |
1892 | | - | |
| 1900 | + | |
1893 | 1901 | | |
1894 | 1902 | | |
1895 | 1903 | | |
1896 | 1904 | | |
1897 | 1905 | | |
1898 | | - | |
| 1906 | + | |
1899 | 1907 | | |
1900 | 1908 | | |
1901 | 1909 | | |
| |||
1913 | 1921 | | |
1914 | 1922 | | |
1915 | 1923 | | |
1916 | | - | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
1917 | 1935 | | |
1918 | 1936 | | |
1919 | 1937 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
444 | 445 | | |
445 | 446 | | |
446 | 447 | | |
447 | | - | |
| 448 | + | |
448 | 449 | | |
449 | 450 | | |
450 | 451 | | |
451 | 452 | | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
452 | 476 | | |
453 | 477 | | |
454 | 478 | | |
| |||
462 | 486 | | |
463 | 487 | | |
464 | 488 | | |
465 | | - | |
| 489 | + | |
466 | 490 | | |
467 | 491 | | |
468 | 492 | | |
469 | 493 | | |
470 | 494 | | |
471 | 495 | | |
472 | | - | |
473 | | - | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
474 | 502 | | |
475 | 503 | | |
476 | 504 | | |
| |||
488 | 516 | | |
489 | 517 | | |
490 | 518 | | |
491 | | - | |
| 519 | + | |
| 520 | + | |
492 | 521 | | |
493 | 522 | | |
494 | 523 | | |
| |||
606 | 635 | | |
607 | 636 | | |
608 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
609 | 643 | | |
610 | 644 | | |
611 | 645 | | |
| |||
614 | 648 | | |
615 | 649 | | |
616 | 650 | | |
617 | | - | |
| 651 | + | |
618 | 652 | | |
619 | 653 | | |
620 | 654 | | |
621 | | - | |
| 655 | + | |
622 | 656 | | |
623 | 657 | | |
624 | 658 | | |
| |||
0 commit comments