applied-ai-018 commited on
Commit
a605e33
·
verified ·
1 Parent(s): ac141ed

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. ckpts/universal/global_step80/zero/18.post_attention_layernorm.weight/exp_avg.pt +3 -0
  2. ckpts/universal/global_step80/zero/18.post_attention_layernorm.weight/exp_avg_sq.pt +3 -0
  3. ckpts/universal/global_step80/zero/18.post_attention_layernorm.weight/fp32.pt +3 -0
  4. ckpts/universal/global_step80/zero/20.attention.dense.weight/fp32.pt +3 -0
  5. ckpts/universal/global_step80/zero/6.attention.dense.weight/exp_avg.pt +3 -0
  6. ckpts/universal/global_step80/zero/6.attention.dense.weight/exp_avg_sq.pt +3 -0
  7. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/__init__.cpython-310.pyc +0 -0
  8. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/arrow_16597.cpython-310.pyc +0 -0
  9. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/arrow_7980.cpython-310.pyc +0 -0
  10. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/conftest.cpython-310.pyc +0 -0
  11. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/read_record_batch.cpython-310.pyc +0 -0
  12. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/strategies.cpython-310.pyc +0 -0
  13. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_array.cpython-310.pyc +0 -0
  14. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_builder.cpython-310.pyc +0 -0
  15. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_cffi.cpython-310.pyc +0 -0
  16. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_compute.cpython-310.pyc +0 -0
  17. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_convert_builtin.cpython-310.pyc +0 -0
  18. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_cpp_internals.cpython-310.pyc +0 -0
  19. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_csv.cpython-310.pyc +0 -0
  20. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_cuda.cpython-310.pyc +0 -0
  21. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_cuda_numba_interop.cpython-310.pyc +0 -0
  22. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_cython.cpython-310.pyc +0 -0
  23. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_dataset_encryption.cpython-310.pyc +0 -0
  24. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_deprecations.cpython-310.pyc +0 -0
  25. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_dlpack.cpython-310.pyc +0 -0
  26. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_exec_plan.cpython-310.pyc +0 -0
  27. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_feather.cpython-310.pyc +0 -0
  28. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_flight.cpython-310.pyc +0 -0
  29. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_flight_async.cpython-310.pyc +0 -0
  30. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_fs.cpython-310.pyc +0 -0
  31. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_gdb.cpython-310.pyc +0 -0
  32. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_io.cpython-310.pyc +0 -0
  33. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_json.cpython-310.pyc +0 -0
  34. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_jvm.cpython-310.pyc +0 -0
  35. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_orc.cpython-310.pyc +0 -0
  36. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_pandas.cpython-310.pyc +0 -0
  37. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_scalars.cpython-310.pyc +0 -0
  38. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_schema.cpython-310.pyc +0 -0
  39. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_sparse_tensor.cpython-310.pyc +0 -0
  40. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_strategies.cpython-310.pyc +0 -0
  41. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_table.cpython-310.pyc +0 -0
  42. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_tensor.cpython-310.pyc +0 -0
  43. venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/util.cpython-310.pyc +0 -0
  44. venv/lib/python3.10/site-packages/pyarrow/tests/arrow_16597.py +37 -0
  45. venv/lib/python3.10/site-packages/pyarrow/tests/extensions.pyx +94 -0
  46. venv/lib/python3.10/site-packages/pyarrow/tests/interchange/__init__.py +16 -0
  47. venv/lib/python3.10/site-packages/pyarrow/tests/interchange/__pycache__/__init__.cpython-310.pyc +0 -0
  48. venv/lib/python3.10/site-packages/pyarrow/tests/interchange/__pycache__/test_conversion.cpython-310.pyc +0 -0
  49. venv/lib/python3.10/site-packages/pyarrow/tests/interchange/__pycache__/test_interchange_spec.cpython-310.pyc +0 -0
  50. venv/lib/python3.10/site-packages/pyarrow/tests/interchange/test_conversion.py +522 -0
