aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jianwei Xie <xiejw@google.com>2017-03-03 09:10:25 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-03-03 09:31:31 -0800
commit936e5937220f18591a04c3baa91ad0f5aaacb171 (patch)
tree58fc43e9417ecfac7c38f1cb610ae72ddde9314a
parent2299ffe31d89a7b62d97681f812bddc9b790bf57 (diff)
Does pandas import check in each caller file directly to avoid flaky tests.
Change: 149118694
-rw-r--r--tensorflow/contrib/learn/python/learn/learn_io/pandas_io.py9
-rw-r--r--tensorflow/python/estimator/BUILD17
-rw-r--r--tensorflow/python/estimator/inputs/__init__.py1
-rw-r--r--tensorflow/python/estimator/inputs/pandas_import.py32
-rw-r--r--tensorflow/python/estimator/inputs/pandas_io.py12
-rw-r--r--tensorflow/python/estimator/inputs/pandas_io_test.py9
-rw-r--r--tensorflow/python/estimator/inputs/queues/feeding_functions.py9
-rw-r--r--tensorflow/python/estimator/inputs/queues/feeding_functions_test.py9
-rw-r--r--tensorflow/python/estimator/inputs/queues/feeding_queue_runner_test.py9
9 files changed, 48 insertions, 59 deletions
diff --git a/tensorflow/contrib/learn/python/learn/learn_io/pandas_io.py b/tensorflow/contrib/learn/python/learn/learn_io/pandas_io.py
index d516754fca..e7fb830568 100644
--- a/tensorflow/contrib/learn/python/learn/learn_io/pandas_io.py
+++ b/tensorflow/contrib/learn/python/learn/learn_io/pandas_io.py
@@ -19,12 +19,17 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
-from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
from tensorflow.python.estimator.inputs.pandas_io import pandas_input_fn # pylint: disable=unused-import
-if HAS_PANDAS:
+try:
# pylint: disable=g-import-not-at-top
import pandas as pd
+ HAS_PANDAS = True
+except IOError:
+ # Pandas writes a temporary file during import. If it fails, don't use pandas.
+ HAS_PANDAS = False
+except ImportError:
+ HAS_PANDAS = False
PANDAS_DTYPES = {
'int8': 'int',
diff --git a/tensorflow/python/estimator/BUILD b/tensorflow/python/estimator/BUILD
index c5a339d6d0..61651c0a2f 100644
--- a/tensorflow/python/estimator/BUILD
+++ b/tensorflow/python/estimator/BUILD
@@ -163,7 +163,6 @@ py_library(
srcs_version = "PY2AND3",
deps = [
":numpy_io",
- ":pandas_import",
":pandas_io",
],
)
@@ -191,19 +190,10 @@ py_test(
)
py_library(
- name = "pandas_import",
- srcs = ["inputs/pandas_import.py"],
- srcs_version = "PY2AND3",
-)
-
-py_library(
name = "pandas_io",
srcs = ["inputs/pandas_io.py"],
srcs_version = "PY2AND3",
- deps = [
- ":inputs_queues",
- ":pandas_import",
- ],
+ deps = [":inputs_queues"],
)
py_test(
@@ -228,10 +218,7 @@ py_library(
"inputs/queues/feeding_queue_runner.py",
],
srcs_version = "PY2AND3",
- deps = [
- ":pandas_import",
- "//tensorflow/python:training",
- ],
+ deps = ["//tensorflow/python:training"],
)
py_test(
diff --git a/tensorflow/python/estimator/inputs/__init__.py b/tensorflow/python/estimator/inputs/__init__.py
index c7bfbf562d..2e5987fe4f 100644
--- a/tensorflow/python/estimator/inputs/__init__.py
+++ b/tensorflow/python/estimator/inputs/__init__.py
@@ -19,5 +19,4 @@ from __future__ import division
from __future__ import print_function
from tensorflow.python.estimator.inputs.numpy_io import numpy_input_fn
-from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
from tensorflow.python.estimator.inputs.pandas_io import pandas_input_fn
diff --git a/tensorflow/python/estimator/inputs/pandas_import.py b/tensorflow/python/estimator/inputs/pandas_import.py
deleted file mode 100644
index 6f78a16847..0000000000
--- a/tensorflow/python/estimator/inputs/pandas_import.py
+++ /dev/null
@@ -1,32 +0,0 @@
-# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# ==============================================================================
-"""Handles pandas import for tensorflow."""
-
-from __future__ import absolute_import
-from __future__ import division
-from __future__ import print_function
-
-import numpy as _ # pylint: disable=unused-import
-
-try:
- # pylint: disable=g-import-not-at-top
- # pylint: disable=unused-import
- import pandas as _
- HAS_PANDAS = True
-except IOError:
- # Pandas writes a temporary file during import. If it fails, don't use pandas.
- HAS_PANDAS = False
-except ImportError:
- HAS_PANDAS = False
diff --git a/tensorflow/python/estimator/inputs/pandas_io.py b/tensorflow/python/estimator/inputs/pandas_io.py
index 914845ba6a..a1e418f487 100644
--- a/tensorflow/python/estimator/inputs/pandas_io.py
+++ b/tensorflow/python/estimator/inputs/pandas_io.py
@@ -20,9 +20,19 @@ from __future__ import division
from __future__ import print_function
import numpy as np
-from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
from tensorflow.python.estimator.inputs.queues import feeding_functions
+try:
+ # pylint: disable=g-import-not-at-top
+ # pylint: disable=unused-import
+ import pandas as pd
+ HAS_PANDAS = True
+except IOError:
+ # Pandas writes a temporary file during import. If it fails, don't use pandas.
+ HAS_PANDAS = False
+except ImportError:
+ HAS_PANDAS = False
+
def pandas_input_fn(x,
y=None,
diff --git a/tensorflow/python/estimator/inputs/pandas_io_test.py b/tensorflow/python/estimator/inputs/pandas_io_test.py
index 2e1fee4dd8..e6934d3ff9 100644
--- a/tensorflow/python/estimator/inputs/pandas_io_test.py
+++ b/tensorflow/python/estimator/inputs/pandas_io_test.py
@@ -21,15 +21,20 @@ from __future__ import print_function
import numpy as np
from tensorflow.python.estimator.inputs import pandas_io
-from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
from tensorflow.python.framework import errors
from tensorflow.python.platform import test
from tensorflow.python.training import coordinator
from tensorflow.python.training import queue_runner_impl
-if HAS_PANDAS:
+try:
# pylint: disable=g-import-not-at-top
import pandas as pd
+ HAS_PANDAS = True
+except IOError:
+ # Pandas writes a temporary file during import. If it fails, don't use pandas.
+ HAS_PANDAS = False
+except ImportError:
+ HAS_PANDAS = False
class PandasIoTest(test.TestCase):
diff --git a/tensorflow/python/estimator/inputs/queues/feeding_functions.py b/tensorflow/python/estimator/inputs/queues/feeding_functions.py
index aa39958559..9da2bce0f8 100644
--- a/tensorflow/python/estimator/inputs/queues/feeding_functions.py
+++ b/tensorflow/python/estimator/inputs/queues/feeding_functions.py
@@ -22,7 +22,6 @@ import collections
import random
import numpy as np
-from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
from tensorflow.python.estimator.inputs.queues import feeding_queue_runner as fqr
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import errors
@@ -34,9 +33,15 @@ from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.summary import summary
from tensorflow.python.training import queue_runner
-if HAS_PANDAS:
+try:
# pylint: disable=g-import-not-at-top
import pandas as pd
+ HAS_PANDAS = True
+except IOError:
+ # Pandas writes a temporary file during import. If it fails, don't use pandas.
+ HAS_PANDAS = False
+except ImportError:
+ HAS_PANDAS = False
def _get_integer_indices_for_next_batch(
diff --git a/tensorflow/python/estimator/inputs/queues/feeding_functions_test.py b/tensorflow/python/estimator/inputs/queues/feeding_functions_test.py
index ad27d990ea..0e602d3f33 100644
--- a/tensorflow/python/estimator/inputs/queues/feeding_functions_test.py
+++ b/tensorflow/python/estimator/inputs/queues/feeding_functions_test.py
@@ -22,13 +22,18 @@ import collections
import numpy as np
-from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
from tensorflow.python.estimator.inputs.queues import feeding_functions as ff
from tensorflow.python.platform import test
-if HAS_PANDAS:
+try:
# pylint: disable=g-import-not-at-top
import pandas as pd
+ HAS_PANDAS = True
+except IOError:
+ # Pandas writes a temporary file during import. If it fails, don't use pandas.
+ HAS_PANDAS = False
+except ImportError:
+ HAS_PANDAS = False
def vals_to_list(a):
diff --git a/tensorflow/python/estimator/inputs/queues/feeding_queue_runner_test.py b/tensorflow/python/estimator/inputs/queues/feeding_queue_runner_test.py
index c8d20970c5..6292eb7da1 100644
--- a/tensorflow/python/estimator/inputs/queues/feeding_queue_runner_test.py
+++ b/tensorflow/python/estimator/inputs/queues/feeding_queue_runner_test.py
@@ -21,16 +21,21 @@ from __future__ import print_function
import numpy as np
from tensorflow.python.client import session
-from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
from tensorflow.python.estimator.inputs.queues import feeding_functions as ff
from tensorflow.python.framework import ops
from tensorflow.python.platform import test
from tensorflow.python.training import coordinator
from tensorflow.python.training import queue_runner_impl
-if HAS_PANDAS:
+try:
# pylint: disable=g-import-not-at-top
import pandas as pd
+ HAS_PANDAS = True
+except IOError:
+ # Pandas writes a temporary file during import. If it fails, don't use pandas.
+ HAS_PANDAS = False
+except ImportError:
+ HAS_PANDAS = False
def get_rows(array, row_indices):