@@ -51,8 +51,12 @@ def test_from_td64nat_raises(self):
5151 Period (td , freq = "D" )
5252
5353 def test_construction (self ):
54- i1 = Period ("1/1/2005" , freq = "M" )
55- i2 = Period ("Jan 2005" )
54+ with tm .assert_produces_warning (
55+ UserWarning ,
56+ match = "Parsing datetime strings without a format specified" ,
57+ ):
58+ i1 = Period ("1/1/2005" , freq = "M" )
59+ i2 = Period ("Jan 2005" )
5660
5761 assert i1 == i2
5862
@@ -81,7 +85,11 @@ def test_construction(self):
8185 assert i1 == i2
8286
8387 i1 = Period (year = 2005 , month = 3 , day = 1 , freq = "D" )
84- i2 = Period ("3/1/2005" , freq = "D" )
88+ with tm .assert_produces_warning (
89+ UserWarning ,
90+ match = "Parsing datetime strings without a format specified" ,
91+ ):
92+ i2 = Period ("3/1/2005" , freq = "D" )
8593 assert i1 == i2
8694
8795 i3 = Period (year = 2005 , month = 3 , day = 1 , freq = "d" )
@@ -169,11 +177,19 @@ def test_construction_bday(self):
169177 def test_construction_quarter (self ):
170178
171179 i1 = Period (year = 2005 , quarter = 1 , freq = "Q" )
172- i2 = Period ("1/1/2005" , freq = "Q" )
180+ with tm .assert_produces_warning (
181+ UserWarning ,
182+ match = "Parsing datetime strings without a format specified" ,
183+ ):
184+ i2 = Period ("1/1/2005" , freq = "Q" )
173185 assert i1 == i2
174186
175187 i1 = Period (year = 2005 , quarter = 3 , freq = "Q" )
176- i2 = Period ("9/1/2005" , freq = "Q" )
188+ with tm .assert_produces_warning (
189+ UserWarning ,
190+ match = "Parsing datetime strings without a format specified" ,
191+ ):
192+ i2 = Period ("9/1/2005" , freq = "Q" )
177193 assert i1 == i2
178194
179195 i1 = Period ("2005Q1" )
@@ -248,9 +264,13 @@ def test_construction_month(self):
248264 assert i1 == i5
249265
250266 def test_period_constructor_offsets (self ):
251- assert Period ("1/1/2005" , freq = offsets .MonthEnd ()) == Period (
252- "1/1/2005" , freq = "M"
253- )
267+ with tm .assert_produces_warning (
268+ UserWarning ,
269+ match = "Parsing datetime strings without a format specified" ,
270+ ):
271+ assert Period ("1/1/2005" , freq = offsets .MonthEnd ()) == Period (
272+ "1/1/2005" , freq = "M"
273+ )
254274 assert Period ("2005" , freq = offsets .YearEnd ()) == Period ("2005" , freq = "A" )
255275 assert Period ("2005" , freq = offsets .MonthEnd ()) == Period ("2005" , freq = "M" )
256276 assert Period ("3/10/2012" , freq = offsets .BusinessDay ()) == Period (
@@ -281,7 +301,8 @@ def test_period_constructor_offsets(self):
281301 )
282302
283303 with tm .assert_produces_warning (
284- UserWarning , match = "without a format specified"
304+ UserWarning ,
305+ match = "Parsing datetime strings without a format specified" ,
285306 ):
286307 assert Period (200701 , freq = offsets .MonthEnd ()) == Period (200701 , freq = "M" )
287308
@@ -292,7 +313,11 @@ def test_period_constructor_offsets(self):
292313 assert i2 .year == 18695
293314
294315 i1 = Period (datetime (2007 , 1 , 1 ), freq = "M" )
295- i2 = Period ("2007-01" , freq = "M" )
316+ with tm .assert_produces_warning (
317+ UserWarning ,
318+ match = "Parsing datetime strings without a format specified" ,
319+ ):
320+ i2 = Period ("200701" , freq = "M" )
296321 assert i1 == i2
297322
298323 i1 = Period (date (2007 , 1 , 1 ), freq = "M" )
0 commit comments