You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by HyukjinKwon <gi...@git.apache.org> on 2017/08/15 14:49:39 UTC

[GitHub] spark pull request #18933: [WIP][SPARK-21722][SQL][PYTHON] Enable timezone-a...

Github user HyukjinKwon commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18933#discussion_r133209362
  
    --- Diff: python/pyspark/sql/tests.py ---
    @@ -2507,6 +2507,37 @@ def test_to_pandas(self):
             self.assertEquals(types[2], np.bool)
             self.assertEquals(types[3], np.float32)
     
    +    @unittest.skipIf(not _have_pandas, "Pandas not installed")
    +    def test_to_pandas_timezone_aware(self):
    +        import pandas as pd
    +        from dateutil import tz
    +        tzlocal = tz.tzlocal()
    +        ts = datetime.datetime(1970, 1, 1)
    +        pdf = pd.DataFrame.from_records([[ts]], columns=['ts'])
    +
    +        self.spark.conf.set('spark.sql.session.timeZone', 'America/Los_Angeles')
    +
    +        schema = StructType().add("ts", TimestampType())
    +        df = self.spark.createDataFrame([(ts,)], schema)
    +
    +        pdf_naive = df.toPandas()
    +        self.assertEqual(pdf_naive['ts'][0].tzinfo, None)
    +        self.assertTrue(pdf_naive.equals(pdf))
    +
    +        self.spark.conf.set('spark.sql.execution.pandas.timeZoneAware', 'true')
    +
    +        pdf_pst = df.toPandas()
    +        self.assertEqual(pdf_pst['ts'][0].tzinfo.zone, 'America/Los_Angeles')
    +        self.assertFalse(pdf_pst.equals(pdf))
    +
    +        pdf_pst_naive = pdf_pst.copy()
    +        pdf_pst_naive['ts'] = pdf_pst_naive['ts'].apply(
    +            lambda ts: ts.tz_convert(tzlocal).tz_localize(None))
    +        self.assertTrue(pdf_pst_naive.equals(pdf))
    +
    +        self.spark.conf.unset('spark.sql.execution.pandas.timeZoneAware')
    +        self.spark.conf.unset('spark.sql.session.timeZone')
    --- End diff --
    
    (Not a big deal but we could use `finally` just in case this test fails and other tests do not get affected by this test failure in the future)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org