Repository navigation
Fix non-nullable ArrayType columns and forward exist_ok in dataframe_to_mds - #25
Merged
Merged
Conversation
PySpark ArrayType equality includes containsNull, so the SPARK_TO_MDS lookup missed array columns declared with containsNull=False (e.g. produced by concat/array over non-null columns) and raised 'is not supported by dataframe_to_mds'. Normalize the lookup to the element type only, mirroring the existing DecimalType handling. Adds regression tests covering schema inference and end-to-end conversion for non-nullable arrays.
avgvi
added a commit
that referenced
this pull request
Oct 10, 2026
Fix non-nullable ArrayType columns and forward exist_ok in dataframe_to_mds
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
dataframe_to_mdshad two problems with real-world Spark frames. First, array columns declared withcontainsNull=False(what Spark produces forarray(...)orconcat(...)of non-nullable columns) were rejected withArrayType(DoubleType(), False) is not supported by dataframe_to_mds, becauseArrayTypeequality and hashing includecontainsNull, so theSPARK_TO_MDSlookup keyed onArrayType(DoubleType())missed. Second,mds_kwargs['exist_ok']reached each partition'sMDSWriterbut not the initialCloudUploader.get(out, ...), so converting into an existing, non-empty output directory raisedFileExistsErroreven withexist_ok=True. This imports mosaicml/streaming#984 by @discobot and mosaicml/streaming#991 by @SiluPanda with the original commits kept so the authors stay credited, and addresses upstream issues mosaicml/streaming#870 and mosaicml/streaming#871.map_spark_dtypenormalises arrays toArrayType(elementType)before theSPARK_TO_MDSlookup, mirroring the existingDecimalTypenormalisation; the MDSndarray:*encodings do not depend on element nullability, and both call sites (user-defined column validation and schema inference) go through it.dataframe_to_mdsreadsexist_okfrommds_kwargs(defaultFalse, so existing behaviour is unchanged) and passes it toCloudUploader.get.non_nullable_array_dataframefixture withtest_non_nullable_array_type_mappingandtest_non_nullable_array_end_to_end_conversion_local[True/False], andtest_end_to_end_conversion_local_exist_ok, which converts into atmp_paththat already contains a file.Checked locally on Python 3.12:
SKIP=pyright pre-commit run --files streaming/base/converters/dataframe_to_mds.py tests/base/converters/test_dataframe_to_mds.pyis clean, the test module collects 25 tests, and thecontainsNulllookup miss reproduces with plainpyspark.sql.types(ArrayType(DoubleType(), containsNull=False) in SPARK_TO_MDSisFalsewhile the normalised key maps tondarray:float64); the 24 tests that start a Spark session could not run here because the only JDK present (Homebrew OpenJDK 26) is rejected by PySpark 3.5, so they rely on CI, which runs this file on Python 3.10 to 3.13.