Skip to content

Commit 5bf829a

Browse files
authored
ARROW-71 Add test for writing from a Parquet file (#73)
1 parent fa7982e commit 5bf829a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

bindings/python/test/test_arrow.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import os
1415
import unittest
1516
import unittest.mock as mock
1617
from test import client_context
@@ -20,6 +21,7 @@
2021
from pyarrow import Table, bool_, decimal128, float64, int32, int64
2122
from pyarrow import schema as ArrowSchema
2223
from pyarrow import string, timestamp
24+
from pyarrow.parquet import read_table, write_table
2325
from pymongo import DESCENDING, WriteConcern
2426
from pymongo.collection import Collection
2527
from pymongoarrow.api import Schema, aggregate_arrow_all, find_arrow_all, write
@@ -247,6 +249,29 @@ def test_write_batching(self, mock):
247249
self.round_trip(data, Schema(schema), coll=self.coll)
248250
self.assertEqual(mock.call_count, 2)
249251

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+
250275

251276
class TestArrowExplicitApi(TestArrowApiMixin, unittest.TestCase):
252277
def run_find(self, *args, **kwargs):

0 commit comments

Comments
 (0)