StorageLevels have .useDisk() and .useMemory() methods.  https://github.com/apache/incubator-spark/blob/master/core/src/main/scala/org/apache/spark/storage/StorageLevel.scala Maybe it makes sense to replace this with storageLevel.useDisk() && !storageLevel.useMemory()