diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi index cc7779895758a..324c1406c6d97 100644 --- a/python/pyarrow/array.pxi +++ b/python/pyarrow/array.pxi @@ -15,6 +15,11 @@ # specific language governing permissions and limitations # under the License. +from pyarrow.compat import HAVE_PANDAS + +if HAVE_PANDAS: + import pyarrow.pandas_compat as pdcompat + cdef _sequence_to_array(object sequence, object mask, object size, DataType type, CMemoryPool* pool, c_bool from_pandas): @@ -165,9 +170,9 @@ def array(object obj, type=None, mask=None, size=None, bint from_pandas=False, from_pandas=True, safe=safe, memory_pool=memory_pool) else: - import pyarrow.pandas_compat as pdcompat - values, type = pdcompat.get_datetimetz_type(values, obj.dtype, - type) + if HAVE_PANDAS: + values, type = pdcompat.get_datetimetz_type( + values, obj.dtype, type) return _ndarray_to_array(values, mask, type, from_pandas, safe, pool) else: diff --git a/python/pyarrow/pandas_compat.py b/python/pyarrow/pandas_compat.py index 403f15dfc2cdb..86e826f783707 100644 --- a/python/pyarrow/pandas_compat.py +++ b/python/pyarrow/pandas_compat.py @@ -28,7 +28,7 @@ import six import pyarrow as pa -from pyarrow.compat import builtin_pickle, PY2, zip_longest # noqa +from pyarrow.compat import builtin_pickle, DatetimeTZDtype, PY2, zip_longest # noqa def infer_dtype(column): @@ -447,8 +447,6 @@ def convert_column(col, ty): def get_datetimetz_type(values, dtype, type_): - from pyarrow.compat import DatetimeTZDtype - if values.dtype.type != np.datetime64: return values, type_ @@ -543,7 +541,6 @@ def _reconstruct_block(item): def _make_datetimetz(tz): - from pyarrow.compat import DatetimeTZDtype tz = pa.lib.string_to_tzinfo(tz) return DatetimeTZDtype('ns', tz=tz) @@ -554,7 +551,6 @@ def _make_datetimetz(tz): def table_to_blockmanager(options, table, categories=None, ignore_metadata=False): - from pyarrow.compat import DatetimeTZDtype index_columns = [] columns = []