Fix incorrect DTI/TDI indexing; warn before dropping tzinfo (#22549) · pandas-dev/pandas@935c5d1 (original) (raw)
`@@ -246,15 +246,19 @@ def setup_method(self, method):
`
246
246
`def test_to_period_millisecond(self):
`
247
247
`index = self.index
`
248
248
``
249
``
`-
period = index.to_period(freq='L')
`
``
249
`+
with tm.assert_produces_warning(UserWarning):
`
``
250
`+
warning that timezone info will be lost
`
``
251
`+
period = index.to_period(freq='L')
`
250
252
`assert 2 == len(period)
`
251
253
`assert period[0] == Period('2007-01-01 10:11:12.123Z', 'L')
`
252
254
`assert period[1] == Period('2007-01-01 10:11:13.789Z', 'L')
`
253
255
``
254
256
`def test_to_period_microsecond(self):
`
255
257
`index = self.index
`
256
258
``
257
``
`-
period = index.to_period(freq='U')
`
``
259
`+
with tm.assert_produces_warning(UserWarning):
`
``
260
`+
warning that timezone info will be lost
`
``
261
`+
period = index.to_period(freq='U')
`
258
262
`assert 2 == len(period)
`
259
263
`assert period[0] == Period('2007-01-01 10:11:12.123456Z', 'U')
`
260
264
`assert period[1] == Period('2007-01-01 10:11:13.789123Z', 'U')
`
`@@ -264,12 +268,20 @@ def test_to_period_microsecond(self):
`
264
268
`dateutil.tz.tzutc()])
`
265
269
`def test_to_period_tz(self, tz):
`
266
270
`ts = date_range('1/1/2000', '2/1/2000', tz=tz)
`
267
``
`-
result = ts.to_period()[0]
`
268
``
`-
expected = ts[0].to_period()
`
``
271
+
``
272
`+
with tm.assert_produces_warning(UserWarning):
`
``
273
`+
GH#21333 warning that timezone info will be lost
`
``
274
`+
result = ts.to_period()[0]
`
``
275
`+
expected = ts[0].to_period()
`
``
276
+
269
277
`assert result == expected
`
270
278
``
271
279
`expected = date_range('1/1/2000', '2/1/2000').to_period()
`
272
``
`-
result = ts.to_period()
`
``
280
+
``
281
`+
with tm.assert_produces_warning(UserWarning):
`
``
282
`+
GH#21333 warning that timezone info will be lost
`
``
283
`+
result = ts.to_period()
`
``
284
+
273
285
`tm.assert_index_equal(result, expected)
`
274
286
``
275
287
`def test_to_period_nofreq(self):
`