From 8fe68af07b0e573929831a1698fc9f1e483ef3c5 Mon Sep 17 00:00:00 2001 From: Alvaro Santiesteban Date: Thu, 13 Feb 2020 03:43:32 +0000 Subject: [PATCH 1/3] Third batch of files --- pandas/tests/indexes/interval/test_setops.py | 6 +- pandas/tests/indexes/multi/test_compat.py | 2 +- .../tests/indexes/period/test_constructors.py | 2 +- .../indexes/timedeltas/test_constructors.py | 2 +- pandas/tests/indexing/test_floats.py | 136 +++++++++--------- 5 files changed, 73 insertions(+), 75 deletions(-) diff --git a/pandas/tests/indexes/interval/test_setops.py b/pandas/tests/indexes/interval/test_setops.py index 3246ac6bafde9..b9eb8b7c41018 100644 --- a/pandas/tests/indexes/interval/test_setops.py +++ b/pandas/tests/indexes/interval/test_setops.py @@ -180,8 +180,8 @@ def test_set_incompatible_types(self, closed, op_name, sort): # GH 19016: incompatible dtypes other = interval_range(Timestamp("20180101"), periods=9, closed=closed) msg = ( - "can only do {op} between two IntervalIndex objects that have " - "compatible dtypes" - ).format(op=op_name) + f"can only do {op_name} between two IntervalIndex objects that have " + f"compatible dtypes" + ) with pytest.raises(TypeError, match=msg): set_op(other, sort=sort) diff --git a/pandas/tests/indexes/multi/test_compat.py b/pandas/tests/indexes/multi/test_compat.py index 9a76f0623eb31..ef549beccda5d 100644 --- a/pandas/tests/indexes/multi/test_compat.py +++ b/pandas/tests/indexes/multi/test_compat.py @@ -29,7 +29,7 @@ def test_numeric_compat(idx): @pytest.mark.parametrize("method", ["all", "any"]) def test_logical_compat(idx, method): - msg = "cannot perform {method}".format(method=method) + msg = f"cannot perform {method}" with pytest.raises(TypeError, match=msg): getattr(idx, method)() diff --git a/pandas/tests/indexes/period/test_constructors.py b/pandas/tests/indexes/period/test_constructors.py index fcbadce3d63b1..418f53591b913 100644 --- a/pandas/tests/indexes/period/test_constructors.py +++ b/pandas/tests/indexes/period/test_constructors.py @@ -364,7 +364,7 @@ def test_constructor_year_and_quarter(self): year = pd.Series([2001, 2002, 2003]) quarter = year - 2000 idx = PeriodIndex(year=year, quarter=quarter) - strs = ["{t[0]:d}Q{t[1]:d}".format(t=t) for t in zip(quarter, year)] + strs = [f"{t[0]:d}Q{t[1]:d}" for t in zip(quarter, year)] lops = list(map(Period, strs)) p = PeriodIndex(lops) tm.assert_index_equal(p, idx) diff --git a/pandas/tests/indexes/timedeltas/test_constructors.py b/pandas/tests/indexes/timedeltas/test_constructors.py index 0de10b5d82171..8e54561df1624 100644 --- a/pandas/tests/indexes/timedeltas/test_constructors.py +++ b/pandas/tests/indexes/timedeltas/test_constructors.py @@ -155,7 +155,7 @@ def test_constructor(self): def test_constructor_iso(self): # GH #21877 expected = timedelta_range("1s", periods=9, freq="s") - durations = ["P0DT0H0M{}S".format(i) for i in range(1, 10)] + durations = [f"P0DT0H0M{i}S" for i in range(1, 10)] result = to_timedelta(durations) tm.assert_index_equal(result, expected) diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index f783c3516e357..b91970765005f 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -53,8 +53,8 @@ def test_scalar_error(self, index_func): s.iloc[3.0] msg = ( - "cannot do positional indexing on {klass} with these " - r"indexers \[3\.0\] of type float".format(klass=type(i).__name__) + fr"cannot do positional indexing on {type(i).__name__} with these " + fr"indexers \[3\.0\] of type float" ) with pytest.raises(TypeError, match=msg): s.iloc[3.0] = 0 @@ -94,11 +94,11 @@ def test_scalar_non_numeric(self, index_func): else: error = TypeError msg = ( - r"cannot do (label|positional) indexing " - r"on {klass} with these indexers \[3\.0\] of " - r"type float|" - "Cannot index by location index with a " - "non-integer key".format(klass=type(i).__name__) + fr"cannot do (label|positional) indexing " + fr"on {type(i).__name__} with these indexers \[3\.0\] of " + fr"type float|" + fr"Cannot index by location index with a " + fr"non-integer key" ) with pytest.raises(error, match=msg): idxr(s)[3.0] @@ -115,9 +115,9 @@ def test_scalar_non_numeric(self, index_func): else: error = TypeError msg = ( - r"cannot do (label|positional) indexing " - r"on {klass} with these indexers \[3\.0\] of " - r"type float".format(klass=type(i).__name__) + fr"cannot do (label|positional) indexing " + fr"on {type(i).__name__} with these indexers \[3\.0\] of " + fr"type float" ) with pytest.raises(error, match=msg): s.loc[3.0] @@ -127,9 +127,9 @@ def test_scalar_non_numeric(self, index_func): # setting with a float fails with iloc msg = ( - r"cannot do (label|positional) indexing " - r"on {klass} with these indexers \[3\.0\] of " - r"type float".format(klass=type(i).__name__) + fr"cannot do (label|positional) indexing " + fr"on {type(i).__name__} with these indexers \[3\.0\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): s.iloc[3.0] = 0 @@ -164,9 +164,9 @@ def test_scalar_non_numeric(self, index_func): s = Series(np.arange(len(i)), index=i) s[3] msg = ( - r"cannot do (label|positional) indexing " - r"on {klass} with these indexers \[3\.0\] of " - r"type float".format(klass=type(i).__name__) + fr"cannot do (label|positional) indexing " + fr"on {type(i).__name__} with these indexers \[3\.0\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): s[3.0] @@ -181,12 +181,10 @@ def test_scalar_with_mixed(self): for idxr in [lambda x: x, lambda x: x.iloc]: msg = ( - r"cannot do label indexing " - r"on {klass} with these indexers \[1\.0\] of " - r"type float|" - "Cannot index by location index with a non-integer key".format( - klass=Index.__name__ - ) + fr"cannot do label indexing " + fr"on {Index.__name__} with these indexers \[1\.0\] of " + fr"type float|" + fr"Cannot index by location index with a non-integer key" ) with pytest.raises(TypeError, match=msg): idxr(s2)[1.0] @@ -203,9 +201,9 @@ def test_scalar_with_mixed(self): for idxr in [lambda x: x]: msg = ( - r"cannot do label indexing " - r"on {klass} with these indexers \[1\.0\] of " - r"type float".format(klass=Index.__name__) + fr"cannot do label indexing " + fr"on {Index.__name__} with these indexers \[1\.0\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): idxr(s3)[1.0] @@ -321,9 +319,9 @@ def test_scalar_float(self): s.iloc[3.0] msg = ( - r"cannot do positional indexing " - r"on {klass} with these indexers \[3\.0\] of " - r"type float".format(klass=Float64Index.__name__) + fr"cannot do positional indexing " + fr"on {Float64Index.__name__} with these indexers \[3\.0\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): s2.iloc[3.0] = 0 @@ -354,9 +352,9 @@ def test_slice_non_numeric(self, index_func): for l in [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]: msg = ( - "cannot do positional indexing " - r"on {klass} with these indexers \[(3|4)\.0\] of " - "type float".format(klass=type(index).__name__) + fr"cannot do positional indexing " + fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): s.iloc[l] @@ -364,10 +362,10 @@ def test_slice_non_numeric(self, index_func): for idxr in [lambda x: x.loc, lambda x: x.iloc, lambda x: x]: msg = ( - "cannot do (slice|positional) indexing " - r"on {klass} with these indexers " - r"\[(3|4)(\.0)?\] " - r"of type (float|int)".format(klass=type(index).__name__) + fr"cannot do (slice|positional) indexing " + fr"on {type(index).__name__} with these indexers " + fr"\[(3|4)(\.0)?\] " + fr"of type (float|int)" ) with pytest.raises(TypeError, match=msg): idxr(s)[l] @@ -376,19 +374,19 @@ def test_slice_non_numeric(self, index_func): for l in [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]: msg = ( - "cannot do positional indexing " - r"on {klass} with these indexers \[(3|4)\.0\] of " - "type float".format(klass=type(index).__name__) + fr"cannot do positional indexing " + fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): s.iloc[l] = 0 for idxr in [lambda x: x.loc, lambda x: x.iloc, lambda x: x]: msg = ( - "cannot do (slice|positional) indexing " - r"on {klass} with these indexers " - r"\[(3|4)(\.0)?\] " - r"of type (float|int)".format(klass=type(index).__name__) + fr"cannot do (slice|positional) indexing " + fr"on {type(index).__name__} with these indexers " + fr"\[(3|4)(\.0)?\] " + fr"of type (float|int)" ) with pytest.raises(TypeError, match=msg): idxr(s)[l] = 0 @@ -426,9 +424,9 @@ def test_slice_integer(self): # positional indexing msg = ( - "cannot do slice indexing " - r"on {klass} with these indexers \[(3|4)\.0\] of " - "type float".format(klass=type(index).__name__) + fr"cannot do slice indexing " + fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): s[l] @@ -450,9 +448,9 @@ def test_slice_integer(self): # positional indexing msg = ( - "cannot do slice indexing " - r"on {klass} with these indexers \[-6\.0\] of " - "type float".format(klass=type(index).__name__) + fr"cannot do slice indexing " + fr"on {type(index).__name__} with these indexers \[-6\.0\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): s[slice(-6.0, 6.0)] @@ -476,9 +474,9 @@ def test_slice_integer(self): # positional indexing msg = ( - "cannot do slice indexing " - r"on {klass} with these indexers \[(2|3)\.5\] of " - "type float".format(klass=type(index).__name__) + fr"cannot do slice indexing " + fr"on {type(index).__name__} with these indexers \[(2|3)\.5\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): s[l] @@ -494,9 +492,9 @@ def test_slice_integer(self): # positional indexing msg = ( - "cannot do slice indexing " - r"on {klass} with these indexers \[(3|4)\.0\] of " - "type float".format(klass=type(index).__name__) + fr"cannot do slice indexing " + fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): s[l] = 0 @@ -517,9 +515,9 @@ def test_integer_positional_indexing(self): klass = RangeIndex msg = ( - "cannot do (slice|positional) indexing " - r"on {klass} with these indexers \[(2|4)\.0\] of " - "type float".format(klass=klass.__name__) + fr"cannot do (slice|positional) indexing " + fr"on {klass.__name__} with these indexers \[(2|4)\.0\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): idxr(s)[l] @@ -545,9 +543,9 @@ def f(idxr): # positional indexing msg = ( - "cannot do slice indexing " - r"on {klass} with these indexers \[(0|1)\.0\] of " - "type float".format(klass=type(index).__name__) + fr"cannot do slice indexing " + fr"on {type(index).__name__} with these indexers \[(0|1)\.0\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): s[l] @@ -560,9 +558,9 @@ def f(idxr): # positional indexing msg = ( - "cannot do slice indexing " - r"on {klass} with these indexers \[-10\.0\] of " - "type float".format(klass=type(index).__name__) + fr"cannot do slice indexing " + fr"on {type(index).__name__} with these indexers \[-10\.0\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): s[slice(-10.0, 10.0)] @@ -579,9 +577,9 @@ def f(idxr): # positional indexing msg = ( - "cannot do slice indexing " - r"on {klass} with these indexers \[0\.5\] of " - "type float".format(klass=type(index).__name__) + fr"cannot do slice indexing " + fr"on {type(index).__name__} with these indexers \[0\.5\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): s[l] @@ -596,9 +594,9 @@ def f(idxr): # positional indexing msg = ( - "cannot do slice indexing " - r"on {klass} with these indexers \[(3|4)\.0\] of " - "type float".format(klass=type(index).__name__) + fr"cannot do slice indexing " + fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " + fr"type float" ) with pytest.raises(TypeError, match=msg): s[l] = 0 From 6fec483a86a237a2feafe0f124b6ae489b9080cb Mon Sep 17 00:00:00 2001 From: Alvaro Santiesteban Date: Thu, 13 Feb 2020 19:30:48 +0000 Subject: [PATCH 2/3] remove unnecesary f and fr prefixes --- pandas/tests/indexes/interval/test_setops.py | 2 +- pandas/tests/indexing/test_floats.py | 92 ++++++++++---------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/pandas/tests/indexes/interval/test_setops.py b/pandas/tests/indexes/interval/test_setops.py index b9eb8b7c41018..d9359d717de1d 100644 --- a/pandas/tests/indexes/interval/test_setops.py +++ b/pandas/tests/indexes/interval/test_setops.py @@ -181,7 +181,7 @@ def test_set_incompatible_types(self, closed, op_name, sort): other = interval_range(Timestamp("20180101"), periods=9, closed=closed) msg = ( f"can only do {op_name} between two IntervalIndex objects that have " - f"compatible dtypes" + "compatible dtypes" ) with pytest.raises(TypeError, match=msg): set_op(other, sort=sort) diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index b91970765005f..6780aed1a350c 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -54,7 +54,7 @@ def test_scalar_error(self, index_func): msg = ( fr"cannot do positional indexing on {type(i).__name__} with these " - fr"indexers \[3\.0\] of type float" + "indexers \[3\.0\] of type float" ) with pytest.raises(TypeError, match=msg): s.iloc[3.0] = 0 @@ -94,11 +94,11 @@ def test_scalar_non_numeric(self, index_func): else: error = TypeError msg = ( - fr"cannot do (label|positional) indexing " + r"cannot do (label|positional) indexing " fr"on {type(i).__name__} with these indexers \[3\.0\] of " - fr"type float|" - fr"Cannot index by location index with a " - fr"non-integer key" + r"type float|" + "Cannot index by location index with a " + "non-integer key" ) with pytest.raises(error, match=msg): idxr(s)[3.0] @@ -115,9 +115,9 @@ def test_scalar_non_numeric(self, index_func): else: error = TypeError msg = ( - fr"cannot do (label|positional) indexing " + r"cannot do (label|positional) indexing " fr"on {type(i).__name__} with these indexers \[3\.0\] of " - fr"type float" + "type float" ) with pytest.raises(error, match=msg): s.loc[3.0] @@ -127,9 +127,9 @@ def test_scalar_non_numeric(self, index_func): # setting with a float fails with iloc msg = ( - fr"cannot do (label|positional) indexing " + r"cannot do (label|positional) indexing " fr"on {type(i).__name__} with these indexers \[3\.0\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): s.iloc[3.0] = 0 @@ -164,9 +164,9 @@ def test_scalar_non_numeric(self, index_func): s = Series(np.arange(len(i)), index=i) s[3] msg = ( - fr"cannot do (label|positional) indexing " + r"cannot do (label|positional) indexing " fr"on {type(i).__name__} with these indexers \[3\.0\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): s[3.0] @@ -181,10 +181,10 @@ def test_scalar_with_mixed(self): for idxr in [lambda x: x, lambda x: x.iloc]: msg = ( - fr"cannot do label indexing " + "cannot do label indexing " fr"on {Index.__name__} with these indexers \[1\.0\] of " - fr"type float|" - fr"Cannot index by location index with a non-integer key" + r"type float|" + "Cannot index by location index with a non-integer key" ) with pytest.raises(TypeError, match=msg): idxr(s2)[1.0] @@ -201,9 +201,9 @@ def test_scalar_with_mixed(self): for idxr in [lambda x: x]: msg = ( - fr"cannot do label indexing " + "cannot do label indexing " fr"on {Index.__name__} with these indexers \[1\.0\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): idxr(s3)[1.0] @@ -319,9 +319,9 @@ def test_scalar_float(self): s.iloc[3.0] msg = ( - fr"cannot do positional indexing " + "cannot do positional indexing " fr"on {Float64Index.__name__} with these indexers \[3\.0\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): s2.iloc[3.0] = 0 @@ -352,9 +352,9 @@ def test_slice_non_numeric(self, index_func): for l in [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]: msg = ( - fr"cannot do positional indexing " + "cannot do positional indexing " fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): s.iloc[l] @@ -362,10 +362,10 @@ def test_slice_non_numeric(self, index_func): for idxr in [lambda x: x.loc, lambda x: x.iloc, lambda x: x]: msg = ( - fr"cannot do (slice|positional) indexing " + "cannot do (slice|positional) indexing " fr"on {type(index).__name__} with these indexers " - fr"\[(3|4)(\.0)?\] " - fr"of type (float|int)" + r"\[(3|4)(\.0)?\] " + r"of type (float|int)" ) with pytest.raises(TypeError, match=msg): idxr(s)[l] @@ -374,19 +374,19 @@ def test_slice_non_numeric(self, index_func): for l in [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]: msg = ( - fr"cannot do positional indexing " + "cannot do positional indexing " fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): s.iloc[l] = 0 for idxr in [lambda x: x.loc, lambda x: x.iloc, lambda x: x]: msg = ( - fr"cannot do (slice|positional) indexing " + "cannot do (slice|positional) indexing " fr"on {type(index).__name__} with these indexers " - fr"\[(3|4)(\.0)?\] " - fr"of type (float|int)" + r"\[(3|4)(\.0)?\] " + r"of type (float|int)" ) with pytest.raises(TypeError, match=msg): idxr(s)[l] = 0 @@ -424,9 +424,9 @@ def test_slice_integer(self): # positional indexing msg = ( - fr"cannot do slice indexing " + "cannot do slice indexing " fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): s[l] @@ -448,9 +448,9 @@ def test_slice_integer(self): # positional indexing msg = ( - fr"cannot do slice indexing " + "cannot do slice indexing " fr"on {type(index).__name__} with these indexers \[-6\.0\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): s[slice(-6.0, 6.0)] @@ -474,9 +474,9 @@ def test_slice_integer(self): # positional indexing msg = ( - fr"cannot do slice indexing " + "cannot do slice indexing " fr"on {type(index).__name__} with these indexers \[(2|3)\.5\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): s[l] @@ -492,9 +492,9 @@ def test_slice_integer(self): # positional indexing msg = ( - fr"cannot do slice indexing " + "cannot do slice indexing " fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): s[l] = 0 @@ -515,9 +515,9 @@ def test_integer_positional_indexing(self): klass = RangeIndex msg = ( - fr"cannot do (slice|positional) indexing " + "cannot do (slice|positional) indexing " fr"on {klass.__name__} with these indexers \[(2|4)\.0\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): idxr(s)[l] @@ -543,9 +543,9 @@ def f(idxr): # positional indexing msg = ( - fr"cannot do slice indexing " + "cannot do slice indexing " fr"on {type(index).__name__} with these indexers \[(0|1)\.0\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): s[l] @@ -558,9 +558,9 @@ def f(idxr): # positional indexing msg = ( - fr"cannot do slice indexing " + "cannot do slice indexing " fr"on {type(index).__name__} with these indexers \[-10\.0\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): s[slice(-10.0, 10.0)] @@ -577,9 +577,9 @@ def f(idxr): # positional indexing msg = ( - fr"cannot do slice indexing " + "cannot do slice indexing " fr"on {type(index).__name__} with these indexers \[0\.5\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): s[l] @@ -594,9 +594,9 @@ def f(idxr): # positional indexing msg = ( - fr"cannot do slice indexing " + "cannot do slice indexing " fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " - fr"type float" + "type float" ) with pytest.raises(TypeError, match=msg): s[l] = 0 From 7d18490313ac85c4e4443f054fb3b82f44f3428e Mon Sep 17 00:00:00 2001 From: Alvaro Santiesteban Date: Thu, 13 Feb 2020 19:36:33 +0000 Subject: [PATCH 3/3] Fix error --- pandas/tests/indexing/test_floats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index 6780aed1a350c..80a4d81b20a13 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -54,7 +54,7 @@ def test_scalar_error(self, index_func): msg = ( fr"cannot do positional indexing on {type(i).__name__} with these " - "indexers \[3\.0\] of type float" + r"indexers \[3\.0\] of type float" ) with pytest.raises(TypeError, match=msg): s.iloc[3.0] = 0