Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/3010#discussion_r19687708
--- Diff: python/pyspark/rdd.py ---
@@ -317,8 +317,23 @@ def sample(self, withReplacement, fraction, seed=None):
Return a sampled subset of this RDD (relies on numpy and falls back
on default random generator if numpy is unavailable).
- >>> sc.parallelize(range(0, 100)).sample(False, 0.1, 2).collect()
#doctest: +SKIP
- [2, 3, 20, 21, 24, 41, 42, 66, 67, 89, 90, 98]
+ >>> rdd = sc.parallelize(range(0, 100), 4)
+ >>> wo = rdd.sample(False, 0.1, 2).collect()
+ >>> wo_dup = rdd.sample(False, 0.1, 2).collect()
+ >>> set(wo) == set(wo_dup)
+ True
+ >>> wr = rdd.sample(True, 0.2, 5).collect()
+ >>> wr_dup = rdd.sample(True, 0.2, 5).collect()
+ >>> set(wr) == set(wr_dup)
+ True
+ >>> wo_s10 = rdd.sample(False, 0.3, 10).collect()
+ >>> wo_s20 = rdd.sample(False, 0.3, 20).collect()
+ >>> set(wo_s10) != set(wo_s20)
+ True
+ >>> wr_s11 = rdd.sample(True, 0.4, 11).collect()
+ >>> wr_s21 = rdd.sample(True, 0.4, 21).collect()
+ >>> set(wr_s11) != set(wr_s21)
+ True
--- End diff --
These tests should be moved into tests.py, then the docstring will be much
clearer.
---
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]