ckpts/universal/global_step80/zero/18.post_attention_layernorm.weight/exp_avg.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c99b99e95b4eda92972e2d1f814119638626449727f7558a0f0784095bc4f03
3
+ size 9372
ckpts/universal/global_step80/zero/18.post_attention_layernorm.weight/exp_avg_sq.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b5e34ddd21b7057a3785a9e4b41e58d874bd149e1d98d587531231ffc41d805f
3
+ size 9387
ckpts/universal/global_step80/zero/18.post_attention_layernorm.weight/fp32.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aa008e995910851fce825278e7ad203a0818533f25ba9938a7b9a66fbd358054
3
+ size 9293
ckpts/universal/global_step80/zero/20.attention.dense.weight/fp32.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99bf85eabd6772edbdb169db47bfd5d4eab143f391fdfe23e5a4126b036e8744
3
+ size 16778317
ckpts/universal/global_step80/zero/6.attention.dense.weight/exp_avg.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:539b96245692d18abe9088ed75acb446f6830cb1e42ee1e2a0208730ad772fc1
3
+ size 16778396
ckpts/universal/global_step80/zero/6.attention.dense.weight/exp_avg_sq.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b74761c1740ecc657f461ec8645e8349502722c918fae51a0d8639be7691b591
3
+ size 16778411
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (181 Bytes). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/arrow_16597.cpython-310.pyc ADDED
Binary file (904 Bytes). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/arrow_7980.cpython-310.pyc ADDED
Binary file (371 Bytes). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/conftest.cpython-310.pyc ADDED
Binary file (8.16 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/read_record_batch.cpython-310.pyc ADDED
Binary file (365 Bytes). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/strategies.cpython-310.pyc ADDED
Binary file (9.38 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_array.cpython-310.pyc ADDED
Binary file (98.4 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_builder.cpython-310.pyc ADDED
Binary file (2.06 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_cffi.cpython-310.pyc ADDED
Binary file (17.3 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_compute.cpython-310.pyc ADDED
Binary file (101 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_convert_builtin.cpython-310.pyc ADDED
Binary file (71.4 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_cpp_internals.cpython-310.pyc ADDED
Binary file (1.12 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_csv.cpython-310.pyc ADDED
Binary file (52.2 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_cuda.cpython-310.pyc ADDED
Binary file (18.7 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_cuda_numba_interop.cpython-310.pyc ADDED
Binary file (6.07 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_cython.cpython-310.pyc ADDED
Binary file (5.09 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_dataset_encryption.cpython-310.pyc ADDED
Binary file (5.65 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_deprecations.cpython-310.pyc ADDED
Binary file (231 Bytes). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_dlpack.cpython-310.pyc ADDED
Binary file (3.71 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_exec_plan.cpython-310.pyc ADDED
Binary file (7.09 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_feather.cpython-310.pyc ADDED
Binary file (22 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_flight.cpython-310.pyc ADDED
Binary file (81.9 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_flight_async.cpython-310.pyc ADDED
Binary file (2.72 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_fs.cpython-310.pyc ADDED
Binary file (49.4 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_gdb.cpython-310.pyc ADDED
Binary file (33.3 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_io.cpython-310.pyc ADDED
Binary file (56.9 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_json.cpython-310.pyc ADDED
Binary file (10.7 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_jvm.cpython-310.pyc ADDED
Binary file (9.09 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_orc.cpython-310.pyc ADDED
Binary file (12.2 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_pandas.cpython-310.pyc ADDED
Binary file (146 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_scalars.cpython-310.pyc ADDED
Binary file (23.6 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_schema.cpython-310.pyc ADDED
Binary file (18.3 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_sparse_tensor.cpython-310.pyc ADDED
Binary file (11 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_strategies.cpython-310.pyc ADDED
Binary file (1.67 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_table.cpython-310.pyc ADDED
Binary file (77 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_tensor.cpython-310.pyc ADDED
Binary file (5.76 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/__pycache__/util.cpython-310.pyc ADDED
Binary file (14.2 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/arrow_16597.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ # This file is called from a test in test_flight.py.
19
+ import time
20
+
21
+ import pyarrow as pa
22
+ import pyarrow.flight as flight
23
+
24
+
25
+ class Server(flight.FlightServerBase):
26
+ def do_put(self, context, descriptor, reader, writer):
27
+ time.sleep(1)
28
+ raise flight.FlightCancelledError("")
29
+
30
+
31
+ if __name__ == "__main__":
32
+ server = Server("grpc://localhost:0")
33
+ client = flight.connect(f"grpc://localhost:{server.port}")
34
+ schema = pa.schema([])
35
+ writer, reader = client.do_put(
36
+ flight.FlightDescriptor.for_command(b""), schema)
37
+ writer.done_writing()
venv/lib/python3.10/site-packages/pyarrow/tests/extensions.pyx ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ # distutils: language=c++
19
+ # cython: language_level = 3
20
+
21
+ from pyarrow.lib cimport *
22
+
23
+ cdef extern from * namespace "arrow::py" nogil:
24
+ """
25
+ #include "arrow/status.h"
26
+ #include "arrow/extension_type.h"
27
+ #include "arrow/ipc/json_simple.h"
28
+
29
+ namespace arrow {
30
+ namespace py {
31
+
32
+ class UuidArray : public ExtensionArray {
33
+ public:
34
+ using ExtensionArray::ExtensionArray;
35
+ };
36
+
37
+ class UuidType : public ExtensionType {
38
+ public:
39
+ UuidType() : ExtensionType(fixed_size_binary(16)) {}
40
+ std::string extension_name() const override { return "uuid"; }
41
+
42
+ bool ExtensionEquals(const ExtensionType& other) const override {
43
+ return other.extension_name() == this->extension_name();
44
+ }
45
+
46
+ std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const override {
47
+ return std::make_shared<ExtensionArray>(data);
48
+ }
49
+
50
+ Result<std::shared_ptr<DataType>> Deserialize(
51
+ std::shared_ptr<DataType> storage_type,
52
+ const std::string& serialized) const override {
53
+ return std::make_shared<UuidType>();
54
+ }
55
+
56
+ std::string Serialize() const override { return ""; }
57
+ };
58
+
59
+
60
+ std::shared_ptr<DataType> MakeUuidType() {
61
+ return std::make_shared<UuidType>();
62
+ }
63
+
64
+ std::shared_ptr<Array> MakeUuidArray() {
65
+ auto uuid_type = MakeUuidType();
66
+ auto json = "[\\"abcdefghijklmno0\\", \\"0onmlkjihgfedcba\\"]";
67
+ auto result = ipc::internal::json::ArrayFromJSON(fixed_size_binary(16), json);
68
+ return ExtensionType::WrapArray(uuid_type, result.ValueOrDie());
69
+ }
70
+
71
+ std::once_flag uuid_registered;
72
+
73
+ static bool RegisterUuidType() {
74
+ std::call_once(uuid_registered, RegisterExtensionType,
75
+ std::make_shared<UuidType>());
76
+ return true;
77
+ }
78
+
79
+ static auto uuid_type_registered = RegisterUuidType();
80
+
81
+ } // namespace py
82
+ } // namespace arrow
83
+ """
84
+
85
+ cdef shared_ptr[CDataType] CMakeUuidType" arrow::py::MakeUuidType"()
86
+ cdef shared_ptr[CArray] CMakeUuidArray" arrow::py::MakeUuidArray"()
87
+
88
+
89
+ def _make_uuid_type():
90
+ return pyarrow_wrap_data_type(CMakeUuidType())
91
+
92
+
93
+ def _make_uuid_array():
94
+ return pyarrow_wrap_array(CMakeUuidArray())
venv/lib/python3.10/site-packages/pyarrow/tests/interchange/__init__.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
venv/lib/python3.10/site-packages/pyarrow/tests/interchange/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (193 Bytes). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/interchange/__pycache__/test_conversion.cpython-310.pyc ADDED
Binary file (13.2 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/interchange/__pycache__/test_interchange_spec.cpython-310.pyc ADDED
Binary file (7.38 kB). View file
 
venv/lib/python3.10/site-packages/pyarrow/tests/interchange/test_conversion.py ADDED
@@ -0,0 +1,522 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ from datetime import datetime as dt
19
+ import numpy as np
20
+ import pyarrow as pa
21
+ from pyarrow.vendored.version import Version
22
+ import pytest
23
+
24
+ import pyarrow.interchange as pi
25
+ from pyarrow.interchange.column import (
26
+ _PyArrowColumn,
27
+ ColumnNullType,
28
+ DtypeKind,
29
+ )
30
+ from pyarrow.interchange.from_dataframe import _from_dataframe
31
+
32
+ try:
33
+ import pandas as pd
34
+ # import pandas.testing as tm
35
+ except ImportError:
36
+ pass
37
+
38
+
39
+ @pytest.mark.parametrize("unit", ['s', 'ms', 'us', 'ns'])
40
+ @pytest.mark.parametrize("tz", ['', 'America/New_York', '+07:30', '-04:30'])
41
+ def test_datetime(unit, tz):
42
+ dt_arr = [dt(2007, 7, 13), dt(2007, 7, 14), None]
43
+ table = pa.table({"A": pa.array(dt_arr, type=pa.timestamp(unit, tz=tz))})
44
+ col = table.__dataframe__().get_column_by_name("A")
45
+
46
+ assert col.size() == 3
47
+ assert col.offset == 0
48
+ assert col.null_count == 1
49
+ assert col.dtype[0] == DtypeKind.DATETIME
50
+ assert col.describe_null == (ColumnNullType.USE_BITMASK, 0)
51
+
52
+
53
+ @pytest.mark.parametrize(
54
+ ["test_data", "kind"],
55
+ [
56
+ (["foo", "bar"], 21),
57
+ ([1.5, 2.5, 3.5], 2),
58
+ ([1, 2, 3, 4], 0),
59
+ ],
60
+ )
61
+ def test_array_to_pyarrowcolumn(test_data, kind):
62
+ arr = pa.array(test_data)
63
+ arr_column = _PyArrowColumn(arr)
64
+
65
+ assert arr_column._col == arr
66
+ assert arr_column.size() == len(test_data)
67
+ assert arr_column.dtype[0] == kind
68
+ assert arr_column.num_chunks() == 1
69
+ assert arr_column.null_count == 0
70
+ assert arr_column.get_buffers()["validity"] is None
71
+ assert len(list(arr_column.get_chunks())) == 1
72
+
73
+ for chunk in arr_column.get_chunks():
74
+ assert chunk == arr_column
75
+
76
+
77
+ def test_offset_of_sliced_array():
78
+ arr = pa.array([1, 2, 3, 4])
79
+ arr_sliced = arr.slice(2, 2)
80
+
81
+ table = pa.table([arr], names=["arr"])
82
+ table_sliced = pa.table([arr_sliced], names=["arr_sliced"])
83
+
84
+ col = table_sliced.__dataframe__().get_column(0)
85
+ assert col.offset == 2
86
+
87
+ result = _from_dataframe(table_sliced.__dataframe__())
88
+ assert table_sliced.equals(result)
89
+ assert not table.equals(result)
90
+
91
+ # pandas hardcodes offset to 0:
92
+ # https://github.com/pandas-dev/pandas/blob/5c66e65d7b9fef47ccb585ce2fd0b3ea18dc82ea/pandas/core/interchange/from_dataframe.py#L247
93
+ # so conversion to pandas can't be tested currently
94
+
95
+ # df = pandas_from_dataframe(table)
96
+ # df_sliced = pandas_from_dataframe(table_sliced)
97
+
98
+ # tm.assert_series_equal(df["arr"][2:4], df_sliced["arr_sliced"],
99
+ # check_index=False, check_names=False)
100
+
101
+
102
+ @pytest.mark.pandas
103
+ @pytest.mark.parametrize(
104
+ "uint", [pa.uint8(), pa.uint16(), pa.uint32()]
105
+ )
106
+ @pytest.mark.parametrize(
107
+ "int", [pa.int8(), pa.int16(), pa.int32(), pa.int64()]
108
+ )
109
+ @pytest.mark.parametrize(
110
+ "float, np_float", [
111
+ # (pa.float16(), np.float16), #not supported by pandas
112
+ (pa.float32(), np.float32),
113
+ (pa.float64(), np.float64)
114
+ ]
115
+ )
116
+ def test_pandas_roundtrip(uint, int, float, np_float):
117
+ if Version(pd.__version__) < Version("1.5.0"):
118
+ pytest.skip("__dataframe__ added to pandas in 1.5.0")
119
+
120
+ arr = [1, 2, 3]
121
+ table = pa.table(
122
+ {
123
+ "a": pa.array(arr, type=uint),
124
+ "b": pa.array(arr, type=int),
125
+ "c": pa.array(np.array(arr, dtype=np_float), type=float),
126
+ "d": [True, False, True],
127
+ }
128
+ )
129
+ from pandas.api.interchange import (
130
+ from_dataframe as pandas_from_dataframe
131
+ )
132
+ pandas_df = pandas_from_dataframe(table)
133
+ result = pi.from_dataframe(pandas_df)
134
+ assert table.equals(result)
135
+
136
+ table_protocol = table.__dataframe__()
137
+ result_protocol = result.__dataframe__()
138
+
139
+ assert table_protocol.num_columns() == result_protocol.num_columns()
140
+ assert table_protocol.num_rows() == result_protocol.num_rows()
141
+ assert table_protocol.num_chunks() == result_protocol.num_chunks()
142
+ assert table_protocol.column_names() == result_protocol.column_names()
143
+
144
+
145
+ @pytest.mark.pandas
146
+ def test_pandas_roundtrip_string():
147
+ # See https://github.com/pandas-dev/pandas/issues/50554
148
+ if Version(pd.__version__) < Version("1.6"):
149
+ pytest.skip("Column.size() bug in pandas")
150
+
151
+ arr = ["a", "", "c"]
152
+ table = pa.table({"a": pa.array(arr)})
153
+
154
+ from pandas.api.interchange import (
155
+ from_dataframe as pandas_from_dataframe
156
+ )
157
+
158
+ pandas_df = pandas_from_dataframe(table)
159
+ result = pi.from_dataframe(pandas_df)
160
+
161
+ assert result["a"].to_pylist() == table["a"].to_pylist()
162
+ assert pa.types.is_string(table["a"].type)
163
+ assert pa.types.is_large_string(result["a"].type)
164
+
165
+ table_protocol = table.__dataframe__()
166
+ result_protocol = result.__dataframe__()
167
+
168
+ assert table_protocol.num_columns() == result_protocol.num_columns()
169
+ assert table_protocol.num_rows() == result_protocol.num_rows()
170
+ assert table_protocol.num_chunks() == result_protocol.num_chunks()
171
+ assert table_protocol.column_names() == result_protocol.column_names()
172
+
173
+
174
+ @pytest.mark.pandas
175
+ def test_pandas_roundtrip_large_string():
176
+ # See https://github.com/pandas-dev/pandas/issues/50554
177
+ if Version(pd.__version__) < Version("1.6"):
178
+ pytest.skip("Column.size() bug in pandas")
179
+
180
+ arr = ["a", "", "c"]
181
+ table = pa.table({"a_large": pa.array(arr, type=pa.large_string())})
182
+
183
+ from pandas.api.interchange import (
184
+ from_dataframe as pandas_from_dataframe
185
+ )
186
+
187
+ if Version(pd.__version__) >= Version("2.0.1"):
188
+ pandas_df = pandas_from_dataframe(table)
189
+ result = pi.from_dataframe(pandas_df)
190
+
191
+ assert result["a_large"].to_pylist() == table["a_large"].to_pylist()
192
+ assert pa.types.is_large_string(table["a_large"].type)
193
+ assert pa.types.is_large_string(result["a_large"].type)
194
+
195
+ table_protocol = table.__dataframe__()
196
+ result_protocol = result.__dataframe__()
197
+
198
+ assert table_protocol.num_columns() == result_protocol.num_columns()
199
+ assert table_protocol.num_rows() == result_protocol.num_rows()
200
+ assert table_protocol.num_chunks() == result_protocol.num_chunks()
201
+ assert table_protocol.column_names() == result_protocol.column_names()
202
+
203
+ else:
204
+ # large string not supported by pandas implementation for
205
+ # older versions of pandas
206
+ # https://github.com/pandas-dev/pandas/issues/52795
207
+ with pytest.raises(AssertionError):
208
+ pandas_from_dataframe(table)
209
+
210
+
211
+ @pytest.mark.pandas
212
+ def test_pandas_roundtrip_string_with_missing():
213
+ # See https://github.com/pandas-dev/pandas/issues/50554
214
+ if Version(pd.__version__) < Version("1.6"):
215
+ pytest.skip("Column.size() bug in pandas")
216
+
217
+ arr = ["a", "", "c", None]
218
+ table = pa.table({"a": pa.array(arr),
219
+ "a_large": pa.array(arr, type=pa.large_string())})
220
+
221
+ from pandas.api.interchange import (
222
+ from_dataframe as pandas_from_dataframe
223
+ )
224
+
225
+ if Version(pd.__version__) >= Version("2.0.2"):
226
+ pandas_df = pandas_from_dataframe(table)
227
+ result = pi.from_dataframe(pandas_df)
228
+
229
+ assert result["a"].to_pylist() == table["a"].to_pylist()
230
+ assert pa.types.is_string(table["a"].type)
231
+ assert pa.types.is_large_string(result["a"].type)
232
+
233
+ assert result["a_large"].to_pylist() == table["a_large"].to_pylist()
234
+ assert pa.types.is_large_string(table["a_large"].type)
235
+ assert pa.types.is_large_string(result["a_large"].type)
236
+ else:
237
+ # older versions of pandas do not have bitmask support
238
+ # https://github.com/pandas-dev/pandas/issues/49888
239
+ with pytest.raises(NotImplementedError):
240
+ pandas_from_dataframe(table)
241
+
242
+
243
+ @pytest.mark.pandas
244
+ def test_pandas_roundtrip_categorical():
245
+ if Version(pd.__version__) < Version("2.0.2"):
246
+ pytest.skip("Bitmasks not supported in pandas interchange implementation")
247
+
248
+ arr = ["Mon", "Tue", "Mon", "Wed", "Mon", "Thu", "Fri", "Sat", None]
249
+ table = pa.table(
250
+ {"weekday": pa.array(arr).dictionary_encode()}
251
+ )
252
+
253
+ from pandas.api.interchange import (
254
+ from_dataframe as pandas_from_dataframe
255
+ )
256
+ pandas_df = pandas_from_dataframe(table)
257
+ result = pi.from_dataframe(pandas_df)
258
+
259
+ assert result["weekday"].to_pylist() == table["weekday"].to_pylist()
260
+ assert pa.types.is_dictionary(table["weekday"].type)
261
+ assert pa.types.is_dictionary(result["weekday"].type)
262
+ assert pa.types.is_string(table["weekday"].chunk(0).dictionary.type)
263
+ assert pa.types.is_large_string(result["weekday"].chunk(0).dictionary.type)
264
+ assert pa.types.is_int32(table["weekday"].chunk(0).indices.type)
265
+ assert pa.types.is_int8(result["weekday"].chunk(0).indices.type)
266
+
267
+ table_protocol = table.__dataframe__()
268
+ result_protocol = result.__dataframe__()
269
+
270
+ assert table_protocol.num_columns() == result_protocol.num_columns()
271
+ assert table_protocol.num_rows() == result_protocol.num_rows()
272
+ assert table_protocol.num_chunks() == result_protocol.num_chunks()
273
+ assert table_protocol.column_names() == result_protocol.column_names()
274
+
275
+ col_table = table_protocol.get_column(0)
276
+ col_result = result_protocol.get_column(0)
277
+
278
+ assert col_result.dtype[0] == DtypeKind.CATEGORICAL
279
+ assert col_result.dtype[0] == col_table.dtype[0]
280
+ assert col_result.size() == col_table.size()
281
+ assert col_result.offset == col_table.offset
282
+
283
+ desc_cat_table = col_result.describe_categorical
284
+ desc_cat_result = col_result.describe_categorical
285
+
286
+ assert desc_cat_table["is_ordered"] == desc_cat_result["is_ordered"]
287
+ assert desc_cat_table["is_dictionary"] == desc_cat_result["is_dictionary"]
288
+ assert isinstance(desc_cat_result["categories"]._col, pa.Array)
289
+
290
+
291
+ @pytest.mark.pandas
292
+ @pytest.mark.parametrize("unit", ['s', 'ms', 'us', 'ns'])
293
+ def test_pandas_roundtrip_datetime(unit):
294
+ if Version(pd.__version__) < Version("1.5.0"):
295
+ pytest.skip("__dataframe__ added to pandas in 1.5.0")
296
+ from datetime import datetime as dt
297
+
298
+ # timezones not included as they are not yet supported in
299
+ # the pandas implementation
300
+ dt_arr = [dt(2007, 7, 13), dt(2007, 7, 14), dt(2007, 7, 15)]
301
+ table = pa.table({"a": pa.array(dt_arr, type=pa.timestamp(unit))})
302
+
303
+ if Version(pd.__version__) < Version("1.6"):
304
+ # pandas < 2.0 always creates datetime64 in "ns"
305
+ # resolution
306
+ expected = pa.table({"a": pa.array(dt_arr, type=pa.timestamp('ns'))})
307
+ else:
308
+ expected = table
309
+
310
+ from pandas.api.interchange import (
311
+ from_dataframe as pandas_from_dataframe
312
+ )
313
+ pandas_df = pandas_from_dataframe(table)
314
+ result = pi.from_dataframe(pandas_df)
315
+
316
+ assert expected.equals(result)
317
+
318
+ expected_protocol = expected.__dataframe__()
319
+ result_protocol = result.__dataframe__()
320
+
321
+ assert expected_protocol.num_columns() == result_protocol.num_columns()
322
+ assert expected_protocol.num_rows() == result_protocol.num_rows()
323
+ assert expected_protocol.num_chunks() == result_protocol.num_chunks()
324
+ assert expected_protocol.column_names() == result_protocol.column_names()
325
+
326
+
327
+ @pytest.mark.pandas
328
+ @pytest.mark.parametrize(
329
+ "np_float", [np.float32, np.float64]
330
+ )
331
+ def test_pandas_to_pyarrow_with_missing(np_float):
332
+ if Version(pd.__version__) < Version("1.5.0"):
333
+ pytest.skip("__dataframe__ added to pandas in 1.5.0")
334
+
335
+ np_array = np.array([0, np.nan, 2], dtype=np_float)
336
+ datetime_array = [None, dt(2007, 7, 14), dt(2007, 7, 15)]
337
+ df = pd.DataFrame({
338
+ "a": np_array, # float, ColumnNullType.USE_NAN
339
+ "dt": datetime_array # ColumnNullType.USE_SENTINEL
340
+ })
341
+ expected = pa.table({
342
+ "a": pa.array(np_array, from_pandas=True),
343
+ "dt": pa.array(datetime_array, type=pa.timestamp("ns"))
344
+ })
345
+ result = pi.from_dataframe(df)
346
+
347
+ assert result.equals(expected)
348
+
349
+
350
+ @pytest.mark.pandas
351
+ def test_pandas_to_pyarrow_float16_with_missing():
352
+ if Version(pd.__version__) < Version("1.5.0"):
353
+ pytest.skip("__dataframe__ added to pandas in 1.5.0")
354
+
355
+ # np.float16 errors if ps.is_nan is used
356
+ # pyarrow.lib.ArrowNotImplementedError: Function 'is_nan' has no kernel
357
+ # matching input types (halffloat)
358
+ np_array = np.array([0, np.nan, 2], dtype=np.float16)
359
+ df = pd.DataFrame({"a": np_array})
360
+
361
+ with pytest.raises(NotImplementedError):
362
+ pi.from_dataframe(df)
363
+
364
+
365
+ @pytest.mark.parametrize(
366
+ "uint", [pa.uint8(), pa.uint16(), pa.uint32()]
367
+ )
368
+ @pytest.mark.parametrize(
369
+ "int", [pa.int8(), pa.int16(), pa.int32(), pa.int64()]
370
+ )
371
+ @pytest.mark.parametrize(
372
+ "float, np_float", [
373
+ (pa.float16(), np.float16),
374
+ (pa.float32(), np.float32),
375
+ (pa.float64(), np.float64)
376
+ ]
377
+ )
378
+ @pytest.mark.parametrize("unit", ['s', 'ms', 'us', 'ns'])
379
+ @pytest.mark.parametrize("tz", ['America/New_York', '+07:30', '-04:30'])
380
+ @pytest.mark.parametrize("offset, length", [(0, 3), (0, 2), (1, 2), (2, 1)])
381
+ def test_pyarrow_roundtrip(uint, int, float, np_float,
382
+ unit, tz, offset, length):
383
+
384
+ from datetime import datetime as dt
385
+ arr = [1, 2, None]
386
+ dt_arr = [dt(2007, 7, 13), None, dt(2007, 7, 15)]
387
+
388
+ table = pa.table(
389
+ {
390
+ "a": pa.array(arr, type=uint),
391
+ "b": pa.array(arr, type=int),
392
+ "c": pa.array(np.array(arr, dtype=np_float),
393
+ type=float, from_pandas=True),
394
+ "d": [True, False, True],
395
+ "e": [True, False, None],
396
+ "f": ["a", None, "c"],
397
+ "g": pa.array(dt_arr, type=pa.timestamp(unit, tz=tz))
398
+ }
399
+ )
400
+ table = table.slice(offset, length)
401
+ result = _from_dataframe(table.__dataframe__())
402
+
403
+ assert table.equals(result)
404
+
405
+ table_protocol = table.__dataframe__()
406
+ result_protocol = result.__dataframe__()
407
+
408
+ assert table_protocol.num_columns() == result_protocol.num_columns()
409
+ assert table_protocol.num_rows() == result_protocol.num_rows()
410
+ assert table_protocol.num_chunks() == result_protocol.num_chunks()
411
+ assert table_protocol.column_names() == result_protocol.column_names()
412
+
413
+
414
+ @pytest.mark.parametrize("offset, length", [(0, 10), (0, 2), (7, 3), (2, 1)])
415
+ def test_pyarrow_roundtrip_categorical(offset, length):
416
+ arr = ["Mon", "Tue", "Mon", "Wed", "Mon", "Thu", "Fri", None, "Sun"]
417
+ table = pa.table(
418
+ {"weekday": pa.array(arr).dictionary_encode()}
419
+ )
420
+ table = table.slice(offset, length)
421
+ result = _from_dataframe(table.__dataframe__())
422
+
423
+ assert table.equals(result)
424
+
425
+ table_protocol = table.__dataframe__()
426
+ result_protocol = result.__dataframe__()
427
+
428
+ assert table_protocol.num_columns() == result_protocol.num_columns()
429
+ assert table_protocol.num_rows() == result_protocol.num_rows()
430
+ assert table_protocol.num_chunks() == result_protocol.num_chunks()
431
+ assert table_protocol.column_names() == result_protocol.column_names()
432
+
433
+ col_table = table_protocol.get_column(0)
434
+ col_result = result_protocol.get_column(0)
435
+
436
+ assert col_result.dtype[0] == DtypeKind.CATEGORICAL
437
+ assert col_result.dtype[0] == col_table.dtype[0]
438
+ assert col_result.size() == col_table.size()
439
+ assert col_result.offset == col_table.offset
440
+
441
+ desc_cat_table = col_table.describe_categorical
442
+ desc_cat_result = col_result.describe_categorical
443
+
444
+ assert desc_cat_table["is_ordered"] == desc_cat_result["is_ordered"]
445
+ assert desc_cat_table["is_dictionary"] == desc_cat_result["is_dictionary"]
446
+ assert isinstance(desc_cat_result["categories"]._col, pa.Array)
447
+
448
+
449
+ @pytest.mark.large_memory
450
+ def test_pyarrow_roundtrip_large_string():
451
+
452
+ data = np.array([b'x'*1024]*(3*1024**2), dtype='object') # 3GB bytes data
453
+ arr = pa.array(data, type=pa.large_string())
454
+ table = pa.table([arr], names=["large_string"])
455
+
456
+ result = _from_dataframe(table.__dataframe__())
457
+ col = result.__dataframe__().get_column(0)
458
+
459
+ assert col.size() == 3*1024**2
460
+ assert pa.types.is_large_string(table[0].type)
461
+ assert pa.types.is_large_string(result[0].type)
462
+
463
+ assert table.equals(result)
464
+
465
+
466
+ def test_nan_as_null():
467
+ table = pa.table({"a": [1, 2, 3, 4]})
468
+ with pytest.raises(RuntimeError):
469
+ table.__dataframe__(nan_as_null=True)
470
+
471
+
472
+ @pytest.mark.pandas
473
+ def test_allow_copy_false():
474
+ if Version(pd.__version__) < Version("1.5.0"):
475
+ pytest.skip("__dataframe__ added to pandas in 1.5.0")
476
+
477
+ # Test that an error is raised when a copy is needed
478
+ # to create a bitmask
479
+
480
+ df = pd.DataFrame({"a": [0, 1.0, 2.0]})
481
+ with pytest.raises(RuntimeError):
482
+ pi.from_dataframe(df, allow_copy=False)
483
+
484
+ df = pd.DataFrame({
485
+ "dt": [None, dt(2007, 7, 14), dt(2007, 7, 15)]
486
+ })
487
+ with pytest.raises(RuntimeError):
488
+ pi.from_dataframe(df, allow_copy=False)
489
+
490
+
491
+ @pytest.mark.pandas
492
+ def test_allow_copy_false_bool_categorical():
493
+ if Version(pd.__version__) < Version("1.5.0"):
494
+ pytest.skip("__dataframe__ added to pandas in 1.5.0")
495
+
496
+ # Test that an error is raised for boolean
497
+ # and categorical dtype (copy is always made)
498
+
499
+ df = pd.DataFrame({"a": [None, False, True]})
500
+ with pytest.raises(RuntimeError):
501
+ pi.from_dataframe(df, allow_copy=False)
502
+
503
+ df = pd.DataFrame({"a": [True, False, True]})
504
+ with pytest.raises(RuntimeError):
505
+ pi.from_dataframe(df, allow_copy=False)
506
+
507
+ df = pd.DataFrame({"weekday": ["a", "b", None]})
508
+ df = df.astype("category")
509
+ with pytest.raises(RuntimeError):
510
+ pi.from_dataframe(df, allow_copy=False)
511
+
512
+ df = pd.DataFrame({"weekday": ["a", "b", "c"]})
513
+ df = df.astype("category")
514
+ with pytest.raises(RuntimeError):
515
+ pi.from_dataframe(df, allow_copy=False)
516
+
517
+
518
+ def test_empty_dataframe():
519
+ schema = pa.schema([('col1', pa.int8())])
520
+ df = pa.table([[]], schema=schema)
521
+ dfi = df.__dataframe__()
522
+ assert pi.from_dataframe(dfi) == df