jorisvandenbossche commented on a change in pull request #7169:
URL: https://github.com/apache/arrow/pull/7169#discussion_r431368560



##########
File path: python/pyarrow/tests/test_pandas.py
##########
@@ -3965,8 +3964,32 @@ def test_timestamp_as_object():
             np.datetime64('2050-05-03 15:42', 'ns'),
         ],
     })
+    # Not part of what we're testing, just ensuring that the inputs are what we
+    # expect.
+    assert (df.dateTimeMs.dtype, df.dateTimeNs.dtype) == (
+        # O == object, <M8[ns] == timestamp64[ns]
+        np.dtype("O"), np.dtype("<M8[ns]")
+    )
+    return df
+
+
[email protected]
+def test_timestamp_as_object_parquet(tempdir):
+    # Timestamps can be stored as Parquet and reloaded into Pandas with no loss
+    # of information if the timestamp_as_object option is True.
+    df = make_df_with_timestamps()
     table = pa.Table.from_pandas(df)
-    pq.write_table(table, 'timeseries.parquet', version="2.0")
-    result = pq.read_table('timeseries.parquet')
+    filename = tempdir / "timestamps_from_pandas.parquet"
+    pq.write_table(table, filename, version="2.0")
+    result = pq.read_table(filename)
     df2 = result.to_pandas(timestamp_as_object=True)
     tm.assert_frame_equal(df, df2, check_like=True)
+
+
+def test_timestamp_as_object():
+    # Timestamps can be converted Arrow and reloaded into Pandas with no loss
+    # of information if the timestamp_as_object option is True.
+    df = make_df_with_timestamps()
+    table = pa.Table.from_pandas(df)
+    df2 = table.to_pandas(timestamp_as_object=True)
+    tm.assert_frame_equal(df, df2, check_like=True)

Review comment:
       I would still like to see more explicit tests (eg from this test it is 
still not clear to me what is actually being returned is a datetime.datetime 
object or not)
   
   Eg something like
   
   ```
   import datetime
   dt = datetime.datetime(2012, 1, 1)
   arr = pa.array([dt], type=pa.timestamp('s'))
   result = arr.to_pandas(timestamp_as_object=True)
   assert result.dtype == object
   assert isinstance(result[0], datetime.datetime)
   assert result[0] == dt 
   ```
   
   And the above can be done for the different resolutions (except ns) to cover 
that as well.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to