Skip to content

Commit 29140d4

Browse files
authored
STYLE: replace unwanted-patterns-strings-to-concatenate with ruff (#51613)
* STYLE: replace unwanted-patterns-strings-to-concatenate with ruff * STYLE: replace unwanted-patterns-strings-to-concatenate with ruff II
1 parent 5dd6efc commit 29140d4

File tree

16 files changed

+44
-135
lines changed

16 files changed

+44
-135
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,6 @@ repos:
342342
(?x)
343343
^(asv_bench|pandas/tests|doc)/
344344
|scripts/validate_min_versions_in_sync\.py$
345-
- id: unwanted-patterns-strings-to-concatenate
346-
name: Check for use of not concatenated strings
347-
language: python
348-
entry: python scripts/validate_unwanted_patterns.py --validation-type="strings_to_concatenate"
349-
types_or: [python, cython]
350345
- id: unwanted-patterns-strings-with-misplaced-whitespace
351346
name: Check for strings with misplaced spaces
352347
language: python

asv_bench/benchmarks/io/csv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def setup(self, sep, decimal, float_precision):
318318
"".join([random.choice(string.digits) for _ in range(28)])
319319
for _ in range(15)
320320
]
321-
rows = sep.join([f"0{decimal}" + "{}"] * 3) + "\n"
321+
rows = sep.join([f"0{decimal}{{}}"] * 3) + "\n"
322322
data = rows * 5
323323
data = data.format(*floats) * 200 # 1000 x 3 strings csv
324324
self.StringIO_input = StringIO(data)

pandas/io/formats/style.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3658,7 +3658,7 @@ def css(rgba, text_only) -> str:
36583658
text_color = "#f1f1f1" if dark else "#000000"
36593659
return (
36603660
f"background-color: {_matplotlib.colors.rgb2hex(rgba)};"
3661-
+ f"color: {text_color};"
3661+
f"color: {text_color};"
36623662
)
36633663
else:
36643664
return f"color: {_matplotlib.colors.rgb2hex(rgba)};"

pandas/io/sas/sas_constants.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
magic: Final = (
66
b"\x00\x00\x00\x00\x00\x00\x00\x00"
7-
+ b"\x00\x00\x00\x00\xc2\xea\x81\x60"
8-
+ b"\xb3\x14\x11\xcf\xbd\x92\x08\x00"
9-
+ b"\x09\xc7\x31\x8c\x18\x1f\x10\x11"
7+
b"\x00\x00\x00\x00\xc2\xea\x81\x60"
8+
b"\xb3\x14\x11\xcf\xbd\x92\x08\x00"
9+
b"\x09\xc7\x31\x8c\x18\x1f\x10\x11"
1010
)
1111

1212
align_1_checker_value: Final = b"3"

