Skip to content

Commit 8cb7d9e

Browse files
committed
Merge remote-tracking branch 'upstream/master' into disown-tz-only-rebased
2 parents 4bf00d8 + aeff38d commit 8cb7d9e

File tree

8 files changed

+56
-22
lines changed

8 files changed

+56
-22
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ env:
2323

2424
git:
2525
# for cloning
26-
depth: 1500
26+
depth: 2000
2727

2828
matrix:
2929
fast_finish: true

pandas/core/arrays/datetimes.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,8 @@ def sequence_to_dt64ns(data, dtype=None, copy=False,
16321632

16331633
inferred_freq = None
16341634

1635+
dtype = _validate_dt64_dtype(dtype)
1636+
16351637
if not hasattr(data, "dtype"):
16361638
# e.g. list, tuple
16371639
if np.ndim(data) == 0:
@@ -1836,7 +1838,7 @@ def maybe_convert_dtype(data, copy):
18361838
data = data.view(_NS_DTYPE)
18371839

18381840
elif is_period_dtype(data):
1839-
# Note: without explicitly raising here, PeriondIndex
1841+
# Note: without explicitly raising here, PeriodIndex
18401842
# test_setops.test_join_does_not_recur fails
18411843
raise TypeError("Passing PeriodDtype data is invalid. "
18421844
"Use `data.to_timestamp()` instead")
@@ -1889,6 +1891,38 @@ def maybe_infer_tz(tz, inferred_tz):
18891891
return tz
18901892

18911893

1894+
def _validate_dt64_dtype(dtype):
1895+
"""
1896+
Check that a dtype, if passed, represents either a numpy datetime64[ns]
1897+
dtype or a pandas DatetimeTZDtype.
1898+
1899+
Parameters
1900+
----------
1901+
dtype : object
1902+
1903+
Returns
1904+
-------
1905+
dtype : None, numpy.dtype, or DatetimeTZDtype
1906+
1907+
Raises
1908+
------
1909+
ValueError : invalid dtype
1910+
1911+
Notes
1912+
-----
1913+
Unlike validate_tz_from_dtype, this does _not_ allow non-existent
1914+
tz errors to go through
1915+
"""
1916+
if dtype is not None:
1917+
dtype = pandas_dtype(dtype)
1918+
if ((isinstance(dtype, np.dtype) and dtype != _NS_DTYPE)
1919+
or not isinstance(dtype, (np.dtype, DatetimeTZDtype))):
1920+
raise ValueError("Unexpected value for 'dtype': '{dtype}'. "
1921+
"Must be 'datetime64[ns]' or DatetimeTZDtype'."
1922+
.format(dtype=dtype))
1923+
return dtype
1924+
1925+
18921926
def validate_tz_from_dtype(dtype, tz):
18931927
"""
18941928
If the given dtype is a DatetimeTZDtype, extract the implied

pandas/core/reshape/tile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,10 @@ def _coerce_to_type(x):
390390
dtype = x.dtype
391391
elif is_datetime64_dtype(x):
392392
x = to_datetime(x)
393-
dtype = np.datetime64
393+
dtype = np.dtype('datetime64[ns]')
394394
elif is_timedelta64_dtype(x):
395395
x = to_timedelta(x)
396-
dtype = np.timedelta64
396+
dtype = np.dtype('timedelta64[ns]')
397397

398398
if dtype is not None:
399399
# GH 19768: force NaT to NaN during integer conversion

pandas/core/series.py

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame):
130130
dtype : str, numpy.dtype, or ExtensionDtype, optional
131131
dtype for the output Series. If not specified, this will be
132132
inferred from `data`.
133+
See the :ref:`user guide <basics.dtypes>` for more usages.
133134
copy : bool, default False
134135
Copy input data.
135136
"""

pandas/tests/arrays/test_datetimelike.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class SharedTests(object):
6464
def test_compare_len1_raises(self):
6565
# make sure we raise when comparing with different lengths, specific
6666
# to the case where one has length-1, which numpy would broadcast
67-
data = np.arange(10, dtype='i8')
67+
data = np.arange(10, dtype='i8') * 24 * 3600 * 10**9
6868

6969
idx = self.index_cls._simple_new(data, freq='D')
7070
arr = self.array_cls(idx)
@@ -77,7 +77,7 @@ def test_compare_len1_raises(self):
7777
idx <= idx[[0]]
7878

7979
def test_take(self):
80-
data = np.arange(100, dtype='i8')
80+
data = np.arange(100, dtype='i8') * 24 * 3600 * 10**9
8181
np.random.shuffle(data)
8282

8383
idx = self.index_cls._simple_new(data, freq='D')
@@ -96,7 +96,7 @@ def test_take(self):
9696
tm.assert_index_equal(self.index_cls(result), expected)
9797

9898
def test_take_fill(self):
99-
data = np.arange(10, dtype='i8')
99+
data = np.arange(10, dtype='i8') * 24 * 3600 * 10**9
100100

101101
idx = self.index_cls._simple_new(data, freq='D')
102102
arr = self.array_cls(idx)
@@ -121,7 +121,7 @@ def test_take_fill(self):
121121
fill_value=pd.Timestamp.now().time)
122122

