Commit 92f13f24 authored by Asim Shankar's avatar Asim Shankar Committed by TensorFlower Gardener
Browse files

[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
parent 7ab8ccb2
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment