Skip to content

Commit 8c7357f

Browse files
committed
Updates
1 parent 1910c7d commit 8c7357f

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed

pandas/core/arrays/datetimes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,7 @@ def sequence_to_dt64ns(data, dtype=None, copy=False,
17071707
data, inferred_tz = objects_to_datetime64ns(
17081708
data, dayfirst=dayfirst, yearfirst=yearfirst)
17091709
tz = maybe_infer_tz(tz, inferred_tz)
1710+
int_as_wall_time = False
17101711

17111712
# `data` may have originally been a Categorical[datetime64[ns, tz]],
17121713
# so we need to handle these types.

pandas/tests/indexes/datetimes/test_astype.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,19 @@ def _check_rng(rng):
240240
def test_integer_index_astype_datetime(self, tz, dtype):
241241
# GH 20997, 20964
242242
val = [pd.Timestamp('2018-01-01', tz=tz).value]
243-
result = pd.Index(val).astype(dtype)
244-
expected = pd.DatetimeIndex(['2018-01-01'], tz=tz)
243+
244+
if tz:
245+
ex_warn = FutureWarning
246+
else:
247+
ex_warn = None
248+
249+
with tm.assert_produces_warning(ex_warn, check_stacklevel=False):
250+
# XXX: This likely shouldn't warn.
251+
# This raised on 0.24.x, so we can probably do the right thing
252+
# now.
253+
result = pd.Index(val).astype(dtype)
254+
with tm.assert_produces_warning(ex_warn, check_stacklevel=False):
255+
expected = pd.DatetimeIndex(val, tz=tz)
245256
tm.assert_index_equal(result, expected)
246257

247258

pandas/tests/indexes/datetimes/test_construction.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,15 @@ def test_construction_with_alt_tz_localize(self, kwargs, tz_aware_fixture):
118118
tz = tz_aware_fixture
119119
i = pd.date_range('20130101', periods=5, freq='H', tz=tz)
120120
kwargs = {key: attrgetter(val)(i) for key, val in kwargs.items()}
121-
result = DatetimeIndex(i.tz_localize(None).asi8, **kwargs)
122-
expected = i.tz_localize(None).tz_localize('UTC').tz_convert(tz)
121+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
122+
result = DatetimeIndex(i.tz_localize(None).asi8, **kwargs)
123+
expected = DatetimeIndex(i, **kwargs)
124+
# expected = i.tz_localize(None).tz_localize('UTC').tz_convert(tz)
123125
tm.assert_index_equal(result, expected)
124126

125127
# localize into the provided tz
126-
i2 = DatetimeIndex(i.tz_localize(None).asi8, tz='UTC')
128+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
129+
i2 = DatetimeIndex(i.tz_localize(None).asi8, tz='UTC')
127130
expected = i.tz_localize(None).tz_localize('UTC')
128131
tm.assert_index_equal(i2, expected)
129132

@@ -559,15 +562,20 @@ def test_constructor_timestamp_near_dst(self):
559562
@pytest.mark.parametrize('box', [
560563
np.array, partial(np.array, dtype=object), list])
561564
@pytest.mark.parametrize('tz, dtype', [
562-
['US/Pacific', 'datetime64[ns, US/Pacific]'],
563-
[None, 'datetime64[ns]']])
565+
pytest.param('US/Pacific', 'datetime64[ns, US/Pacific]',
566+
marks=[pytest.mark.xfail(),
567+
pytest.mark.filterwarnings("ignore")]),
568+
[None, 'datetime64[ns]'],
569+
])
564570
def test_constructor_with_int_tz(self, klass, box, tz, dtype):
565571
# GH 20997, 20964
566572
ts = Timestamp('2018-01-01', tz=tz)
567573
result = klass(box([ts.value]), dtype=dtype)
568574
expected = klass([ts])
569575
assert result == expected
570576

577+
@pytest.mark.xfail(reason="TBD", strict=False) # non-strict for tz-naive
578+
@pytest.mark.filterwarnings("ignore::FutureWarning")
571579
def test_construction_int_rountrip(self, tz_naive_fixture):
572580
# GH 12619
573581
tz = tz_naive_fixture

pandas/tests/indexes/multi/test_integrity.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def test_values_multiindex_datetimeindex():
5050
# Test to ensure we hit the boxing / nobox part of MI.values
5151
ints = np.arange(10 ** 18, 10 ** 18 + 5)
5252
naive = pd.DatetimeIndex(ints)
53-
aware = pd.DatetimeIndex(ints, tz='US/Central')
53+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
54+
aware = pd.DatetimeIndex(ints, tz='US/Central')
5455

5556
idx = pd.MultiIndex.from_arrays([naive, aware])
5657
result = idx.values

pandas/tests/indexes/test_base.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,27 +398,34 @@ def test_constructor_dtypes_to_timedelta(self, cast_index, vals):
398398
@pytest.mark.parametrize("klass", [pd.Index, pd.DatetimeIndex])
399399
def test_constructor_dtypes_datetime(self, tz_naive_fixture, attr, utc,
400400
klass):
401+
# TODO: update comment
401402
# Test constructing with a datetimetz dtype
402403
# .values produces numpy datetimes, so these are considered naive
403404
# .asi8 produces integers, so these are considered epoch timestamps
404405
index = pd.date_range('2011-01-01', periods=5)
405406
arg = getattr(index, attr)
406-
if utc:
407-
index = index.tz_localize('UTC').tz_convert(tz_naive_fixture)
408-
else:
409-
index = index.tz_localize(tz_naive_fixture)
407+
index = index.tz_localize(tz_naive_fixture)
410408
dtype = index.dtype
411409

412-
result = klass(arg, tz=tz_naive_fixture)
410+
if tz_naive_fixture and attr == "asi8":
411+
ex_warn = FutureWarning
412+
else:
413+
ex_warn = None
414+
415+
with tm.assert_produces_warning(ex_warn, check_stacklevel=False):
416+
result = klass(arg, tz=tz_naive_fixture)
413417
tm.assert_index_equal(result, index)
414418

415-
result = klass(arg, dtype=dtype)
419+
with tm.assert_produces_warning(ex_warn, check_stacklevel=False):
420+
result = klass(arg, dtype=dtype)
416421
tm.assert_index_equal(result, index)
417422

418-
result = klass(list(arg), tz=tz_naive_fixture)
423+
with tm.assert_produces_warning(ex_warn, check_stacklevel=False):
424+
result = klass(list(arg), tz=tz_naive_fixture)
419425
tm.assert_index_equal(result, index)
420426

421-
result = klass(list(arg), dtype=dtype)
427+
with tm.assert_produces_warning(ex_warn, check_stacklevel=False):
428+
result = klass(list(arg), dtype=dtype)
422429
tm.assert_index_equal(result, index)
423430

424431
@pytest.mark.parametrize("attr", ['values', 'asi8'])

0 commit comments

Comments
 (0)