|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
| 14 | +import os |
14 | 15 | import unittest
|
15 | 16 | import unittest.mock as mock
|
16 | 17 | from test import client_context
|
|
20 | 21 | from pyarrow import Table, bool_, decimal128, float64, int32, int64
|
21 | 22 | from pyarrow import schema as ArrowSchema
|
22 | 23 | from pyarrow import string, timestamp
|
| 24 | +from pyarrow.parquet import read_table, write_table |
23 | 25 | from pymongo import DESCENDING, WriteConcern
|
24 | 26 | from pymongo.collection import Collection
|
25 | 27 | from pymongoarrow.api import Schema, aggregate_arrow_all, find_arrow_all, write
|
@@ -247,6 +249,29 @@ def test_write_batching(self, mock):
|
247 | 249 | self.round_trip(data, Schema(schema), coll=self.coll)
|
248 | 250 | self.assertEqual(mock.call_count, 2)
|
249 | 251 |
|
| 252 | + def test_parquet(self): |
| 253 | + schema = { |
| 254 | + "data": int64(), |
| 255 | + "float": float64(), |
| 256 | + "datetime": timestamp("ms"), |
| 257 | + "string": string(), |
| 258 | + "bool": bool_(), |
| 259 | + } |
| 260 | + data = Table.from_pydict( |
| 261 | + { |
| 262 | + "data": [i for i in range(2)], |
| 263 | + "float": [i for i in range(2)], |
| 264 | + "datetime": [i for i in range(2)], |
| 265 | + "string": [str(i) for i in range(2)], |
| 266 | + "bool": [True for _ in range(2)], |
| 267 | + }, |
| 268 | + ArrowSchema(schema), |
| 269 | + ) |
| 270 | + write_table(data, "test.parquet") |
| 271 | + data = read_table("test.parquet") |
| 272 | + self.round_trip(data, Schema(schema)) |
| 273 | + os.remove("test.parquet") |
| 274 | + |
250 | 275 |
|
251 | 276 | class TestArrowExplicitApi(TestArrowApiMixin, unittest.TestCase):
|
252 | 277 | def run_find(self, *args, **kwargs):
|
|
0 commit comments