@@ -231,3 +231,43 @@ def test_dunder_array(array):
231231 np .array (obj , dtype = dtype )
232232 with pytest .raises (TypeError , match = msg ):
233233 np .array (obj , dtype = getattr (np , dtype ))
234+
235+
236+ def test_to_timestamp_monthly_resolution ():
237+ idx = PeriodIndex (["2011-01" , "NaT" , "2011-02" ], freq = "2M" )
238+ ts = idx .to_timestamp ()
239+ assert ts .dtype == np .dtype ("datetime64[M]" )
240+
241+
242+ def test_to_timestamp_yearly_resolution ():
243+ idx = PeriodIndex (["2011" , "2012" ], freq = "A" )
244+ ts = idx .to_timestamp ()
245+ assert ts .dtype == np .dtype ("datetime64[Y]" )
246+
247+
248+ def test_to_timestamp_large_month_no_out_of_bounds ():
249+ idx = PeriodIndex (["May 3000" ], freq = "M" )
250+ ts = idx .to_timestamp ()
251+ assert ts .dtype == np .dtype ("datetime64[M]" )
252+ assert str (ts [0 ]) == "3000-05"
253+
254+
255+ def test_to_timestamp_large_year_no_out_of_bounds ():
256+ idx = PeriodIndex (["3000" ], freq = "Y" )
257+ ts = idx .to_timestamp ()
258+ assert ts .dtype == np .dtype ("datetime64[Y]" )
259+ assert str (ts [0 ]) == "3000"
260+
261+
262+ def test_to_timestamp_daily_resolution ():
263+ idx = PeriodIndex (["2011-01-01" , "2011-01-02" ], freq = "D" )
264+ ts = idx .to_timestamp ()
265+ assert ts .dtype == np .dtype ("datetime64[D]" )
266+
267+
268+ def test_to_timestamp_nanosecond_resolution ():
269+ idx = PeriodIndex (
270+ ["2011-01-01 00:00:00.000000001" , "2011-01-01 00:00:00.000000002" ], freq = "N"
271+ )
272+ ts = idx .to_timestamp ()
273+ assert ts .dtype == np .dtype ("datetime64[ns]" )
0 commit comments