123123
def test_concat_same_type(self):
124-
data = np.arange(10, dtype='i8')
124+
data = np.arange(10, dtype='i8') * 24 * 3600 * 10**9
125125

126126
idx = self.index_cls._simple_new(data, freq='D').insert(0, pd.NaT)
127127
arr = self.array_cls(idx)

pandas/tests/arrays/test_datetimes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
class TestDatetimeArrayConstructor(object):
1919
def test_mismatched_timezone_raises(self):
20-
a = DatetimeArray(np.array(['2000-01-01T06:00:00'], dtype='M8[ns]'),
21-
dtype=DatetimeTZDtype(tz='US/Central'))
20+
arr = DatetimeArray(np.array(['2000-01-01T06:00:00'], dtype='M8[ns]'),
21+
dtype=DatetimeTZDtype(tz='US/Central'))
2222
dtype = DatetimeTZDtype(tz='US/Eastern')
23-
with pytest.raises(TypeError, match='do not match'):
24-
DatetimeArray(a, dtype=dtype)
23+
with pytest.raises(TypeError, match='data is already tz-aware'):
24+
DatetimeArray(arr, dtype=dtype)
2525

2626
def test_non_array_raises(self):
2727
with pytest.raises(ValueError, match='list'):

pandas/tests/arrays/test_timedeltas.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ def test_other_type_raises(self):
1919
TimedeltaArray(np.array([1, 2, 3], dtype='bool'))
2020

2121
def test_incorrect_dtype_raises(self):
22-
with pytest.raises(TypeError, match="dtype category"):
22+
# TODO: why TypeError for 'category' but ValueError for i8?
23+
with pytest.raises(TypeError,
24+
match='data type "category" not understood'):
2325
TimedeltaArray(np.array([1, 2, 3], dtype='i8'), dtype='category')
2426

25-
with pytest.raises(TypeError, match="dtype int"):
27+
with pytest.raises(ValueError,
28+
match=r"Only timedelta64\[ns\] dtype is valid"):
2629
TimedeltaArray(np.array([1, 2, 3], dtype='i8'),
2730
dtype=np.dtype(int))
2831

29-
def test_freq_infer_raises(self):
30-
with pytest.raises(ValueError, match='Frequency inference'):
31-
TimedeltaArray(np.array([1, 2, 3], dtype='i8'), freq="infer")
32-
3332
def test_copy(self):
3433
data = np.array([1, 2, 3], dtype='m8[ns]')
3534
arr = TimedeltaArray(data, copy=False)

pandas/tests/dtypes/test_common.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ def test_is_datetime64_any_dtype():
340340
assert com.is_datetime64_any_dtype(np.datetime64)
341341
assert com.is_datetime64_any_dtype(np.array([], dtype=np.datetime64))
342342
assert com.is_datetime64_any_dtype(DatetimeTZDtype("ns", "US/Eastern"))
343-
assert com.is_datetime64_any_dtype(pd.DatetimeIndex([1, 2, 3],
344-
dtype=np.datetime64))
343+
assert com.is_datetime64_any_dtype(
344+
pd.DatetimeIndex([1, 2, 3], dtype="datetime64[ns]"))
345345

346346

347347
def test_is_datetime64_ns_dtype():
@@ -356,8 +356,8 @@ def test_is_datetime64_ns_dtype():
356356
assert not com.is_datetime64_ns_dtype(np.array([], dtype="datetime64[ps]"))
357357

358358
assert com.is_datetime64_ns_dtype(DatetimeTZDtype("ns", "US/Eastern"))
359-
assert com.is_datetime64_ns_dtype(pd.DatetimeIndex([1, 2, 3],
360-
dtype=np.datetime64))
359+
assert com.is_datetime64_ns_dtype(
360+
pd.DatetimeIndex([1, 2, 3], dtype=np.dtype('datetime64[ns]')))
361361

362362

363363
def test_is_timedelta64_ns_dtype():

0 commit comments

Comments
 (0)