test_datetime_values.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. # coding=utf-8
  2. # pylint: disable-msg=E1101,W0612
  3. import calendar
  4. from datetime import date, datetime, time
  5. import locale
  6. import unicodedata
  7. import numpy as np
  8. import pytest
  9. import pytz
  10. from pandas._libs.tslibs.timezones import maybe_get_tz
  11. from pandas.core.dtypes.common import is_integer_dtype, is_list_like
  12. import pandas as pd
  13. from pandas import (
  14. DataFrame, DatetimeIndex, Index, PeriodIndex, Series, TimedeltaIndex,
  15. bdate_range, compat, date_range, period_range, timedelta_range)
  16. from pandas.core.arrays import PeriodArray
  17. import pandas.core.common as com
  18. import pandas.util.testing as tm
  19. from pandas.util.testing import assert_series_equal
  20. class TestSeriesDatetimeValues():
  21. def test_dt_namespace_accessor(self):
  22. # GH 7207, 11128
  23. # test .dt namespace accessor
  24. ok_for_period = PeriodArray._datetimelike_ops
  25. ok_for_period_methods = ['strftime', 'to_timestamp', 'asfreq']
  26. ok_for_dt = DatetimeIndex._datetimelike_ops
  27. ok_for_dt_methods = ['to_period', 'to_pydatetime', 'tz_localize',
  28. 'tz_convert', 'normalize', 'strftime', 'round',
  29. 'floor', 'ceil', 'day_name', 'month_name']
  30. ok_for_td = TimedeltaIndex._datetimelike_ops
  31. ok_for_td_methods = ['components', 'to_pytimedelta', 'total_seconds',
  32. 'round', 'floor', 'ceil']
  33. def get_expected(s, name):
  34. result = getattr(Index(s._values), prop)
  35. if isinstance(result, np.ndarray):
  36. if is_integer_dtype(result):
  37. result = result.astype('int64')
  38. elif not is_list_like(result):
  39. return result
  40. return Series(result, index=s.index, name=s.name)
  41. def compare(s, name):
  42. a = getattr(s.dt, prop)
  43. b = get_expected(s, prop)
  44. if not (is_list_like(a) and is_list_like(b)):
  45. assert a == b
  46. else:
  47. tm.assert_series_equal(a, b)
  48. # datetimeindex
  49. cases = [Series(date_range('20130101', periods=5), name='xxx'),
  50. Series(date_range('20130101', periods=5, freq='s'),
  51. name='xxx'),
  52. Series(date_range('20130101 00:00:00', periods=5, freq='ms'),
  53. name='xxx')]
  54. for s in cases:
  55. for prop in ok_for_dt:
  56. # we test freq below
  57. if prop != 'freq':
  58. compare(s, prop)
  59. for prop in ok_for_dt_methods:
  60. getattr(s.dt, prop)
  61. result = s.dt.to_pydatetime()
  62. assert isinstance(result, np.ndarray)
  63. assert result.dtype == object
  64. result = s.dt.tz_localize('US/Eastern')
  65. exp_values = DatetimeIndex(s.values).tz_localize('US/Eastern')
  66. expected = Series(exp_values, index=s.index, name='xxx')
  67. tm.assert_series_equal(result, expected)
  68. tz_result = result.dt.tz
  69. assert str(tz_result) == 'US/Eastern'
  70. freq_result = s.dt.freq
  71. assert freq_result == DatetimeIndex(s.values, freq='infer').freq
  72. # let's localize, then convert
  73. result = s.dt.tz_localize('UTC').dt.tz_convert('US/Eastern')
  74. exp_values = (DatetimeIndex(s.values).tz_localize('UTC')
  75. .tz_convert('US/Eastern'))
  76. expected = Series(exp_values, index=s.index, name='xxx')
  77. tm.assert_series_equal(result, expected)
  78. # datetimeindex with tz
  79. s = Series(date_range('20130101', periods=5, tz='US/Eastern'),
  80. name='xxx')
  81. for prop in ok_for_dt:
  82. # we test freq below
  83. if prop != 'freq':
  84. compare(s, prop)
  85. for prop in ok_for_dt_methods:
  86. getattr(s.dt, prop)
  87. result = s.dt.to_pydatetime()
  88. assert isinstance(result, np.ndarray)
  89. assert result.dtype == object
  90. result = s.dt.tz_convert('CET')
  91. expected = Series(s._values.tz_convert('CET'),
  92. index=s.index, name='xxx')
  93. tm.assert_series_equal(result, expected)
  94. tz_result = result.dt.tz
  95. assert str(tz_result) == 'CET'
  96. freq_result = s.dt.freq
  97. assert freq_result == DatetimeIndex(s.values, freq='infer').freq
  98. # timedelta index
  99. cases = [Series(timedelta_range('1 day', periods=5),
  100. index=list('abcde'), name='xxx'),
  101. Series(timedelta_range('1 day 01:23:45', periods=5,
  102. freq='s'), name='xxx'),
  103. Series(timedelta_range('2 days 01:23:45.012345', periods=5,
  104. freq='ms'), name='xxx')]
  105. for s in cases:
  106. for prop in ok_for_td:
  107. # we test freq below
  108. if prop != 'freq':
  109. compare(s, prop)
  110. for prop in ok_for_td_methods:
  111. getattr(s.dt, prop)
  112. result = s.dt.components
  113. assert isinstance(result, DataFrame)
  114. tm.assert_index_equal(result.index, s.index)
  115. result = s.dt.to_pytimedelta()
  116. assert isinstance(result, np.ndarray)
  117. assert result.dtype == object
  118. result = s.dt.total_seconds()
  119. assert isinstance(result, pd.Series)
  120. assert result.dtype == 'float64'
  121. freq_result = s.dt.freq
  122. assert freq_result == TimedeltaIndex(s.values, freq='infer').freq
  123. # both
  124. index = date_range('20130101', periods=3, freq='D')
  125. s = Series(date_range('20140204', periods=3, freq='s'),
  126. index=index, name='xxx')
  127. exp = Series(np.array([2014, 2014, 2014], dtype='int64'),
  128. index=index, name='xxx')
  129. tm.assert_series_equal(s.dt.year, exp)
  130. exp = Series(np.array([2, 2, 2], dtype='int64'),
  131. index=index, name='xxx')
  132. tm.assert_series_equal(s.dt.month, exp)
  133. exp = Series(np.array([0, 1, 2], dtype='int64'),
  134. index=index, name='xxx')
  135. tm.assert_series_equal(s.dt.second, exp)
  136. exp = pd.Series([s[0]] * 3, index=index, name='xxx')
  137. tm.assert_series_equal(s.dt.normalize(), exp)
  138. # periodindex
  139. cases = [Series(period_range('20130101', periods=5, freq='D'),
  140. name='xxx')]
  141. for s in cases:
  142. for prop in ok_for_period:
  143. # we test freq below
  144. if prop != 'freq':
  145. compare(s, prop)
  146. for prop in ok_for_period_methods:
  147. getattr(s.dt, prop)
  148. freq_result = s.dt.freq
  149. assert freq_result == PeriodIndex(s.values).freq
  150. # test limited display api
  151. def get_dir(s):
  152. results = [r for r in s.dt.__dir__() if not r.startswith('_')]
  153. return list(sorted(set(results)))
  154. s = Series(date_range('20130101', periods=5, freq='D'), name='xxx')
  155. results = get_dir(s)
  156. tm.assert_almost_equal(
  157. results, list(sorted(set(ok_for_dt + ok_for_dt_methods))))
  158. s = Series(period_range('20130101', periods=5,
  159. freq='D', name='xxx').astype(object))
  160. results = get_dir(s)
  161. tm.assert_almost_equal(
  162. results, list(sorted(set(ok_for_period + ok_for_period_methods))))
  163. # 11295
  164. # ambiguous time error on the conversions
  165. s = Series(pd.date_range('2015-01-01', '2016-01-01',
  166. freq='T'), name='xxx')
  167. s = s.dt.tz_localize('UTC').dt.tz_convert('America/Chicago')
  168. results = get_dir(s)
  169. tm.assert_almost_equal(
  170. results, list(sorted(set(ok_for_dt + ok_for_dt_methods))))
  171. exp_values = pd.date_range('2015-01-01', '2016-01-01', freq='T',
  172. tz='UTC').tz_convert('America/Chicago')
  173. expected = Series(exp_values, name='xxx')
  174. tm.assert_series_equal(s, expected)
  175. # no setting allowed
  176. s = Series(date_range('20130101', periods=5, freq='D'), name='xxx')
  177. with pytest.raises(ValueError, match="modifications"):
  178. s.dt.hour = 5
  179. # trying to set a copy
  180. with pd.option_context('chained_assignment', 'raise'):
  181. with pytest.raises(com.SettingWithCopyError):
  182. s.dt.hour[0] = 5
  183. @pytest.mark.parametrize('method, dates', [
  184. ['round', ['2012-01-02', '2012-01-02', '2012-01-01']],
  185. ['floor', ['2012-01-01', '2012-01-01', '2012-01-01']],
  186. ['ceil', ['2012-01-02', '2012-01-02', '2012-01-02']]
  187. ])
  188. def test_dt_round(self, method, dates):
  189. # round
  190. s = Series(pd.to_datetime(['2012-01-01 13:00:00',
  191. '2012-01-01 12:01:00',
  192. '2012-01-01 08:00:00']), name='xxx')
  193. result = getattr(s.dt, method)('D')
  194. expected = Series(pd.to_datetime(dates), name='xxx')
  195. tm.assert_series_equal(result, expected)
  196. def test_dt_round_tz(self):
  197. s = Series(pd.to_datetime(['2012-01-01 13:00:00',
  198. '2012-01-01 12:01:00',
  199. '2012-01-01 08:00:00']), name='xxx')
  200. result = (s.dt.tz_localize('UTC')
  201. .dt.tz_convert('US/Eastern')
  202. .dt.round('D'))
  203. exp_values = pd.to_datetime(['2012-01-01', '2012-01-01',
  204. '2012-01-01']).tz_localize('US/Eastern')
  205. expected = Series(exp_values, name='xxx')
  206. tm.assert_series_equal(result, expected)
  207. @pytest.mark.parametrize('method', ['ceil', 'round', 'floor'])
  208. def test_dt_round_tz_ambiguous(self, method):
  209. # GH 18946 round near "fall back" DST
  210. df1 = pd.DataFrame([
  211. pd.to_datetime('2017-10-29 02:00:00+02:00', utc=True),
  212. pd.to_datetime('2017-10-29 02:00:00+01:00', utc=True),
  213. pd.to_datetime('2017-10-29 03:00:00+01:00', utc=True)
  214. ],
  215. columns=['date'])
  216. df1['date'] = df1['date'].dt.tz_convert('Europe/Madrid')
  217. # infer
  218. result = getattr(df1.date.dt, method)('H', ambiguous='infer')
  219. expected = df1['date']
  220. tm.assert_series_equal(result, expected)
  221. # bool-array
  222. result = getattr(df1.date.dt, method)(
  223. 'H', ambiguous=[True, False, False]
  224. )
  225. tm.assert_series_equal(result, expected)
  226. # NaT
  227. result = getattr(df1.date.dt, method)('H', ambiguous='NaT')
  228. expected = df1['date'].copy()
  229. expected.iloc[0:2] = pd.NaT
  230. tm.assert_series_equal(result, expected)
  231. # raise
  232. with pytest.raises(pytz.AmbiguousTimeError):
  233. getattr(df1.date.dt, method)('H', ambiguous='raise')
  234. @pytest.mark.parametrize('method, ts_str, freq', [
  235. ['ceil', '2018-03-11 01:59:00-0600', '5min'],
  236. ['round', '2018-03-11 01:59:00-0600', '5min'],
  237. ['floor', '2018-03-11 03:01:00-0500', '2H']])
  238. def test_dt_round_tz_nonexistent(self, method, ts_str, freq):
  239. # GH 23324 round near "spring forward" DST
  240. s = Series([pd.Timestamp(ts_str, tz='America/Chicago')])
  241. result = getattr(s.dt, method)(freq, nonexistent='shift_forward')
  242. expected = Series(
  243. [pd.Timestamp('2018-03-11 03:00:00', tz='America/Chicago')]
  244. )
  245. tm.assert_series_equal(result, expected)
  246. result = getattr(s.dt, method)(freq, nonexistent='NaT')
  247. expected = Series([pd.NaT]).dt.tz_localize(result.dt.tz)
  248. tm.assert_series_equal(result, expected)
  249. with pytest.raises(pytz.NonExistentTimeError,
  250. match='2018-03-11 02:00:00'):
  251. getattr(s.dt, method)(freq, nonexistent='raise')
  252. def test_dt_namespace_accessor_categorical(self):
  253. # GH 19468
  254. dti = DatetimeIndex(['20171111', '20181212']).repeat(2)
  255. s = Series(pd.Categorical(dti), name='foo')
  256. result = s.dt.year
  257. expected = Series([2017, 2017, 2018, 2018], name='foo')
  258. tm.assert_series_equal(result, expected)
  259. def test_dt_accessor_no_new_attributes(self):
  260. # https://github.com/pandas-dev/pandas/issues/10673
  261. s = Series(date_range('20130101', periods=5, freq='D'))
  262. with pytest.raises(AttributeError,
  263. match="You cannot add any new attribute"):
  264. s.dt.xlabel = "a"
  265. @pytest.mark.parametrize('time_locale', [
  266. None] if tm.get_locales() is None else [None] + tm.get_locales())
  267. def test_dt_accessor_datetime_name_accessors(self, time_locale):
  268. # Test Monday -> Sunday and January -> December, in that sequence
  269. if time_locale is None:
  270. # If the time_locale is None, day-name and month_name should
  271. # return the english attributes
  272. expected_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
  273. 'Friday', 'Saturday', 'Sunday']
  274. expected_months = ['January', 'February', 'March', 'April', 'May',
  275. 'June', 'July', 'August', 'September',
  276. 'October', 'November', 'December']
  277. else:
  278. with tm.set_locale(time_locale, locale.LC_TIME):
  279. expected_days = calendar.day_name[:]
  280. expected_months = calendar.month_name[1:]
  281. s = Series(date_range(freq='D', start=datetime(1998, 1, 1),
  282. periods=365))
  283. english_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
  284. 'Friday', 'Saturday', 'Sunday']
  285. for day, name, eng_name in zip(range(4, 11),
  286. expected_days,
  287. english_days):
  288. name = name.capitalize()
  289. assert s.dt.weekday_name[day] == eng_name
  290. assert s.dt.day_name(locale=time_locale)[day] == name
  291. s = s.append(Series([pd.NaT]))
  292. assert np.isnan(s.dt.day_name(locale=time_locale).iloc[-1])
  293. s = Series(date_range(freq='M', start='2012', end='2013'))
  294. result = s.dt.month_name(locale=time_locale)
  295. expected = Series([month.capitalize() for month in expected_months])
  296. # work around https://github.com/pandas-dev/pandas/issues/22342
  297. if not compat.PY2:
  298. result = result.str.normalize("NFD")
  299. expected = expected.str.normalize("NFD")
  300. tm.assert_series_equal(result, expected)
  301. for s_date, expected in zip(s, expected_months):
  302. result = s_date.month_name(locale=time_locale)
  303. expected = expected.capitalize()
  304. if not compat.PY2:
  305. result = unicodedata.normalize("NFD", result)
  306. expected = unicodedata.normalize("NFD", expected)
  307. assert result == expected
  308. s = s.append(Series([pd.NaT]))
  309. assert np.isnan(s.dt.month_name(locale=time_locale).iloc[-1])
  310. def test_strftime(self):
  311. # GH 10086
  312. s = Series(date_range('20130101', periods=5))
  313. result = s.dt.strftime('%Y/%m/%d')
  314. expected = Series(['2013/01/01', '2013/01/02', '2013/01/03',
  315. '2013/01/04', '2013/01/05'])
  316. tm.assert_series_equal(result, expected)
  317. s = Series(date_range('2015-02-03 11:22:33.4567', periods=5))
  318. result = s.dt.strftime('%Y/%m/%d %H-%M-%S')
  319. expected = Series(['2015/02/03 11-22-33', '2015/02/04 11-22-33',
  320. '2015/02/05 11-22-33', '2015/02/06 11-22-33',
  321. '2015/02/07 11-22-33'])
  322. tm.assert_series_equal(result, expected)
  323. s = Series(period_range('20130101', periods=5))
  324. result = s.dt.strftime('%Y/%m/%d')
  325. expected = Series(['2013/01/01', '2013/01/02', '2013/01/03',
  326. '2013/01/04', '2013/01/05'])
  327. tm.assert_series_equal(result, expected)
  328. s = Series(period_range(
  329. '2015-02-03 11:22:33.4567', periods=5, freq='s'))
  330. result = s.dt.strftime('%Y/%m/%d %H-%M-%S')
  331. expected = Series(['2015/02/03 11-22-33', '2015/02/03 11-22-34',
  332. '2015/02/03 11-22-35', '2015/02/03 11-22-36',
  333. '2015/02/03 11-22-37'])
  334. tm.assert_series_equal(result, expected)
  335. s = Series(date_range('20130101', periods=5))
  336. s.iloc[0] = pd.NaT
  337. result = s.dt.strftime('%Y/%m/%d')
  338. expected = Series(['NaT', '2013/01/02', '2013/01/03', '2013/01/04',
  339. '2013/01/05'])
  340. tm.assert_series_equal(result, expected)
  341. datetime_index = date_range('20150301', periods=5)
  342. result = datetime_index.strftime("%Y/%m/%d")
  343. expected = Index(['2015/03/01', '2015/03/02', '2015/03/03',
  344. '2015/03/04', '2015/03/05'], dtype=np.object_)
  345. # dtype may be S10 or U10 depending on python version
  346. tm.assert_index_equal(result, expected)
  347. period_index = period_range('20150301', periods=5)
  348. result = period_index.strftime("%Y/%m/%d")
  349. expected = Index(['2015/03/01', '2015/03/02', '2015/03/03',
  350. '2015/03/04', '2015/03/05'], dtype='=U10')
  351. tm.assert_index_equal(result, expected)
  352. s = Series([datetime(2013, 1, 1, 2, 32, 59), datetime(2013, 1, 2, 14,
  353. 32, 1)])
  354. result = s.dt.strftime('%Y-%m-%d %H:%M:%S')
  355. expected = Series(["2013-01-01 02:32:59", "2013-01-02 14:32:01"])
  356. tm.assert_series_equal(result, expected)
  357. s = Series(period_range('20130101', periods=4, freq='H'))
  358. result = s.dt.strftime('%Y/%m/%d %H:%M:%S')
  359. expected = Series(["2013/01/01 00:00:00", "2013/01/01 01:00:00",
  360. "2013/01/01 02:00:00", "2013/01/01 03:00:00"])
  361. s = Series(period_range('20130101', periods=4, freq='L'))
  362. result = s.dt.strftime('%Y/%m/%d %H:%M:%S.%l')
  363. expected = Series(["2013/01/01 00:00:00.000",
  364. "2013/01/01 00:00:00.001",
  365. "2013/01/01 00:00:00.002",
  366. "2013/01/01 00:00:00.003"])
  367. tm.assert_series_equal(result, expected)
  368. def test_valid_dt_with_missing_values(self):
  369. from datetime import date, time
  370. # GH 8689
  371. s = Series(date_range('20130101', periods=5, freq='D'))
  372. s.iloc[2] = pd.NaT
  373. for attr in ['microsecond', 'nanosecond', 'second', 'minute', 'hour',
  374. 'day']:
  375. expected = getattr(s.dt, attr).copy()
  376. expected.iloc[2] = np.nan
  377. result = getattr(s.dt, attr)
  378. tm.assert_series_equal(result, expected)
  379. result = s.dt.date
  380. expected = Series(
  381. [date(2013, 1, 1), date(2013, 1, 2), np.nan, date(2013, 1, 4),
  382. date(2013, 1, 5)], dtype='object')
  383. tm.assert_series_equal(result, expected)
  384. result = s.dt.time
  385. expected = Series(
  386. [time(0), time(0), np.nan, time(0), time(0)], dtype='object')
  387. tm.assert_series_equal(result, expected)
  388. def test_dt_accessor_api(self):
  389. # GH 9322
  390. from pandas.core.indexes.accessors import (
  391. CombinedDatetimelikeProperties, DatetimeProperties)
  392. assert Series.dt is CombinedDatetimelikeProperties
  393. s = Series(date_range('2000-01-01', periods=3))
  394. assert isinstance(s.dt, DatetimeProperties)
  395. @pytest.mark.parametrize('ser', [Series(np.arange(5)),
  396. Series(list('abcde')),
  397. Series(np.random.randn(5))])
  398. def test_dt_accessor_invalid(self, ser):
  399. # GH#9322 check that series with incorrect dtypes don't have attr
  400. with pytest.raises(AttributeError, match="only use .dt accessor"):
  401. ser.dt
  402. assert not hasattr(ser, 'dt')
  403. def test_dt_accessor_updates_on_inplace(self):
  404. s = Series(pd.date_range('2018-01-01', periods=10))
  405. s[2] = None
  406. s.fillna(pd.Timestamp('2018-01-01'), inplace=True)
  407. result = s.dt.date
  408. assert result[0] == result[2]
  409. def test_between(self):
  410. s = Series(bdate_range('1/1/2000', periods=20).astype(object))
  411. s[::2] = np.nan
  412. result = s[s.between(s[3], s[17])]
  413. expected = s[3:18].dropna()
  414. assert_series_equal(result, expected)
  415. result = s[s.between(s[3], s[17], inclusive=False)]
  416. expected = s[5:16].dropna()
  417. assert_series_equal(result, expected)
  418. def test_date_tz(self):
  419. # GH11757
  420. rng = pd.DatetimeIndex(['2014-04-04 23:56',
  421. '2014-07-18 21:24',
  422. '2015-11-22 22:14'], tz="US/Eastern")
  423. s = Series(rng)
  424. expected = Series([date(2014, 4, 4),
  425. date(2014, 7, 18),
  426. date(2015, 11, 22)])
  427. assert_series_equal(s.dt.date, expected)
  428. assert_series_equal(s.apply(lambda x: x.date()), expected)
  429. def test_datetime_understood(self):
  430. # Ensures it doesn't fail to create the right series
  431. # reported in issue#16726
  432. series = pd.Series(pd.date_range("2012-01-01", periods=3))
  433. offset = pd.offsets.DateOffset(days=6)
  434. result = series - offset
  435. expected = pd.Series(pd.to_datetime([
  436. '2011-12-26', '2011-12-27', '2011-12-28']))
  437. tm.assert_series_equal(result, expected)
  438. def test_dt_timetz_accessor(self, tz_naive_fixture):
  439. # GH21358
  440. tz = maybe_get_tz(tz_naive_fixture)
  441. dtindex = pd.DatetimeIndex(['2014-04-04 23:56', '2014-07-18 21:24',
  442. '2015-11-22 22:14'], tz=tz)
  443. s = Series(dtindex)
  444. expected = Series([time(23, 56, tzinfo=tz), time(21, 24, tzinfo=tz),
  445. time(22, 14, tzinfo=tz)])
  446. result = s.dt.timetz
  447. tm.assert_series_equal(result, expected)
  448. def test_setitem_with_string_index(self):
  449. # GH 23451
  450. x = pd.Series([1, 2, 3], index=['Date', 'b', 'other'])
  451. x['Date'] = date.today()
  452. assert x.Date == date.today()
  453. assert x['Date'] == date.today()
  454. def test_setitem_with_different_tz(self):
  455. # GH#24024
  456. ser = pd.Series(pd.date_range('2000', periods=2, tz="US/Central"))
  457. ser[0] = pd.Timestamp("2000", tz='US/Eastern')
  458. expected = pd.Series([
  459. pd.Timestamp("2000-01-01 00:00:00-05:00", tz="US/Eastern"),
  460. pd.Timestamp("2000-01-02 00:00:00-06:00", tz="US/Central"),
  461. ], dtype=object)
  462. tm.assert_series_equal(ser, expected)