|
1 | 1 | from datetime import date, datetime, time, timedelta
|
| 2 | +import re |
2 | 3 | from warnings import catch_warnings, simplefilter
|
3 | 4 |
|
4 | 5 | import numpy as np
|
@@ -59,15 +60,16 @@ def test_getitem(self, float_frame):
|
59 | 60 | ad = np.random.randn(len(df))
|
60 | 61 | df["@awesome_domain"] = ad
|
61 | 62 |
|
62 |
| - with pytest.raises(KeyError): |
| 63 | + with pytest.raises(KeyError, match=re.escape("'df[\"$10\"]'")): |
63 | 64 | df.__getitem__('df["$10"]')
|
64 | 65 |
|
65 | 66 | res = df["@awesome_domain"]
|
66 | 67 | tm.assert_numpy_array_equal(ad, res.values)
|
67 | 68 |
|
68 | 69 | def test_getitem_dupe_cols(self):
|
69 | 70 | df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=["a", "a", "b"])
|
70 |
| - with pytest.raises(KeyError): |
| 71 | + msg = "\"None of [Index(['baf'], dtype='object')] are in the [columns]\"" |
| 72 | + with pytest.raises(KeyError, match=re.escape(msg)): |
71 | 73 | df[["baf"]]
|
72 | 74 |
|
73 | 75 | def test_get(self, float_frame):
|
@@ -446,14 +448,16 @@ def test_getitem_setitem_ix_negative_integers(self, float_frame):
|
446 | 448 |
|
447 | 449 | df = DataFrame(np.random.randn(8, 4))
|
448 | 450 | # ix does label-based indexing when having an integer index
|
| 451 | + msg = "\"None of [Int64Index([-1], dtype='int64')] are in the [index]\"" |
449 | 452 | with catch_warnings(record=True):
|
450 | 453 | simplefilter("ignore", FutureWarning)
|
451 |
| - with pytest.raises(KeyError): |
| 454 | + with pytest.raises(KeyError, match=re.escape(msg)): |
452 | 455 | df.ix[[-1]]
|
453 | 456 |
|
| 457 | + msg = "\"None of [Int64Index([-1], dtype='int64')] are in the [columns]\"" |
454 | 458 | with catch_warnings(record=True):
|
455 | 459 | simplefilter("ignore", FutureWarning)
|
456 |
| - with pytest.raises(KeyError): |
| 460 | + with pytest.raises(KeyError, match=re.escape(msg)): |
457 | 461 | df.ix[:, [-1]]
|
458 | 462 |
|
459 | 463 | # #1942
|
@@ -497,7 +501,11 @@ def test_setitem(self, float_frame):
|
497 | 501 | float_frame["col6"] = series
|
498 | 502 | tm.assert_series_equal(series, float_frame["col6"], check_names=False)
|
499 | 503 |
|
500 |
| - with pytest.raises(KeyError): |
| 504 | + msg = ( |
| 505 | + r"\"None of \[Float64Index\(\[.*dtype='float64'\)\] are in the" |
| 506 | + r" \[columns\]\"" |
| 507 | + ) |
| 508 | + with pytest.raises(KeyError, match=msg): |
501 | 509 | float_frame[np.random.randn(len(float_frame) + 1)] = 1
|
502 | 510 |
|
503 | 511 | # set ndarray
|
@@ -1885,10 +1893,10 @@ def test_lookup_bool(self):
|
1885 | 1893 | assert df["mask"].dtype == np.bool_
|
1886 | 1894 |
|
1887 | 1895 | def test_lookup_raises(self, float_frame):
|
1888 |
| - with pytest.raises(KeyError): |
| 1896 | + with pytest.raises(KeyError, match="'One or more row labels was not found'"): |
1889 | 1897 | float_frame.lookup(["xyz"], ["A"])
|
1890 | 1898 |
|
1891 |
| - with pytest.raises(KeyError): |
| 1899 | + with pytest.raises(KeyError, match="'One or more column labels was not found'"): |
1892 | 1900 | float_frame.lookup([float_frame.index[0]], ["xyz"])
|
1893 | 1901 |
|
1894 | 1902 | with pytest.raises(ValueError, match="same size"):
|
@@ -2544,7 +2552,9 @@ def test_xs(self, float_frame, datetime_frame):
|
2544 | 2552 | assert xs["A"] == 1
|
2545 | 2553 | assert xs["B"] == "1"
|
2546 | 2554 |
|
2547 |
| - with pytest.raises(KeyError): |
| 2555 | + with pytest.raises( |
| 2556 | + KeyError, match=re.escape("Timestamp('1999-12-31 00:00:00', freq='B')") |
| 2557 | + ): |
2548 | 2558 | datetime_frame.xs(datetime_frame.index[0] - BDay())
|
2549 | 2559 |
|
2550 | 2560 | # xs get column
|
|
0 commit comments