Skip to content

Commit 695c1ea

Browse files
committed
add missing return
1 parent de96698 commit 695c1ea

File tree

4 files changed

+58
-27
lines changed

4 files changed

+58
-27
lines changed

pandas/tests/frame/methods/test_reset_index.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -337,24 +337,19 @@ def test_reset_index_multiindex_nan(self):
337337
tm.assert_frame_equal(rs, df)
338338

339339
@pytest.mark.parametrize(
340-
"name",
340+
"name, warn",
341341
[
342-
None,
343-
"foo",
344-
2,
345-
3.0,
346-
pd.Timedelta(6),
347-
Timestamp("2012-12-30", tz="UTC"),
348-
"2012-12-31",
342+
(None, UserWarning),
343+
("foo", UserWarning),
344+
(2, None),
345+
(3.0, None),
346+
(pd.Timedelta(6), None),
347+
(Timestamp("2012-12-30", tz="UTC"), FutureWarning),
348+
("2012-12-31", None),
349349
],
350350
)
351-
def test_reset_index_with_datetimeindex_cols(self, name):
351+
def test_reset_index_with_datetimeindex_cols(self, name, warn):
352352
# GH#5818
353-
warn = None
354-
if isinstance(name, Timestamp) and name.tz is not None:
355-
# _deprecate_mismatched_indexing
356-
warn = FutureWarning
357-
358353
df = DataFrame(
359354
[[1, 2], [3, 4]],
360355
columns=date_range("1/1/2013", "1/2/2013"),

pandas/tests/io/parser/test_parse_dates.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,12 @@ def test_parse_date_column_with_empty_string(all_parsers):
16301630
# see gh-6428
16311631
parser = all_parsers
16321632
data = "case,opdate\n7,10/18/2006\n7,10/18/2008\n621, "
1633-
result = parser.read_csv(StringIO(data), parse_dates=["opdate"])
1633+
result = parser.read_csv_check_warnings(
1634+
UserWarning,
1635+
"Parsing datetime strings without a format specified",
1636+
StringIO(data),
1637+
parse_dates=["opdate"],
1638+
)
16341639

16351640
expected_data = [[7, "10/18/2006"], [7, "10/18/2008"], [621, " "]]
16361641
expected = DataFrame(expected_data, columns=["case", "opdate"])

pandas/tests/scalar/period/test_period.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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")

pandas/tests/tslibs/test_array_to_datetime.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,17 @@ def test_coerce_of_invalid_datetimes(errors):
166166
if errors == "ignore":
167167
# Without coercing, the presence of any invalid
168168
# dates prevents any values from being converted.
169-
result, _ = tslib.array_to_datetime(**kwargs)
169+
with tm.assert_produces_warning(
170+
UserWarning, match="without a format specified"
171+
):
172+
result, _ = tslib.array_to_datetime(**kwargs)
170173
tm.assert_numpy_array_equal(result, arr)
171174
else: # coerce.
172175
# With coercing, the invalid dates becomes iNaT
173-
result, _ = tslib.array_to_datetime(arr, errors="coerce")
176+
with tm.assert_produces_warning(
177+
UserWarning, match="without a format specified"
178+
):
179+
result, _ = tslib.array_to_datetime(arr, errors="coerce")
174180
expected = ["2013-01-01T00:00:00.000000000", iNaT, iNaT]
175181

176182
tm.assert_numpy_array_equal(result, np.array(expected, dtype="M8[ns]"))

0 commit comments

Comments
 (0)