paleolimbot commented on code in PR #502:
URL: https://github.com/apache/arrow-nanoarrow/pull/502#discussion_r1628174089


##########
python/tests/test_array.py:
##########
@@ -354,3 +355,87 @@ def test_array_inspect(capsys):
     array.inspect()
     captured = capsys.readouterr()
     assert captured.out.startswith("<ArrowArray struct<col0: int32")
+
+
+def test_timestamp_array(capsys):
+    schema = na.struct(
+        {
+            "creation_timestamp": na.timestamp("ms"),
+        }
+    )
+
+    d1 = int(round(datetime(1985, 12, 31, 0, 0, 
tzinfo=timezone.utc).timestamp() * 1e3))
+    d2 = int(round(datetime(2005, 3, 4, 0, 0, tzinfo=timezone.utc).timestamp() 
* 1e3))
+
+    columns = [
+        na.c_array([d1, d2], na.timestamp("ms")),
+    ]
+
+    c_array = na.c_array_from_buffers(
+        schema, length=columns[0].length, buffers=[None], children=columns
+    )
+    array = na.Array(c_array)
+    names, columns = array.to_columns_pysequence()
+    assert names == ["creation_timestamp"]
+    assert list(array.to_pysequence()) == [
+        {"creation_timestamp": datetime(1985, 12, 31, 0, 0)},
+        {"creation_timestamp": datetime(2005, 3, 4, 0, 0)},
+    ]
+    array.inspect()
+    captured = capsys.readouterr()
+    assert captured.out.startswith(
+        "<ArrowArray struct<creation_timestamp: timestamp('ms'"
+    )

Review Comment:
   Would `assert repr(array).startswith()` be simpler here?



##########
python/tests/test_array.py:
##########
@@ -354,3 +355,87 @@ def test_array_inspect(capsys):
     array.inspect()
     captured = capsys.readouterr()
     assert captured.out.startswith("<ArrowArray struct<col0: int32")
+
+
+def test_timestamp_array(capsys):
+    schema = na.struct(
+        {
+            "creation_timestamp": na.timestamp("ms"),
+        }
+    )
+
+    d1 = int(round(datetime(1985, 12, 31, 0, 0, 
tzinfo=timezone.utc).timestamp() * 1e3))
+    d2 = int(round(datetime(2005, 3, 4, 0, 0, tzinfo=timezone.utc).timestamp() 
* 1e3))
+
+    columns = [
+        na.c_array([d1, d2], na.timestamp("ms")),
+    ]
+
+    c_array = na.c_array_from_buffers(
+        schema, length=columns[0].length, buffers=[None], children=columns
+    )
+    array = na.Array(c_array)
+    names, columns = array.to_columns_pysequence()
+    assert names == ["creation_timestamp"]
+    assert list(array.to_pysequence()) == [
+        {"creation_timestamp": datetime(1985, 12, 31, 0, 0)},
+        {"creation_timestamp": datetime(2005, 3, 4, 0, 0)},
+    ]
+    array.inspect()
+    captured = capsys.readouterr()
+    assert captured.out.startswith(
+        "<ArrowArray struct<creation_timestamp: timestamp('ms'"
+    )
+
+
+def test_pyarrow_table_using_array():

Review Comment:
   I get that this test and the next one are testing the big picture, although 
they are slightly out of place here among lower-level tests that are mostly 
concerned with validating Array behaviour. We do need integration tests and 
don't have a good place for them at the moment...would it make sense to open a 
GitHub issue with these examples? I don't mind implementing the tests (there 
are more tests like this I'd like to put there, too 🙂 )



##########
python/tests/test_c_array.py:
##########
@@ -514,3 +516,37 @@ def test_c_array_from_buffers_validation():
             validation_level=validation_level,
         )
         assert c_array.length == 2
+
+
+def test_c_array_timestamp_seconds():
+    d1 = int(round(datetime(1970, 1, 1).timestamp()))
+    d2 = int(round(datetime(1985, 12, 31).timestamp()))
+    d3 = int(round(datetime(2005, 3, 4).timestamp()))
+
+    c_array = na.c_array([d1, d2, d3], na.timestamp("s"))
+    c_array_from_c_array = na.c_array(c_array)

Review Comment:
   I am not sure I understand why this line is needed? (Also in tests below). 
In this example, `c_array` should also have the properties that we are testing 
below?



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to