Github user BryanCutler commented on a diff in the pull request: https://github.com/apache/spark/pull/18933#discussion_r133254340 --- 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)) --- End diff -- This is not really a test that `df.toPandas()` is time zone naive. If that was true then you should be able to do ``` df = self.spark.createDataFrame([(ts,)], schema) os.environ["TZ"] = "America/New_York" time.tzset() pdf_naive = df.toPandas() self.assertTrue(pdf_naive.equals(pdf)) ``` but this will fail because `toPandas()` does a conversion to local time, which is what the original data happens to be
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org