Skip to content

Commit 4357621

Browse files
authored
STY: Enable ruff ambiguous unicode character (#54330)
1 parent e8961f1 commit 4357621

File tree

25 files changed

+49
-46
lines changed

25 files changed

+49
-46
lines changed

pandas/core/frame.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7131,7 +7131,7 @@ def value_counts(
71317131
ascending : bool, default False
71327132
Sort in ascending order.
71337133
dropna : bool, default True
7134-
Dont include counts of rows that contain NA values.
7134+
Don't include counts of rows that contain NA values.
71357135
71367136
.. versionadded:: 1.3.0
71377137
@@ -9968,7 +9968,7 @@ def map(
99689968
func : callable
99699969
Python function, returns a single value from a single value.
99709970
na_action : {None, 'ignore'}, default None
9971-
If ignore, propagate NaN values, without passing them to func.
9971+
If 'ignore', propagate NaN values, without passing them to func.
99729972
**kwargs
99739973
Additional keyword arguments to pass as keywords arguments to
99749974
`func`.
@@ -10054,7 +10054,7 @@ def applymap(
1005410054
func : callable
1005510055
Python function, returns a single value from a single value.
1005610056
na_action : {None, 'ignore'}, default None
10057-
If ignore, propagate NaN values, without passing them to func.
10057+
If 'ignore', propagate NaN values, without passing them to func.
1005810058
**kwargs
1005910059
Additional keyword arguments to pass as keywords arguments to
1006010060
`func`.

pandas/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5633,7 +5633,7 @@ def filter(
56335633
Keep labels from axis for which "like in label == True".
56345634
regex : str (regular expression)
56355635
Keep labels from axis for which re.search(regex, label) == True.
5636-
axis : {0 or index, 1 or columns, None}, default None
5636+
axis : {0 or 'index', 1 or 'columns', None}, default None
56375637
The axis to filter on, expressed either as an index (int)
56385638
or axis name (str). By default this is the info axis, 'columns' for
56395639
DataFrame. For `Series` this parameter is unused and defaults to `None`.
@@ -5922,7 +5922,7 @@ def sample(
59225922
59235923
np.random.Generator objects now accepted
59245924
5925-
axis : {0 or index, 1 or columns, None}, default None
5925+
axis : {0 or 'index', 1 or 'columns', None}, default None
59265926
Axis to sample. Accepts axis number or name. Default is stat axis
59275927
for given data type. For `Series` this parameter is unused and defaults to `None`.
59285928
ignore_index : bool, default False

pandas/core/groupby/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,7 @@ def value_counts(
23222322
ascending : bool, default False
23232323
Sort in ascending order.
23242324
dropna : bool, default True
2325-
Dont include counts of rows that contain NA values.
2325+
Don't include counts of rows that contain NA values.
23262326
23272327
Returns
23282328
-------

pandas/core/indexes/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class DatetimeIndex(DatetimeTimedeltaMixin):
177177
yearfirst : bool, default False
178178
If True parse dates in `data` with the year first order.
179179
dtype : numpy.dtype or DatetimeTZDtype or str, default None
180-
Note that the only NumPy dtype allowed is datetime64[ns].
180+
Note that the only NumPy dtype allowed is `datetime64[ns]`.
181181
copy : bool, default False
182182
Make a copy of input ndarray.
183183
name : label, default None

pandas/core/reshape/merge.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,7 @@ def _factorize_keys(
23362336
sort : bool, defaults to True
23372337
If True, the encoding is done such that the unique elements in the
23382338
keys are sorted.
2339-
how : {left’, ‘right’, ‘outer’, ‘inner}, default inner
2339+
how : {'left', 'right', 'outer', 'inner'}, default 'inner'
23402340
Type of merge.
23412341
23422342
Returns

pandas/core/tools/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ def to_datetime(
916916
- **DataFrame/dict-like** are converted to :class:`Series` with
917917
:class:`datetime64` dtype. For each row a datetime is created from assembling
918918
the various dataframe columns. Column keys can be common abbreviations
919-
like [year’, ‘month’, ‘day’, ‘minute’, ‘second’, ‘ms’, ‘us’, ‘ns’]) or
919+
like ['year', 'month', 'day', 'minute', 'second', 'ms', 'us', 'ns']) or
920920
plurals of the same.
921921
922922
The following causes are responsible for :class:`datetime.datetime` objects

pandas/io/excel/_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1268,14 +1268,14 @@ def __init__(
12681268
@property
12691269
def date_format(self) -> str:
12701270
"""
1271-
Format string for dates written into Excel files (e.g. YYYY-MM-DD).
1271+
Format string for dates written into Excel files (e.g. 'YYYY-MM-DD').
12721272
"""
12731273
return self._date_format
12741274

12751275
@property
12761276
def datetime_format(self) -> str:
12771277
"""
1278-
Format string for dates written into Excel files (e.g. YYYY-MM-DD).
1278+
Format string for dates written into Excel files (e.g. 'YYYY-MM-DD').
12791279
"""
12801280
return self._datetime_format
12811281

pandas/io/formats/html.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def render(self) -> list[str]:
9494
self._write_table()
9595

9696
if self.should_show_dimensions:
97-
by = chr(215) # ×
97+
by = chr(215) # × # noqa: RUF003
9898
self.write(
9999
f"<p>{len(self.frame)} rows {by} {len(self.frame.columns)} columns</p>"
100100
)

pandas/io/formats/style.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3489,7 +3489,7 @@ def highlight_quantile(
34893489
Left bound, in [0, q_right), for the target quantile range.
34903490
q_right : float, default 1
34913491
Right bound, in (q_left, 1], for the target quantile range.
3492-
interpolation : {linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest}
3492+
interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
34933493
Argument passed to ``Series.quantile`` or ``DataFrame.quantile`` for
34943494
quantile estimation.
34953495
inclusive : {'both', 'neither', 'left', 'right'}

pandas/io/sql.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def read_sql_query(
441441
rows to include in each chunk.
442442
dtype : Type name or dict of columns
443443
Data type for data or columns. E.g. np.float64 or
444-
{‘a’: np.float64, ‘b’: np.int32, ‘c’: ‘Int64}.
444+
{'a': np.float64, 'b': np.int32, 'c': 'Int64'}.
445445
446446
.. versionadded:: 1.3.0
447447
dtype_backend : {'numpy_nullable', 'pyarrow'}, default 'numpy_nullable'
@@ -597,7 +597,7 @@ def read_sql(
597597
.. versionadded:: 2.0
598598
dtype : Type name or dict of columns
599599
Data type for data or columns. E.g. np.float64 or
600-
{‘a’: np.float64, ‘b’: np.int32, ‘c’: ‘Int64}.
600+
{'a': np.float64, 'b': np.int32, 'c': 'Int64'}.
601601
The argument is ignored if a table is passed instead of a query.
602602
603603
.. versionadded:: 2.0.0
@@ -1759,7 +1759,7 @@ def read_query(
17591759
of rows to include in each chunk.
17601760
dtype : Type name or dict of columns
17611761
Data type for data or columns. E.g. np.float64 or
1762-
{‘a’: np.float64, ‘b’: np.int32, ‘c’: ‘Int64}
1762+
{'a': np.float64, 'b': np.int32, 'c': 'Int64'}
17631763
17641764
.. versionadded:: 1.3.0
17651765

pandas/io/stata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3768,7 +3768,7 @@ def _validate_variable_name(self, name: str) -> str:
37683768
and c != "_"
37693769
)
37703770
or 128 <= ord(c) < 192
3771-
or c in {"×", "÷"}
3771+
or c in {"×", "÷"} # noqa: RUF001
37723772
):
37733773
name = name.replace(c, "_")
37743774

pandas/tests/extension/test_arrow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,7 @@ def test_str_slice_replace(start, stop, repl, exp):
20612061
["!|,", "isalnum", False],
20622062
["aaa", "isalpha", True],
20632063
["!!!", "isalpha", False],
2064-
["٠", "isdecimal", True],
2064+
["٠", "isdecimal", True], # noqa: RUF001
20652065
["~!", "isdecimal", False],
20662066
["2", "isdigit", True],
20672067
["~", "isdigit", False],

pandas/tests/frame/methods/test_to_csv.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,10 @@ def test_to_csv_path_is_none(self, float_frame):
957957
(DataFrame([["abc", "def", "ghi"]], columns=["X", "Y", "Z"]), "ascii"),
958958
(DataFrame(5 * [[123, "你好", "世界"]], columns=["X", "Y", "Z"]), "gb2312"),
959959
(
960-
DataFrame(5 * [[123, "Γειά σου", "Κόσμε"]], columns=["X", "Y", "Z"]),
960+
DataFrame(
961+
5 * [[123, "Γειά σου", "Κόσμε"]], # noqa: RUF001
962+
columns=["X", "Y", "Z"],
963+
),
961964
"cp737",
962965
),
963966
],

pandas/tests/groupby/test_groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ def test_groupby_dtype_inference_empty():
14021402

14031403

14041404
def test_groupby_unit64_float_conversion():
1405-
#  GH: 30859 groupby converts unit64 to floats sometimes
1405+
# GH: 30859 groupby converts unit64 to floats sometimes
14061406
df = DataFrame({"first": [1], "second": [1], "value": [16148277970000000000]})
14071407
result = df.groupby(["first", "second"])["value"].max()
14081408
expected = Series(

pandas/tests/io/json/test_json_table_schema.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def test_read_json_from_to_json_results(self):
251251
"recommender_id": {"row_0": 3},
252252
"recommender_name_jp": {"row_0": "浦田"},
253253
"recommender_name_en": {"row_0": "Urata"},
254-
"name_jp": {"row_0": "博多人形松尾吉将まつお よしまさ"},
254+
"name_jp": {"row_0": "博多人形(松尾吉将まつお よしまさ)"},
255255
"name_en": {"row_0": "Hakata Dolls Matsuo"},
256256
}
257257
)

pandas/tests/io/parser/test_encoding.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,12 @@ def test_encoding_named_temp_file(all_parsers):
223223
def test_parse_encoded_special_characters(encoding):
224224
# GH16218 Verify parsing of data with encoded special characters
225225
# Data contains a Unicode 'FULLWIDTH COLON' (U+FF1A) at position (0,"a")
226-
data = "a\tb\n:foo\t0\nbar\t1\nbaz\t2"
226+
data = "a\tb\n:foo\t0\nbar\t1\nbaz\t2" # noqa: RUF001
227227
encoded_data = BytesIO(data.encode(encoding))
228228
result = read_csv(encoded_data, delimiter="\t", encoding=encoding)
229229

230230
expected = DataFrame(
231-
data=[[":foo", 0], ["bar", 1], ["baz", 2]],
231+
data=[[":foo", 0], ["bar", 1], ["baz", 2]], # noqa: RUF001
232232
columns=["a", "b"],
233233
)
234234
tm.assert_frame_equal(result, expected)

pandas/tests/io/parser/test_read_fwf.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ def test_read_csv_compat():
190190

191191

192192
def test_bytes_io_input():
193-
result = read_fwf(BytesIO("שלום\nשלום".encode()), widths=[2, 2], encoding="utf8")
193+
data = BytesIO("שלום\nשלום".encode()) # noqa: RUF001
194+
result = read_fwf(data, widths=[2, 2], encoding="utf8")
194195
expected = DataFrame([["של", "ום"]], columns=["של", "ום"])
195196
tm.assert_frame_equal(result, expected)
196197

pandas/tests/io/test_clipboard.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ def df(request):
6262
data_type = request.param
6363

6464
if data_type == "delims":
65-
return DataFrame({"a": ['"a,\t"b|c', "d\tef´"], "b": ["hi'j", "k''lm"]})
65+
return DataFrame({"a": ['"a,\t"b|c', "d\tef`"], "b": ["hi'j", "k''lm"]})
6666
elif data_type == "utf8":
67-
return DataFrame({"a": ["µasd", "Ωœ∑´"], "b": ["øπ∆˚¬", "œ∑´®"]})
67+
return DataFrame({"a": ["µasd", "Ωœ∑`"], "b": ["øπ∆˚¬", "œ∑`®"]})
6868
elif data_type == "utf16":
6969
return DataFrame(
7070
{"a": ["\U0001f44d\U0001f44d", "\U0001f44d\U0001f44d"], "b": ["abc", "def"]}
@@ -402,7 +402,7 @@ def test_round_trip_valid_encodings(self, enc, df):
402402
self.check_round_trip_frame(df, encoding=enc)
403403

404404
@pytest.mark.single_cpu
405-
@pytest.mark.parametrize("data", ["\U0001f44d...", "Ωœ∑´...", "abcd..."])
405+
@pytest.mark.parametrize("data", ["\U0001f44d...", "Ωœ∑`...", "abcd..."])
406406
@pytest.mark.xfail(
407407
(os.environ.get("DISPLAY") is None and not is_platform_mac())
408408
or is_ci_environment(),

pandas/tests/io/test_stata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def test_read_dta18(self, datapath):
286286
["Cat", "Bogota", "Bogotá", 1, 1.0, "option b Ünicode", 1.0],
287287
["Dog", "Boston", "Uzunköprü", np.nan, np.nan, np.nan, np.nan],
288288
["Plane", "Rome", "Tromsø", 0, 0.0, "option a", 0.0],
289-
["Potato", "Tokyo", "Elâzığ", -4, 4.0, 4, 4],
289+
["Potato", "Tokyo", "Elâzığ", -4, 4.0, 4, 4], # noqa: RUF001
290290
["", "", "", 0, 0.3332999, "option a", 1 / 3.0],
291291
],
292292
columns=[

pandas/tests/series/methods/test_to_csv.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ def test_to_csv_path_is_none(self):
122122
# GH 21241, 21118
123123
(Series(["abc", "def", "ghi"], name="X"), "ascii"),
124124
(Series(["123", "你好", "世界"], name="中文"), "gb2312"),
125-
(Series(["123", "Γειά σου", "Κόσμε"], name="Ελληνικά"), "cp737"),
125+
(
126+
Series(["123", "Γειά σου", "Κόσμε"], name="Ελληνικά"), # noqa: RUF001
127+
"cp737",
128+
),
126129
],
127130
)
128131
def test_to_csv_compression(self, s, encoding, compression):

pandas/tests/strings/test_strings.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,10 @@ def test_isnumeric_unicode(method, expected, any_string_dtype):
226226
# 0x00bc: ¼ VULGAR FRACTION ONE QUARTER
227227
# 0x2605: ★ not number
228228
# 0x1378: ፸ ETHIOPIC NUMBER SEVENTY
229-
# 0xFF13: 3 Em 3
230-
ser = Series(["A", "3", "¼", "★", "፸", "3", "four"], dtype=any_string_dtype)
229+
# 0xFF13: 3 Em 3 # noqa: RUF003
230+
ser = Series(
231+
["A", "3", "¼", "★", "፸", "3", "four"], dtype=any_string_dtype # noqa: RUF001
232+
)
231233
expected_dtype = "bool" if any_string_dtype == "object" else "boolean"
232234
expected = Series(expected, dtype=expected_dtype)
233235
result = getattr(ser.str, method)()
@@ -246,7 +248,7 @@ def test_isnumeric_unicode(method, expected, any_string_dtype):
246248
],
247249
)
248250
def test_isnumeric_unicode_missing(method, expected, any_string_dtype):
249-
values = ["A", np.nan, "¼", "★", np.nan, "3", "four"]
251+
values = ["A", np.nan, "¼", "★", np.nan, "3", "four"] # noqa: RUF001
250252
ser = Series(values, dtype=any_string_dtype)
251253
expected_dtype = "object" if any_string_dtype == "object" else "boolean"
252254
expected = Series(expected, dtype=expected_dtype)
@@ -564,12 +566,12 @@ def test_decode_errors_kwarg():
564566
"form, expected",
565567
[
566568
("NFKC", ["ABC", "ABC", "123", np.nan, "アイエ"]),
567-
("NFC", ["ABC", "ABC", "123", np.nan, "アイエ"]),
569+
("NFC", ["ABC", "ABC", "123", np.nan, "アイエ"]), # noqa: RUF001
568570
],
569571
)
570572
def test_normalize(form, expected, any_string_dtype):
571573
ser = Series(
572-
["ABC", "ABC", "123", np.nan, "アイエ"],
574+
["ABC", "ABC", "123", np.nan, "アイエ"], # noqa: RUF001
573575
index=["a", "b", "c", "d", "e"],
574576
dtype=any_string_dtype,
575577
)
@@ -580,7 +582,7 @@ def test_normalize(form, expected, any_string_dtype):
580582

581583
def test_normalize_bad_arg_raises(any_string_dtype):
582584
ser = Series(
583-
["ABC", "ABC", "123", np.nan, "アイエ"],
585+
["ABC", "ABC", "123", np.nan, "アイエ"], # noqa: RUF001
584586
index=["a", "b", "c", "d", "e"],
585587
dtype=any_string_dtype,
586588
)
@@ -589,7 +591,7 @@ def test_normalize_bad_arg_raises(any_string_dtype):
589591

590592

591593
def test_normalize_index():
592-
idx = Index(["ABC", "123", "アイエ"])
594+
idx = Index(["ABC", "123", "アイエ"]) # noqa: RUF001
593595
expected = Index(["ABC", "123", "アイエ"])
594596
result = idx.str.normalize("NFKC")
595597
tm.assert_index_equal(result, expected)

pandas/tseries/holiday.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ def merge(self, other, inplace: bool = False):
570570
offset=DateOffset(weekday=MO(3)),
571571
)
572572
USPresidentsDay = Holiday(
573-
"Washingtons Birthday", month=2, day=1, offset=DateOffset(weekday=MO(3))
573+
"Washington's Birthday", month=2, day=1, offset=DateOffset(weekday=MO(3))
574574
)
575575
GoodFriday = Holiday("Good Friday", month=1, day=1, offset=[Easter(), Day(-2)])
576576

pyproject.toml

-6
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,6 @@ ignore = [
326326
"PLR0124",
327327
# Consider `elif` instead of `else` then `if` to remove indentation level
328328
"PLR5501",
329-
# ambiguous-unicode-character-string
330-
"RUF001",
331-
# ambiguous-unicode-character-docstring
332-
"RUF002",
333-
# ambiguous-unicode-character-comment
334-
"RUF003",
335329
# collection-literal-concatenation
336330
"RUF005",
337331
# pairwise-over-zipped (>=PY310 only)

web/pandas/about/governance.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ In particular, the Core Team may:
128128
and merging pull requests.
129129
- Make decisions about the Services that are run by The Project and manage
130130
those Services for the benefit of the Project and Community.
131-
- Make decisions when regular community discussion doesnt produce consensus
131+
- Make decisions when regular community discussion doesn't produce consensus
132132
on an issue in a reasonable time frame.
133133

134134
### Core Team membership
@@ -157,7 +157,7 @@ they will be considered for removal from the Core Team. Before removal,
157157
inactive Member will be approached by the BDFL to see if they plan on returning
158158
to active participation. If not they will be removed immediately upon a Core
159159
Team vote. If they plan on returning to active participation soon, they will be
160-
given a grace period of one year. If they dont return to active participation
160+
given a grace period of one year. If they don't return to active participation
161161
within that time period they will be removed by vote of the Core Team without
162162
further grace period. All former Core Team members can be considered for
163163
membership again at any time in the future, like any other Project Contributor.

web/pandas/community/coc.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Examples of unacceptable behavior by participants include:
2121
* Other unethical or unprofessional conduct
2222

2323
Furthermore, we encourage inclusive behavior - for example,
24-
please dont say “hey guys!” but “hey everyone!”.
24+
please don't say “hey guys!” but “hey everyone!”.
2525

2626
Project maintainers have the right and responsibility to remove, edit, or
2727
reject comments, commits, code, wiki edits, issues, and other contributions

0 commit comments

Comments
 (0)