xinrong-databricks commented on a change in pull request #33095:
URL: https://github.com/apache/spark/pull/33095#discussion_r662446564
##########
File path: python/pyspark/pandas/tests/data_type_ops/test_boolean_ops.py
##########
@@ -572,10 +578,28 @@ def test_isnull(self):
def test_astype(self):
pser = self.pser
psser = self.psser
+
+ # [True, False, <NA>] is returned in pandas
self.assert_eq(["True", "False", "None"],
self.psser.astype(str).tolist())
+
self.assert_eq(pser.astype("category"), psser.astype("category"))
cat_type = CategoricalDtype(categories=[False, True])
self.assert_eq(pser.astype(cat_type), psser.astype(cat_type))
+ for dtype in self.extension_dtypes:
+ if extension_float_dtypes_available:
+ is_extension_float_dtype = dtype in [
+ "Float32",
+ "Float64",
+ Float32Dtype(),
+ Float64Dtype(),
+ ]
+
+ if is_extension_float_dtype:
+ self.assert_eq([1.0, 0.0, np.nan],
self.psser.astype(dtype).tolist())
+ else:
+ self.check_extension(pser.astype(dtype),
psser.astype(dtype))
+ else:
+ self.check_extension(pser.astype(dtype), psser.astype(dtype))
Review comment:
Better approach! Modified.
##########
File path: python/pyspark/pandas/tests/data_type_ops/test_boolean_ops.py
##########
@@ -572,10 +578,28 @@ def test_isnull(self):
def test_astype(self):
pser = self.pser
psser = self.psser
+
+ # [True, False, <NA>] is returned in pandas
self.assert_eq(["True", "False", "None"],
self.psser.astype(str).tolist())
+
self.assert_eq(pser.astype("category"), psser.astype("category"))
cat_type = CategoricalDtype(categories=[False, True])
self.assert_eq(pser.astype(cat_type), psser.astype(cat_type))
+ for dtype in self.extension_dtypes:
+ if extension_float_dtypes_available:
+ is_extension_float_dtype = dtype in [
+ "Float32",
+ "Float64",
+ Float32Dtype(),
+ Float64Dtype(),
+ ]
+
+ if is_extension_float_dtype:
+ self.assert_eq([1.0, 0.0, np.nan],
self.psser.astype(dtype).tolist())
Review comment:
Sure added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]