Repository navigation
[Dataset] Enable read_tfrecords to accept features with missing values - #31922
Conversation
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
|
Thanks for the speedy PR to address the issue! |
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
|
@c21 @scottjlee Can we prioritize getting this over the line btw? This is blocking @daikeshi |
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
clarkzinzow
left a comment
There was a problem hiding this comment.
LGTM overall, only a few nits
| if not pa.types.is_list(c.type) or not pa.types.is_null( | ||
| c.type.value_type | ||
| ): | ||
| continue | ||
| elif pa.types.is_null(c.type.value_type): | ||
| if pa.types.is_list(scalar_type): | ||
| # If we are dealing with a list input, | ||
| # cast the array to the scalar_type found above. | ||
| col_chunked_arrays[c_idx] = c.cast(scalar_type) | ||
| else: | ||
| # If we are dealing with a single value, construct | ||
| # a new array with null values filled. | ||
| col_chunked_arrays[c_idx] = pa.chunked_array( | ||
| [pa.nulls(c.length(), type=scalar_type)] | ||
| ) |
There was a problem hiding this comment.
Nit: Instead of an if A: continue, elif B: blah, could have an if not A and B: blah. And since we happen to have that not A = True ==> B = True (since pa.types.is_null(c.type.value_type) is necessary for not A), this simplifies to just not A, or pa.types.is_list(c.type) and pa.types.is_null(c.type.value_type).
| if not pa.types.is_list(c.type) or not pa.types.is_null( | |
| c.type.value_type | |
| ): | |
| continue | |
| elif pa.types.is_null(c.type.value_type): | |
| if pa.types.is_list(scalar_type): | |
| # If we are dealing with a list input, | |
| # cast the array to the scalar_type found above. | |
| col_chunked_arrays[c_idx] = c.cast(scalar_type) | |
| else: | |
| # If we are dealing with a single value, construct | |
| # a new array with null values filled. | |
| col_chunked_arrays[c_idx] = pa.chunked_array( | |
| [pa.nulls(c.length(), type=scalar_type)] | |
| ) | |
| if pa.types.is_list(c.type) and pa.types.is_null( | |
| c.type.value_type | |
| ): | |
| if pa.types.is_list(scalar_type): | |
| # If we are dealing with a list input, | |
| # cast the array to the scalar_type found above. | |
| col_chunked_arrays[c_idx] = c.cast(scalar_type) | |
| else: | |
| # If we are dealing with a single value, construct | |
| # a new array with null values filled. | |
| col_chunked_arrays[c_idx] = pa.chunked_array( | |
| [pa.nulls(c.length(), type=scalar_type)] | |
| ) |
| else: | ||
| # If the feature value is empty, set the type to null for now | ||
| # to allow pyarrow to construct a valid Array; later, infer the | ||
| # type from other records which have non-empty values for the feature. |
|
|
||
| # Read the TFRecords. | ||
| readback_ds = ray.data.read_tfrecords(tmp_path) | ||
| readback_ds = ray.data.read_tfrecords(tmp_path, parallelism=1) |
There was a problem hiding this comment.
Nit: Could we actually remove this parallelism specification, along with the above parallelism specification for from_items(), and change the below assert to:
# Repartition each dataset into single block so column types are unified.
assert ds.repartition(1).take() == readback_ds.repartition(1).take()That way we can ensure that multi-block roundtrips work (provided that it does actually work, lmk if it doesn't), and the single-block thing is only part of checking that the roundtrip is equal.
Signed-off-by: Scott Lee <[email protected]>
Signed-off-by: Scott Lee <[email protected]>
…ues (ray-project#31922) Currently, ray.data.read_tfrecords does not allow a feature with missing values when reading a TFRecords Dataset. This PR bridges the gap and handles tf.train.Features with missing values. Signed-off-by: Scott Lee <[email protected]> Signed-off-by: Edward Oakes <[email protected]>
…ues (ray-project#31922) Currently, ray.data.read_tfrecords does not allow a feature with missing values when reading a TFRecords Dataset. This PR bridges the gap and handles tf.train.Features with missing values. Signed-off-by: Scott Lee <[email protected]>
…ues (ray-project#31922) Currently, ray.data.read_tfrecords does not allow a feature with missing values when reading a TFRecords Dataset. This PR bridges the gap and handles tf.train.Features with missing values. Signed-off-by: Scott Lee <[email protected]> Signed-off-by: elliottower <[email protected]>
Signed-off-by: Scott Lee [email protected]
Why are these changes needed?
Currently,
ray.data.read_tfrecordsdoes not allow a feature with missing values when reading aTFRecordsDataset. This PR bridges the gap and handlestf.train.Features with missing values.Related issue number
Closes #31831
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.