Skip to content

Commit 7c1c4e6

Browse files
committed
more fixups
1 parent dee9018 commit 7c1c4e6

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

pandas/tests/dtypes/test_generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class TestABCClasses:
1919
tuples = [[1, 2, 2], ["red", "blue", "red"]]
2020
multi_index = pd.MultiIndex.from_arrays(tuples, names=("number", "color"))
21-
datetime_index = pd.to_datetime(["1/1/2000", "1/1/2010"])
21+
datetime_index = pd.to_datetime(["2000/1/1", "2010/1/1"])
2222
timedelta_index = pd.to_timedelta(np.arange(5), unit="s")
2323
period_index = pd.period_range("1/1/2000", "1/1/2010", freq="M")
2424
categorical = pd.Categorical([1, 2, 3], categories=[2, 3, 1])

pandas/tests/frame/methods/test_reset_index.py

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

339339
@pytest.mark.parametrize(
340-
"name, warn",
340+
"name",
341341
[
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),
342+
None,
343+
"foo",
344+
2,
345+
3.0,
346+
pd.Timedelta(6),
347+
Timestamp("2012-12-30", tz="UTC"),
348+
"2012-12-31",
349349
],
350350
)
351-
def test_reset_index_with_datetimeindex_cols(self, name, warn):
351+
def test_reset_index_with_datetimeindex_cols(self, name):
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+
353358
df = DataFrame(
354359
[[1, 2], [3, 4]],
355360
columns=date_range("1/1/2013", "1/2/2013"),

pandas/tests/tslibs/test_array_to_datetime.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,30 @@ def test_number_looking_strings_not_into_datetime(data):
119119

120120

121121
@pytest.mark.parametrize(
122-
"invalid_date",
122+
"invalid_date, warn",
123123
[
124-
date(1000, 1, 1),
125-
datetime(1000, 1, 1),
126-
"1000-01-01",
127-
"Jan 1, 1000",
128-
np.datetime64("1000-01-01"),
124+
(date(1000, 1, 1), None),
125+
(datetime(1000, 1, 1), None),
126+
("1000-01-01", None),
127+
("Jan 1, 1000", UserWarning),
128+
(np.datetime64("1000-01-01"), None),
129129
],
130130
)
131131
@pytest.mark.parametrize("errors", ["coerce", "raise"])
132-
def test_coerce_outside_ns_bounds(invalid_date, errors):
132+
def test_coerce_outside_ns_bounds(invalid_date, warn, errors):
133133
arr = np.array([invalid_date], dtype="object")
134134
kwargs = {"values": arr, "errors": errors}
135135

136136
if errors == "raise":
137137
msg = "Out of bounds .* present at position 0"
138138

139-
with pytest.raises(ValueError, match=msg):
139+
with pytest.raises(ValueError, match=msg), tm.assert_produces_warning(
140+
warn, match="without a format specified"
141+
):
140142
tslib.array_to_datetime(**kwargs)
141143
else: # coerce.
142-
result, _ = tslib.array_to_datetime(**kwargs)
144+
with tm.assert_produces_warning(warn, match="without a format specified"):
145+
result, _ = tslib.array_to_datetime(**kwargs)
143146
expected = np.array([iNaT], dtype="M8[ns]")
144147

145148
tm.assert_numpy_array_equal(result, expected)
@@ -163,17 +166,11 @@ def test_coerce_of_invalid_datetimes(errors):
163166
if errors == "ignore":
164167
# Without coercing, the presence of any invalid
165168
# dates prevents any values from being converted.
166-
with tm.assert_produces_warning(
167-
UserWarning, match="without a format specified"
168-
):
169-
result, _ = tslib.array_to_datetime(**kwargs)
169+
result, _ = tslib.array_to_datetime(**kwargs)
170170
tm.assert_numpy_array_equal(result, arr)
171171
else: # coerce.
172172
# With coercing, the invalid dates becomes iNaT
173-
with tm.assert_produces_warning(
174-
UserWarning, match="without a format specified"
175-
):
176-
result, _ = tslib.array_to_datetime(arr, errors="coerce")
173+
result, _ = tslib.array_to_datetime(arr, errors="coerce")
177174
expected = ["2013-01-01T00:00:00.000000000", iNaT, iNaT]
178175

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

0 commit comments

Comments
 (0)