title: How to replace make_one_shot_iterator () from google machine learning crash course
body: <p>I am following the Google Machine Learning Intensive Course. But it uses version 1.x of TensorFlow, so I was planning to change the exercises to be able to run them in TensorFlow 2.0. But I am stuck in that exercise:</p>
  
  <p><a href="https://colab.research.google.com/notebooks/mlcc/first_steps_with_tensor_flow.ipynb?utm_source=mlcc&amp;utm_campaign=colab-external&amp;utm_medium=referral&amp;utm_content=firststeps-colab&amp;hl=es#scrollTo=7UwqGbbxP53O" rel="nofollow noreferrer">https://colab.research.google.com/notebooks/mlcc/first_steps_with_tensor_flow.ipynb?utm_source=mlcc&amp;utm_campaign=colab-external&amp;utm_medium=referral&amp;utm_content=firststeps-colab&amp;hl=es#scrollTo=7UwqGbbxP53O</a></p>
  
  <p>Specifically the code:</p>
  
  <pre><code>    def my_input_fn(features, targets, batch_size=1, shuffle=True, num_epochs=None):
      """Trains a linear regression model of one feature.
  
      Args:
        features: pandas DataFrame of features
        targets: pandas DataFrame of targets
        batch_size: Size of batches to be passed to the model
        shuffle: True or False. Whether to shuffle the data.
        num_epochs: Number of epochs for which data should be repeated. None = repeat indefinitely
      Returns:
        Tuple of (features, labels) for next data batch
      """
  
      # Convert pandas data into a dict of np arrays.
      features = {key:np.array(value) for key,value in dict(features).items()}                                           
  
      # Construct a dataset, and configure batching/repeating.
      ds = Dataset.from_tensor_slices((features,targets)) # warning: 2GB limit
      ds = ds.batch(batch_size).repeat(num_epochs)
  
      # Shuffle the data, if specified.
      if shuffle:
        ds = ds.shuffle(buffer_size=10000)
  
      # Return the next batch of data.
      features, labels = ds.make_one_shot_iterator().get_next()
      return features, labels
  </code></pre>
  
  <p>I have replaced <code>features, labels = ds.make_one_shot_iterator().get_next()</code> with <code>features, labels = tf.compat.v1.data.make_one_shot_iterator(ds).get_next()</code></p>
  
  <p>and it seems to work but make_one_shot_iterator() is depreceated, so, how can i replace it?</p>
  
  <p>Also according to <a href="https://github.com/tensorflow/tensorflow/issues/29252" rel="nofollow noreferrer">https://github.com/tensorflow/tensorflow/issues/29252</a> , I have tried</p>
  
  <pre><code> features, labels = ds.__iter__()
      next(ds.__iter__())
      return features, labels
  </code></pre>
  
  <p>but it returns the error <code>__iter __ () is only supported inside of tf.function or when eager execution is enabled.</code></p>
  
  <p>I am quite inexperienced in python and follow the course as a hobbyist. Any ideas on how to solve it? Thank you.</p>