Skip to content

Commit e666f5c

Browse files
TST: Verify whether read-only datetime64 array can be factorized (35650) (#35775)
* TST: Verify whether read-only datetime64 array can be factorized (35650) * CLN: Make test more inline with similar factorize tests
1 parent b7a31eb commit e666f5c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/tests/test_algos.py

+13
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,19 @@ def test_object_factorize(self, writable):
252252
tm.assert_numpy_array_equal(codes, expected_codes)
253253
tm.assert_numpy_array_equal(uniques, expected_uniques)
254254

255+
def test_datetime64_factorize(self, writable):
256+
# GH35650 Verify whether read-only datetime64 array can be factorized
257+
data = np.array([np.datetime64("2020-01-01T00:00:00.000")])
258+
data.setflags(write=writable)
259+
expected_codes = np.array([0], dtype=np.int64)
260+
expected_uniques = np.array(
261+
["2020-01-01T00:00:00.000000000"], dtype="datetime64[ns]"
262+
)
263+
264+
codes, uniques = pd.factorize(data)
265+
tm.assert_numpy_array_equal(codes, expected_codes)
266+
tm.assert_numpy_array_equal(uniques, expected_uniques)
267+
255268
def test_deprecate_order(self):
256269
# gh 19727 - check warning is raised for deprecated keyword, order.
257270
# Test not valid once order keyword is removed.

0 commit comments

Comments
 (0)