pandas/tests/groupby/test_raises.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -342,25 +342,25 @@ def test_groupby_raises_category(
342342
"cummax": (
343343
(NotImplementedError, TypeError),
344344
"(category type does not support cummax operations|"
345-
+ "category dtype not supported|"
346-
+ "cummax is not supported for category dtype)",
345+
"category dtype not supported|"
346+
"cummax is not supported for category dtype)",
347347
),
348348
"cummin": (
349349
(NotImplementedError, TypeError),
350350
"(category type does not support cummin operations|"
351-
+ "category dtype not supported|"
351+
"category dtype not supported|"
352352
"cummin is not supported for category dtype)",
353353
),
354354
"cumprod": (
355355
(NotImplementedError, TypeError),
356356
"(category type does not support cumprod operations|"
357-
+ "category dtype not supported|"
357+
"category dtype not supported|"
358358
"cumprod is not supported for category dtype)",
359359
),
360360
"cumsum": (
361361
(NotImplementedError, TypeError),
362362
"(category type does not support cumsum operations|"
363-
+ "category dtype not supported|"
363+
"category dtype not supported|"
364364
"cumsum is not supported for category dtype)",
365365
),
366366
"diff": (
@@ -371,7 +371,7 @@ def test_groupby_raises_category(
371371
"fillna": (
372372
TypeError,
373373
r"Cannot setitem on a Categorical with a new category \(0\), "
374-
+ "set the categories first",
374+
"set the categories first",
375375
)
376376
if not using_copy_on_write
377377
else (None, ""), # no-op with CoW
@@ -539,33 +539,33 @@ def test_groupby_raises_category_on_category(
539539
"cummax": (
540540
(NotImplementedError, TypeError),
541541
"(cummax is not supported for category dtype|"
542-
+ "category dtype not supported|"
543-
+ "category type does not support cummax operations)",
542+
"category dtype not supported|"
543+
"category type does not support cummax operations)",
544544
),
545545
"cummin": (
546546
(NotImplementedError, TypeError),
547547
"(cummin is not supported for category dtype|"
548-
+ "category dtype not supported|"
548+
"category dtype not supported|"
549549
"category type does not support cummin operations)",
550550
),
551551
"cumprod": (
552552
(NotImplementedError, TypeError),
553553
"(cumprod is not supported for category dtype|"
554-
+ "category dtype not supported|"
554+
"category dtype not supported|"
555555
"category type does not support cumprod operations)",
556556
),
557557
"cumsum": (
558558
(NotImplementedError, TypeError),
559559
"(cumsum is not supported for category dtype|"
560-
+ "category dtype not supported|"
561-
+ "category type does not support cumsum operations)",
560+
"category dtype not supported|"
561+
"category type does not support cumsum operations)",
562562
),
563563
"diff": (TypeError, "unsupported operand type"),
564564
"ffill": (None, ""),
565565
"fillna": (
566566
TypeError,
567567
r"Cannot setitem on a Categorical with a new category \(0\), "
568-
+ "set the categories first",
568+
"set the categories first",
569569
)
570570
if not using_copy_on_write
571571
else (None, ""), # no-op with CoW

pandas/tests/io/excel/test_readers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ def test_index_col_with_unnamed(self, read_ext, index_col):
341341
def test_usecols_pass_non_existent_column(self, read_ext):
342342
msg = (
343343
"Usecols do not match columns, "
344-
"columns expected but not found: " + r"\['E'\]"
344+
"columns expected but not found: "
345+
r"\['E'\]"
345346
)
346347

347348
with pytest.raises(ValueError, match=msg):

pandas/tests/io/formats/test_css.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def test_css_border_shorthands(prop, expected):
193193
"margin: 1px; margin-top: 2px",
194194
"",
195195
"margin-left: 1px; margin-right: 1px; "
196-
+ "margin-bottom: 1px; margin-top: 2px",
196+
"margin-bottom: 1px; margin-top: 2px",
197197
),
198198
("margin-top: 2px", "margin: 1px", "margin: 1px; margin-top: 2px"),
199199
("margin: 1px", "margin-top: 2px", "margin: 1px"),

pandas/tests/io/formats/test_format.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,18 +2160,18 @@ def test_freq_name_separation(self):
21602160
def test_to_string_mixed(self):
21612161
s = Series(["foo", np.nan, -1.23, 4.56])
21622162
result = s.to_string()
2163-
expected = "0 foo\n" + "1 NaN\n" + "2 -1.23\n" + "3 4.56"
2163+
expected = "".join(["0 foo\n", "1 NaN\n", "2 -1.23\n", "3 4.56"])
21642164
assert result == expected
21652165

21662166
# but don't count NAs as floats
21672167
s = Series(["foo", np.nan, "bar", "baz"])
21682168
result = s.to_string()
2169-
expected = "0 foo\n" + "1 NaN\n" + "2 bar\n" + "3 baz"
2169+
expected = "".join(["0 foo\n", "1 NaN\n", "2 bar\n", "3 baz"])
21702170
assert result == expected
21712171

21722172
s = Series(["foo", 5, "bar", "baz"])
21732173
result = s.to_string()
2174-
expected = "0 foo\n" + "1 5\n" + "2 bar\n" + "3 baz"
2174+
expected = "".join(["0 foo\n", "1 5\n", "2 bar\n", "3 baz"])
21752175
assert result == expected
21762176

21772177
def test_to_string_float_na_spacing(self):
@@ -2181,18 +2181,18 @@ def test_to_string_float_na_spacing(self):
21812181
result = s.to_string()
21822182
expected = (
21832183
"0 NaN\n"
2184-
+ "1 1.5678\n"
2185-
+ "2 NaN\n"
2186-
+ "3 -3.0000\n"
2187-
+ "4 NaN"
2184+
"1 1.5678\n"
2185+
"2 NaN\n"
2186+
"3 -3.0000\n"
2187+
"4 NaN"
21882188
)
21892189
assert result == expected
21902190

21912191
def test_to_string_without_index(self):
21922192
# GH 11729 Test index=False option
21932193
s = Series([1, 2, 3, 4])
21942194
result = s.to_string(index=False)
2195-
expected = "1\n" + "2\n" + "3\n" + "4"
2195+
expected = "\n".join(["1", "2", "3", "4"])
21962196
assert result == expected
21972197

21982198
def test_unicode_name_in_footer(self):
@@ -2823,7 +2823,9 @@ def dtype(self):
28232823

28242824
series = Series(ExtTypeStub())
28252825
res = repr(series) # This line crashed before #33770 was fixed.
2826-
expected = "0 [False True]\n" + "1 [ True False]\n" + "dtype: DtypeStub"
2826+
expected = "\n".join(
2827+
["0 [False True]", "1 [ True False]", "dtype: DtypeStub"]
2828+
)
28272829
assert res == expected
28282830

28292831

pandas/tests/io/json/test_normalize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def test_record_prefix(self, state_data):
397397
def test_non_ascii_key(self):
398398
testjson = (
399399
b'[{"\xc3\x9cnic\xc3\xb8de":0,"sub":{"A":1, "B":2}},'
400-
+ b'{"\xc3\x9cnic\xc3\xb8de":1,"sub":{"A":3, "B":4}}]'
400+
b'{"\xc3\x9cnic\xc3\xb8de":1,"sub":{"A":3, "B":4}}]'
401401
).decode("utf8")
402402

403403
testdata = {

pandas/tests/io/parser/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def all_parsers_all_precisions(request):
189189
_encoding_prefixes = ["utf", "UTF"]
190190

191191
_encoding_fmts = [
192-
f"{prefix}{sep}" + "{0}" for sep in _encoding_seps for prefix in _encoding_prefixes
192+
f"{prefix}{sep}{{0}}" for sep in _encoding_seps for prefix in _encoding_prefixes
193193
]
194194

195195

0 commit comments

Comments
 (0)