Skip to content

Commit b1436b8

Browse files
committed
Don't use is_datetime64tz_dtype for old pandas.
1 parent ee1a1c8 commit b1436b8

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

python/pyspark/sql/types.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,14 +1699,14 @@ def _check_dataframe_localize_timestamps(pdf, schema, timezone):
16991699
.dt.tz_convert(tz).dt.tz_localize(None)
17001700
except ImportError:
17011701
import pandas as pd
1702-
from pandas.core.common import is_datetime64tz_dtype, is_datetime64_dtype
1702+
from pandas.core.common import is_datetime64_dtype
17031703
from pandas.tslib import _dateutil_tzlocal
17041704
tzlocal = _dateutil_tzlocal()
17051705
tz = timezone or tzlocal
17061706
for column, series in pdf.iteritems():
17071707
if type(schema[str(column)].dataType) == TimestampType:
17081708
# TODO: handle nested timestamps, such as ArrayType(TimestampType())?
1709-
if is_datetime64tz_dtype(series.dtype):
1709+
if not is_datetime64_dtype(series.dtype):
17101710
# `series.dt.tz_convert(tzlocal).dt.tz_localize(None)` doesn't work properly.
17111711
pdf[column] = pd.Series([ts.tz_convert(tz).tz_localize(None)
17121712
if ts is not pd.NaT else pd.NaT for ts in series])
@@ -1726,19 +1726,23 @@ def _check_series_convert_timestamps_internal(s, timezone):
17261726
"""
17271727
try:
17281728
from pandas.api.types import is_datetime64tz_dtype, is_datetime64_dtype
1729-
tzlocal = 'tzlocal()'
1729+
# TODO: handle nested timestamps, such as ArrayType(TimestampType())?
1730+
if is_datetime64_dtype(s.dtype):
1731+
tz = timezone or 'tzlocal()'
1732+
return s.dt.tz_localize(tz).dt.tz_convert('UTC')
1733+
elif is_datetime64tz_dtype(s.dtype):
1734+
return s.dt.tz_convert('UTC')
1735+
else:
1736+
return s
17301737
except ImportError:
1731-
from pandas.core.common import is_datetime64tz_dtype, is_datetime64_dtype
1738+
from pandas.core.common import is_datetime64_dtype
17321739
from pandas.tslib import _dateutil_tzlocal
1733-
tzlocal = _dateutil_tzlocal()
1734-
# TODO: handle nested timestamps, such as ArrayType(TimestampType())?
1735-
if is_datetime64_dtype(s.dtype):
1736-
tz = timezone or tzlocal
1737-
return s.dt.tz_localize(tz).dt.tz_convert('UTC')
1738-
elif is_datetime64tz_dtype(s.dtype):
1739-
return s.dt.tz_convert('UTC')
1740-
else:
1741-
return s
1740+
# TODO: handle nested timestamps, such as ArrayType(TimestampType())?
1741+
if is_datetime64_dtype(s.dtype):
1742+
tz = timezone or _dateutil_tzlocal()
1743+
return s.dt.tz_localize(tz).dt.tz_convert('UTC')
1744+
else:
1745+
return s.dt.tz_convert('UTC')
17421746

17431747

17441748
def _test():

0 commit comments

Comments
 (0)