Eliminated code duplication, refactored to pattern-matching style Partitioner and PythonPartitioner