Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ archs = "x86_64 arm64"
[tool.pytest.ini_options]
minversion = "7"
addopts = ["-ra", "--strict-config", "--strict-markers", "--durations=5", "--junitxml=xunit-results/TEST-results.xml"]
testpaths = ["test", "test/pandas_types"]
testpaths = ["test"]
log_cli_level = "INFO"
norecursedirs = ["test/*"]
faulthandler_timeout = 1500
xfail_strict = true
filterwarnings = [
Expand Down
23 changes: 17 additions & 6 deletions bindings/python/test/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def setUpClass(cls):
cls.coll = cls.client.pymongoarrow_test.get_collection(
"test", write_concern=WriteConcern(w="majority")
)
cls.addClassCleanup(cls.client.close)

def setUp(self):
self.coll.drop()
Expand Down Expand Up @@ -113,6 +114,14 @@ def test_find_simple(self):
self.assertEqual(find_cmd.command_name, "find")
self.assertEqual(find_cmd.command["projection"], {"_id": True, "data": True})

def test_find_repeat_type(self):
expected = Table.from_pydict(
{"_id": [1, 2, 3, 4], "data": [10, 20, 30, None]},
ArrowSchema([("_id", int32()), ("data", int32())]),
)
table = self.run_find({}, schema=Schema({"_id": int32(), "data": int32()}))
self.assertEqual(table, expected)

def test_find_with_projection(self):
expected = Table.from_pydict(
{"_id": [4, 3], "data": [None, 60]},
Expand Down Expand Up @@ -266,18 +275,19 @@ def test_pymongo_error(self):
},
ArrowSchema(schema),
)

client = MongoClient(
host="somedomainthatdoesntexist.org",
port=123456789,
serverSelectionTimeoutMS=10,
)
with self.assertRaises(ArrowWriteError) as exc:
write(
MongoClient(
host="somedomainthatdoesntexist.org",
port=123456789,
serverSelectionTimeoutMS=10,
).pymongoarrow_test.get_collection(
client.pymongoarrow_test.get_collection(
"test", write_concern=WriteConcern(w="majority")
),
data,
)
client.close()
self.assertEqual(
exc.exception.details.keys(),
{"nInserted", "writeConcernErrors", "writeErrors"},
Expand Down Expand Up @@ -840,6 +850,7 @@ def setUpClass(cls):
cls.client = client_context.get_client(
event_listeners=[cls.getmore_listener, cls.cmd_listener]
)
cls.addClassCleanup(cls.client.close)

def test_find_decimal128(self):
oids = list(ObjectId() for i in range(4))
Expand Down
3 changes: 3 additions & 0 deletions bindings/python/test/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def setUp(self):
for doc in self.coll.find({}, sort=[("_id", ASCENDING)]):
self.expected_times.append(doc["data"])

def tearDown(self):
self.client.close()

def test_context_creation_fails_with_unsupported_granularity(self):
unsupported_granularities = ["s", "us", "ns"]
for g in unsupported_granularities:
Expand Down
6 changes: 5 additions & 1 deletion bindings/python/test/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def setUpClass(cls):
)
cls.schema = {}

@classmethod
def tearDownClass(cls):
cls.client.close()

def assert_numpy_equal(self, actual, expected):
self.assertIsInstance(actual, dict)
for field in expected:
Expand Down Expand Up @@ -321,7 +325,7 @@ def table_from_dict(self, d, schema=None):
out = {}
for k, v in d.items():
if any(isinstance(x, int) for x in v) and None in v:
out[k] = np.array(v, dtype=np.float_)
out[k] = np.array(v, dtype=np.float64)
else:
out[k] = np.array(v, dtype=np.dtype(type(v[0]))) # Infer
return out
Expand Down
4 changes: 4 additions & 0 deletions bindings/python/test/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def setUpClass(cls):
event_listeners=[cls.getmore_listener, cls.cmd_listener]
)

@classmethod
def tearDownClass(cls):
cls.client.close()


class TestExplicitPandasApi(PandasTestBase):
@classmethod
Expand Down
10 changes: 5 additions & 5 deletions bindings/python/test/test_polars.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def setUpClass(cls):
event_listeners=[cls.getmore_listener, cls.cmd_listener],
uuidRepresentation="standard",
)
cls.addClassCleanup(cls.client.close)


class TestExplicitPolarsApi(PolarsTestBase):
Expand Down Expand Up @@ -182,11 +183,11 @@ def test_polars_types(self):
"Boolean": pl.Series([True, False, None]),
}

df_in = pl.DataFrame._from_dict(data=data, schema=pl_schema)
df_in = pl.from_dict(data=data, schema=pl_schema)
self.coll.drop()
write(self.coll, df_in)
df_out = find_polars_all(self.coll, {}, schema=Schema(pa_schema))
pl.testing.assert_frame_equal(df_in, df_out.drop("_id"))
pl.testing.assert_frame_equal(df_in, df_out)

def test_extension_types_fail(self):
"""Confirm failure on ExtensionTypes for Polars.DataFrame.from_arrow"""
Expand Down Expand Up @@ -264,10 +265,9 @@ def test_exceptions_for_unsupported_polar_types(self):
class MyObject:
pass

with self.assertRaises(pl.PolarsPanicError) as exc:
with self.assertRaises(pl.exceptions.PanicException) as exc:
df_in = pl.DataFrame(data=[MyObject()] * 2)
write(self.coll, df_in)
self.assertTrue("not implemented" in exc.exception.args[0])

def test_polars_binary_type(self):
"""Demonstrates that binary data is not yet supported. TODO [ARROW-214]
Expand Down Expand Up @@ -393,5 +393,5 @@ def test_bson_types(self):
try:
dfpl = pl.from_arrow(table.drop("_id"))
assert dfpl["value"].dtype == data_type["ptype"]
except pl.ComputeError:
except pl.exceptions.ComputeError:
assert isinstance(table["value"].type, pa.ExtensionType)
4 changes: 4 additions & 0 deletions bindings/python/test/test_pymongoarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def setUpClass(cls):
raise unittest.SkipTest("cannot connect to MongoDB")
cls.client = client_context.get_client()

@classmethod
def tearDownClass(cls):
cls.client.close()

def test_version(self):
self.assertIsNotNone(__version__)
self.assertIsInstance(__version__, str)
Expand Down
Loading