Skip to content

Instantly share code, notes, and snippets.

@dpoulopoulos
Last active February 22, 2020 18:27
Show Gist options
  • Select an option

  • Save dpoulopoulos/cd5f39c749ce60705d7f60aa950bcaf7 to your computer and use it in GitHub Desktop.

Select an option

Save dpoulopoulos/cd5f39c749ce60705d7f60aa950bcaf7 to your computer and use it in GitHub Desktop.
Find prime, odd and even numbers in the dataset.
import numpy as np
from metaflow import FlowSpec, step
class CheckNumbers(FlowSpec):
@step
def start(self):
"""
Initializes a random dataset.
"""
np.random.seed(0)
self.data = np.random.randint(1, 1000000, size=10000)
self.next(self.prime, self.odd, self.even)
@step
def prime(self):
"""
Calculates the prime numbers in the dataset.
"""
self.primes = [num for num in self.data if check_prime(num)]
self.next(self.join)
@step
def odd(self):
"""
Calculates the odd numbers in the dataset.
"""
self.odds = [num for num in self.data if check_odd(num)]
self.next(self.join)
@step
def even(self):
"""
Calculates the even numbers in the dataset.
"""
self.evens = [num for num in self.data if check_even(num)]
self.next(self.join)
@step
def join(self, inputs):
"""
Joins the branch.
"""
self.primes = inputs.prime.primes
self.odds = inputs.odd.odds
self.evens = inputs.even.evens
self.next(self.end)
@step
def end(self):
"""
Prints the results and terminates the run.
"""
print(f'Primes: {self.primes}')
print(f'Odds: {self.odds}')
print(f'Evens: {self.evens}')
if __name__ == '__main__':
CheckNumbers()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment