[eager]: Fix bug in converting pandas objects to Tensors.
Specifically, fix a segmentation fault when converting objects that implement the Python sequence protocol (i.e., __getitem__, __len__, and __iter__) but which do not have contiguous keys. Fixes #20347 However, there are still some discrepancies possible between tf.convert_to_tensor(o) (or tf.constant(o)) with and without eager execution enabled. Fixing those is left as a follow up excercise. Sample differences: (1) Empty sequences that have numpy conversions defined. import pandas as pd import tensorflow as tf s = pd.Series([]) # Empty series t = tf.constant(s) With eager execution enabled, t.dtype ends up with a dtype of float32 (as py_seq_tensor.cc considers empty lists to be float32) With graph construction, t.dtype ends up with a dtype of float64 (as make_tensor_proto() converts 's' to a numpy array and uses its dtype). (2) Objects that implement __getitem__, __len__, and __iter__, but are not convertible to numpy arrays (e.g., do not implement __array__): - With eager execution enabled, these can be converted to a tensor - For graph construction, the conversion fails. PiperOrigin-RevId: 203019624
Loading
Please sign in to comment