Github user holdenk commented on a diff in the pull request:
https://github.com/apache/spark/pull/16793#discussion_r104452225
--- Diff: python/pyspark/sql/dataframe.py ---
@@ -1307,43 +1309,75 @@ def replace(self, to_replace, value, subset=None):
|null| null|null|
+----+------+----+
"""
- if not isinstance(to_replace, (float, int, long, basestring, list,
tuple, dict)):
+ # Helper functions
+ def all_of(types):
+ """Given a type or tuple of types
+ and sequence of xs check if each x
+ is instance of type(s)
+
+ >>> all_of(bool)([True, False])
+ True
+ >>> all_of(basestring)(["a", 1])
+ False
+ """
+ def all_of_(xs):
+ return all(isinstance(x, types) for x in xs)
+ return all_of_
+
+ all_of_bool = all_of(bool)
+ all_of_str = all_of(basestring)
+ all_of_numeric = all_of((float, int, long))
+
+ # Validate input types
+ valid_types = (bool, float, int, long, basestring, list, tuple)
+ if not isinstance(to_replace, valid_types + (dict, )):
raise ValueError(
- "to_replace should be a float, int, long, string, list,
tuple, or dict")
+ "to_replace should be a float, int, long, string, list,
tuple, or dict. "
+ "Got {0}".format(type(to_replace)))
- if not isinstance(value, (float, int, long, basestring, list,
tuple)):
- raise ValueError("value should be a float, int, long, string,
list, or tuple")
+ if (not isinstance(value, valid_types) and
--- End diff --
This seems like a weird split.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]