Skip to content

Commit 936e593

Browse files
Jianwei Xietensorflower-gardener
authored andcommitted
Does pandas import check in each caller file directly to avoid flaky tests.
Change: 149118694
1 parent 2299ffe commit 936e593

9 files changed

Lines changed: 48 additions & 59 deletions

File tree

tensorflow/contrib/learn/python/learn/learn_io/pandas_io.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@
1919
from __future__ import division
2020
from __future__ import print_function
2121

22-
from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
2322
from tensorflow.python.estimator.inputs.pandas_io import pandas_input_fn # pylint: disable=unused-import
2423

25-
if HAS_PANDAS:
24+
try:
2625
# pylint: disable=g-import-not-at-top
2726
import pandas as pd
27+
HAS_PANDAS = True
28+
except IOError:
29+
# Pandas writes a temporary file during import. If it fails, don't use pandas.
30+
HAS_PANDAS = False
31+
except ImportError:
32+
HAS_PANDAS = False
2833

2934
PANDAS_DTYPES = {
3035
'int8': 'int',

tensorflow/python/estimator/BUILD

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ py_library(
163163
srcs_version = "PY2AND3",
164164
deps = [
165165
":numpy_io",
166-
":pandas_import",
167166
":pandas_io",
168167
],
169168
)
@@ -190,20 +189,11 @@ py_test(
190189
],
191190
)
192191

193-
py_library(
194-
name = "pandas_import",
195-
srcs = ["inputs/pandas_import.py"],
196-
srcs_version = "PY2AND3",
197-
)
198-
199192
py_library(
200193
name = "pandas_io",
201194
srcs = ["inputs/pandas_io.py"],
202195
srcs_version = "PY2AND3",
203-
deps = [
204-
":inputs_queues",
205-
":pandas_import",
206-
],
196+
deps = [":inputs_queues"],
207197
)
208198

209199
py_test(
@@ -228,10 +218,7 @@ py_library(
228218
"inputs/queues/feeding_queue_runner.py",
229219
],
230220
srcs_version = "PY2AND3",
231-
deps = [
232-
":pandas_import",
233-
"//tensorflow/python:training",
234-
],
221+
deps = ["//tensorflow/python:training"],
235222
)
236223

237224
py_test(

tensorflow/python/estimator/inputs/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@
1919
from __future__ import print_function
2020

2121
from tensorflow.python.estimator.inputs.numpy_io import numpy_input_fn
22-
from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
2322
from tensorflow.python.estimator.inputs.pandas_io import pandas_input_fn

tensorflow/python/estimator/inputs/pandas_import.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

tensorflow/python/estimator/inputs/pandas_io.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,19 @@
2020
from __future__ import print_function
2121

2222
import numpy as np
23-
from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
2423
from tensorflow.python.estimator.inputs.queues import feeding_functions
2524

25+
try:
26+
# pylint: disable=g-import-not-at-top
27+
# pylint: disable=unused-import
28+
import pandas as pd
29+
HAS_PANDAS = True
30+
except IOError:
31+
# Pandas writes a temporary file during import. If it fails, don't use pandas.
32+
HAS_PANDAS = False
33+
except ImportError:
34+
HAS_PANDAS = False
35+
2636

2737
def pandas_input_fn(x,
2838
y=None,

tensorflow/python/estimator/inputs/pandas_io_test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@
2121
import numpy as np
2222

2323
from tensorflow.python.estimator.inputs import pandas_io
24-
from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
2524
from tensorflow.python.framework import errors
2625
from tensorflow.python.platform import test
2726
from tensorflow.python.training import coordinator
2827
from tensorflow.python.training import queue_runner_impl
2928

30-
if HAS_PANDAS:
29+
try:
3130
# pylint: disable=g-import-not-at-top
3231
import pandas as pd
32+
HAS_PANDAS = True
33+
except IOError:
34+
# Pandas writes a temporary file during import. If it fails, don't use pandas.
35+
HAS_PANDAS = False
36+
except ImportError:
37+
HAS_PANDAS = False
3338

3439

3540
class PandasIoTest(test.TestCase):

tensorflow/python/estimator/inputs/queues/feeding_functions.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import random
2323
import numpy as np
2424

25-
from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
2625
from tensorflow.python.estimator.inputs.queues import feeding_queue_runner as fqr
2726
from tensorflow.python.framework import dtypes
2827
from tensorflow.python.framework import errors
@@ -34,9 +33,15 @@
3433
from tensorflow.python.summary import summary
3534
from tensorflow.python.training import queue_runner
3635

37-
if HAS_PANDAS:
36+
try:
3837
# pylint: disable=g-import-not-at-top
3938
import pandas as pd
39+
HAS_PANDAS = True
40+
except IOError:
41+
# Pandas writes a temporary file during import. If it fails, don't use pandas.
42+
HAS_PANDAS = False
43+
except ImportError:
44+
HAS_PANDAS = False
4045

4146

4247
def _get_integer_indices_for_next_batch(

tensorflow/python/estimator/inputs/queues/feeding_functions_test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@
2222

2323
import numpy as np
2424

25-
from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
2625
from tensorflow.python.estimator.inputs.queues import feeding_functions as ff
2726
from tensorflow.python.platform import test
2827

29-
if HAS_PANDAS:
28+
try:
3029
# pylint: disable=g-import-not-at-top
3130
import pandas as pd
31+
HAS_PANDAS = True
32+
except IOError:
33+
# Pandas writes a temporary file during import. If it fails, don't use pandas.
34+
HAS_PANDAS = False
35+
except ImportError:
36+
HAS_PANDAS = False
3237

3338

3439
def vals_to_list(a):

tensorflow/python/estimator/inputs/queues/feeding_queue_runner_test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,21 @@
2121
import numpy as np
2222

2323
from tensorflow.python.client import session
24-
from tensorflow.python.estimator.inputs.pandas_import import HAS_PANDAS
2524
from tensorflow.python.estimator.inputs.queues import feeding_functions as ff
2625
from tensorflow.python.framework import ops
2726
from tensorflow.python.platform import test
2827
from tensorflow.python.training import coordinator
2928
from tensorflow.python.training import queue_runner_impl
3029

31-
if HAS_PANDAS:
30+
try:
3231
# pylint: disable=g-import-not-at-top
3332
import pandas as pd
33+
HAS_PANDAS = True
34+
except IOError:
35+
# Pandas writes a temporary file during import. If it fails, don't use pandas.
36+
HAS_PANDAS = False
37+
except ImportError:
38+
HAS_PANDAS = False
3439

3540

3641
def get_rows(array, row_indices):

0 commit comments

Comments
 (0)