Skip to content

Commit a7ac7d6

Browse files
authored
48855 style fix pylint issues pointless string statement (pandas-dev#49880)
* feat: Adding pylint check pointless-string-statement Fixing issues for pointless-string-statement so that we can add the PyLint check to the project * fix: Addressing a PR comment * fix: resolving PR comments
1 parent c77aad2 commit a7ac7d6

File tree

11 files changed

+116
-124
lines changed

11 files changed

+116
-124
lines changed

pandas/core/indexes/base.py

+10-15
Original file line numberDiff line numberDiff line change
@@ -587,20 +587,18 @@ def _dtype_to_subclass(cls, dtype: DtypeObj):
587587

588588
raise NotImplementedError(dtype)
589589

590-
"""
591-
NOTE for new Index creation:
590+
# NOTE for new Index creation:
592591

593-
- _simple_new: It returns new Index with the same type as the caller.
594-
All metadata (such as name) must be provided by caller's responsibility.
595-
Using _shallow_copy is recommended because it fills these metadata
596-
otherwise specified.
592+
# - _simple_new: It returns new Index with the same type as the caller.
593+
# All metadata (such as name) must be provided by caller's responsibility.
594+
# Using _shallow_copy is recommended because it fills these metadata
595+
# otherwise specified.
597596

598-
- _shallow_copy: It returns new Index with the same type (using
599-
_simple_new), but fills caller's metadata otherwise specified. Passed
600-
kwargs will overwrite corresponding metadata.
597+
# - _shallow_copy: It returns new Index with the same type (using
598+
# _simple_new), but fills caller's metadata otherwise specified. Passed
599+
# kwargs will overwrite corresponding metadata.
601600

602-
See each method's docstring.
603-
"""
601+
# See each method's docstring.
604602

605603
@classmethod
606604
def _simple_new(cls: type[_IndexT], values, name: Hashable = None) -> _IndexT:
@@ -3963,10 +3961,7 @@ def is_int(v):
39633961
is_positional = is_index_slice and ints_are_positional
39643962

39653963
if kind == "getitem":
3966-
"""
3967-
called from the getitem slicers, validate that we are in fact
3968-
integers
3969-
"""
3964+
# called from the getitem slicers, validate that we are in fact integers
39703965
if self.is_integer():
39713966
if is_frame:
39723967
# unambiguously positional, no deprecation

pandas/plotting/_matplotlib/core.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -839,12 +839,10 @@ def _get_xticks(self, convert_period: bool = False):
839839
self.data = self.data.reindex(index=index.sort_values())
840840
x = self.data.index.to_timestamp()._mpl_repr()
841841
elif index.is_numeric():
842-
"""
843-
Matplotlib supports numeric values or datetime objects as
844-
xaxis values. Taking LBYL approach here, by the time
845-
matplotlib raises exception when using non numeric/datetime
846-
values for xaxis, several actions are already taken by plt.
847-
"""
842+
# Matplotlib supports numeric values or datetime objects as
843+
# xaxis values. Taking LBYL approach here, by the time
844+
# matplotlib raises exception when using non numeric/datetime
845+
# values for xaxis, several actions are already taken by plt.
848846
x = index._mpl_repr()
849847
elif is_datetype:
850848
self.data = self.data[notna(self.data.index)]

pandas/tests/frame/methods/test_reset_index.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,10 @@ def test_reset_index_duplicate_columns_allow(
452452
tm.assert_frame_equal(result, expected)
453453
else:
454454
if not flag and allow_duplicates:
455-
msg = "Cannot specify 'allow_duplicates=True' when "
456-
"'self.flags.allows_duplicate_labels' is False"
455+
msg = (
456+
"Cannot specify 'allow_duplicates=True' when "
457+
"'self.flags.allows_duplicate_labels' is False"
458+
)
457459
else:
458460
msg = r"cannot insert \('A', ''\), already exists"
459461
with pytest.raises(ValueError, match=msg):

pandas/tests/indexes/multi/test_analytics.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
def test_shift(idx):
1616

1717
# GH8083 test the base class for shift
18-
msg = "This method is only implemented for DatetimeIndex, PeriodIndex and "
19-
"TimedeltaIndex; Got type MultiIndex"
18+
msg = (
19+
"This method is only implemented for DatetimeIndex, PeriodIndex and "
20+
"TimedeltaIndex; Got type MultiIndex"
21+
)
2022
with pytest.raises(NotImplementedError, match=msg):
2123
idx.shift(1)
2224
with pytest.raises(NotImplementedError, match=msg):

pandas/tests/indexing/interval/test_interval_new.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ def test_loc_with_overlap(self, indexer_sl):
162162
result = indexer_sl(ser)[Interval(1, 5) : Interval(3, 7)]
163163
tm.assert_series_equal(expected, result)
164164

165-
msg = "'can only get slices from an IntervalIndex if bounds are"
166-
" non-overlapping and all monotonic increasing or decreasing'"
165+
msg = (
166+
"'can only get slices from an IntervalIndex if bounds are "
167+
"non-overlapping and all monotonic increasing or decreasing'"
168+
)
167169
with pytest.raises(KeyError, match=msg):
168170
indexer_sl(ser)[Interval(1, 6) : Interval(3, 8)]
169171

pandas/tests/io/parser/common/test_read_errors.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,10 @@ def test_bad_header_uniform_error(all_parsers):
241241
data = "+++123456789...\ncol1,col2,col3,col4\n1,2,3,4\n"
242242
msg = "Expected 2 fields in line 2, saw 4"
243243
if parser.engine == "c":
244-
msg = "Could not construct index. Requested to use 1 "
245-
"number of columns, but 3 left to parse."
244+
msg = (
245+
"Could not construct index. Requested to use 1 "
246+
"number of columns, but 3 left to parse."
247+
)
246248

247249
with pytest.raises(ParserError, match=msg):
248250
parser.read_csv(StringIO(data), index_col=0, on_bad_lines="error")

pandas/tests/io/xml/test_to_xml.py

+33-35
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,39 @@
2222
from pandas.io.common import get_handle
2323
from pandas.io.xml import read_xml
2424

25-
"""
26-
CHECKLIST
27-
28-
[x] - ValueError: "Values for parser can only be lxml or etree."
29-
30-
etree
31-
[x] - ImportError: "lxml not found, please install or use the etree parser."
32-
[X] - TypeError: "...is not a valid type for attr_cols"
33-
[X] - TypeError: "...is not a valid type for elem_cols"
34-
[X] - LookupError: "unknown encoding"
35-
[X] - KeyError: "...is not included in namespaces"
36-
[X] - KeyError: "no valid column"
37-
[X] - ValueError: "To use stylesheet, you need lxml installed..."
38-
[] - OSError: (NEED PERMISSOIN ISSUE, DISK FULL, ETC.)
39-
[X] - FileNotFoundError: "No such file or directory"
40-
[X] - PermissionError: "Forbidden"
41-
42-
lxml
43-
[X] - TypeError: "...is not a valid type for attr_cols"
44-
[X] - TypeError: "...is not a valid type for elem_cols"
45-
[X] - LookupError: "unknown encoding"
46-
[] - OSError: (NEED PERMISSOIN ISSUE, DISK FULL, ETC.)
47-
[X] - FileNotFoundError: "No such file or directory"
48-
[X] - KeyError: "...is not included in namespaces"
49-
[X] - KeyError: "no valid column"
50-
[X] - ValueError: "stylesheet is not a url, file, or xml string."
51-
[] - LookupError: (NEED WRONG ENCODING FOR FILE OUTPUT)
52-
[] - URLError: (USUALLY DUE TO NETWORKING)
53-
[] - HTTPError: (NEED AN ONLINE STYLESHEET)
54-
[X] - OSError: "failed to load external entity"
55-
[X] - XMLSyntaxError: "Opening and ending tag mismatch"
56-
[X] - XSLTApplyError: "Cannot resolve URI"
57-
[X] - XSLTParseError: "failed to compile"
58-
[X] - PermissionError: "Forbidden"
59-
"""
25+
# CHECKLIST
26+
27+
# [x] - ValueError: "Values for parser can only be lxml or etree."
28+
29+
# etree
30+
# [x] - ImportError: "lxml not found, please install or use the etree parser."
31+
# [X] - TypeError: "...is not a valid type for attr_cols"
32+
# [X] - TypeError: "...is not a valid type for elem_cols"
33+
# [X] - LookupError: "unknown encoding"
34+
# [X] - KeyError: "...is not included in namespaces"
35+
# [X] - KeyError: "no valid column"
36+
# [X] - ValueError: "To use stylesheet, you need lxml installed..."
37+
# [] - OSError: (NEED PERMISSOIN ISSUE, DISK FULL, ETC.)
38+
# [X] - FileNotFoundError: "No such file or directory"
39+
# [X] - PermissionError: "Forbidden"
40+
41+
# lxml
42+
# [X] - TypeError: "...is not a valid type for attr_cols"
43+
# [X] - TypeError: "...is not a valid type for elem_cols"
44+
# [X] - LookupError: "unknown encoding"
45+
# [] - OSError: (NEED PERMISSOIN ISSUE, DISK FULL, ETC.)
46+
# [X] - FileNotFoundError: "No such file or directory"
47+
# [X] - KeyError: "...is not included in namespaces"
48+
# [X] - KeyError: "no valid column"
49+
# [X] - ValueError: "stylesheet is not a url, file, or xml string."
50+
# [] - LookupError: (NEED WRONG ENCODING FOR FILE OUTPUT)
51+
# [] - URLError: (USUALLY DUE TO NETWORKING)
52+
# [] - HTTPError: (NEED AN ONLINE STYLESHEET)
53+
# [X] - OSError: "failed to load external entity"
54+
# [X] - XMLSyntaxError: "Opening and ending tag mismatch"
55+
# [X] - XSLTApplyError: "Cannot resolve URI"
56+
# [X] - XSLTParseError: "failed to compile"
57+
# [X] - PermissionError: "Forbidden"
6058

6159
geom_df = DataFrame(
6260
{

pandas/tests/io/xml/test_xml.py

+51-53
Original file line numberDiff line numberDiff line change
@@ -27,59 +27,57 @@
2727
from pandas.io.common import get_handle
2828
from pandas.io.xml import read_xml
2929

30-
"""
31-
CHECK LIST
32-
33-
[x] - ValueError: "Values for parser can only be lxml or etree."
34-
35-
etree
36-
[X] - ImportError: "lxml not found, please install or use the etree parser."
37-
[X] - TypeError: "expected str, bytes or os.PathLike object, not NoneType"
38-
[X] - ValueError: "Either element or attributes can be parsed not both."
39-
[X] - ValueError: "xpath does not return any nodes..."
40-
[X] - SyntaxError: "You have used an incorrect or unsupported XPath"
41-
[X] - ValueError: "names does not match length of child elements in xpath."
42-
[X] - TypeError: "...is not a valid type for names"
43-
[X] - ValueError: "To use stylesheet, you need lxml installed..."
44-
[] - URLError: (GENERAL ERROR WITH HTTPError AS SUBCLASS)
45-
[X] - HTTPError: "HTTP Error 404: Not Found"
46-
[] - OSError: (GENERAL ERROR WITH FileNotFoundError AS SUBCLASS)
47-
[X] - FileNotFoundError: "No such file or directory"
48-
[] - ParseError (FAILSAFE CATCH ALL FOR VERY COMPLEX XML)
49-
[X] - UnicodeDecodeError: "'utf-8' codec can't decode byte 0xe9..."
50-
[X] - UnicodeError: "UTF-16 stream does not start with BOM"
51-
[X] - BadZipFile: "File is not a zip file"
52-
[X] - OSError: "Invalid data stream"
53-
[X] - LZMAError: "Input format not supported by decoder"
54-
[X] - ValueError: "Unrecognized compression type"
55-
[X] - PermissionError: "Forbidden"
56-
57-
lxml
58-
[X] - ValueError: "Either element or attributes can be parsed not both."
59-
[X] - AttributeError: "__enter__"
60-
[X] - XSLTApplyError: "Cannot resolve URI"
61-
[X] - XSLTParseError: "document is not a stylesheet"
62-
[X] - ValueError: "xpath does not return any nodes."
63-
[X] - XPathEvalError: "Invalid expression"
64-
[] - XPathSyntaxError: (OLD VERSION IN lxml FOR XPATH ERRORS)
65-
[X] - TypeError: "empty namespace prefix is not supported in XPath"
66-
[X] - ValueError: "names does not match length of child elements in xpath."
67-
[X] - TypeError: "...is not a valid type for names"
68-
[X] - LookupError: "unknown encoding"
69-
[] - URLError: (USUALLY DUE TO NETWORKING)
70-
[X - HTTPError: "HTTP Error 404: Not Found"
71-
[X] - OSError: "failed to load external entity"
72-
[X] - XMLSyntaxError: "Start tag expected, '<' not found"
73-
[] - ParserError: (FAILSAFE CATCH ALL FOR VERY COMPLEX XML
74-
[X] - ValueError: "Values for parser can only be lxml or etree."
75-
[X] - UnicodeDecodeError: "'utf-8' codec can't decode byte 0xe9..."
76-
[X] - UnicodeError: "UTF-16 stream does not start with BOM"
77-
[X] - BadZipFile: "File is not a zip file"
78-
[X] - OSError: "Invalid data stream"
79-
[X] - LZMAError: "Input format not supported by decoder"
80-
[X] - ValueError: "Unrecognized compression type"
81-
[X] - PermissionError: "Forbidden"
82-
"""
30+
# CHECK LIST
31+
32+
# [x] - ValueError: "Values for parser can only be lxml or etree."
33+
34+
# etree
35+
# [X] - ImportError: "lxml not found, please install or use the etree parser."
36+
# [X] - TypeError: "expected str, bytes or os.PathLike object, not NoneType"
37+
# [X] - ValueError: "Either element or attributes can be parsed not both."
38+
# [X] - ValueError: "xpath does not return any nodes..."
39+
# [X] - SyntaxError: "You have used an incorrect or unsupported XPath"
40+
# [X] - ValueError: "names does not match length of child elements in xpath."
41+
# [X] - TypeError: "...is not a valid type for names"
42+
# [X] - ValueError: "To use stylesheet, you need lxml installed..."
43+
# [] - URLError: (GENERAL ERROR WITH HTTPError AS SUBCLASS)
44+
# [X] - HTTPError: "HTTP Error 404: Not Found"
45+
# [] - OSError: (GENERAL ERROR WITH FileNotFoundError AS SUBCLASS)
46+
# [X] - FileNotFoundError: "No such file or directory"
47+
# [] - ParseError (FAILSAFE CATCH ALL FOR VERY COMPLEX XML)
48+
# [X] - UnicodeDecodeError: "'utf-8' codec can't decode byte 0xe9..."
49+
# [X] - UnicodeError: "UTF-16 stream does not start with BOM"
50+
# [X] - BadZipFile: "File is not a zip file"
51+
# [X] - OSError: "Invalid data stream"
52+
# [X] - LZMAError: "Input format not supported by decoder"
53+
# [X] - ValueError: "Unrecognized compression type"
54+
# [X] - PermissionError: "Forbidden"
55+
56+
# lxml
57+
# [X] - ValueError: "Either element or attributes can be parsed not both."
58+
# [X] - AttributeError: "__enter__"
59+
# [X] - XSLTApplyError: "Cannot resolve URI"
60+
# [X] - XSLTParseError: "document is not a stylesheet"
61+
# [X] - ValueError: "xpath does not return any nodes."
62+
# [X] - XPathEvalError: "Invalid expression"
63+
# [] - XPathSyntaxError: (OLD VERSION IN lxml FOR XPATH ERRORS)
64+
# [X] - TypeError: "empty namespace prefix is not supported in XPath"
65+
# [X] - ValueError: "names does not match length of child elements in xpath."
66+
# [X] - TypeError: "...is not a valid type for names"
67+
# [X] - LookupError: "unknown encoding"
68+
# [] - URLError: (USUALLY DUE TO NETWORKING)
69+
# [X - HTTPError: "HTTP Error 404: Not Found"
70+
# [X] - OSError: "failed to load external entity"
71+
# [X] - XMLSyntaxError: "Start tag expected, '<' not found"
72+
# [] - ParserError: (FAILSAFE CATCH ALL FOR VERY COMPLEX XML
73+
# [X] - ValueError: "Values for parser can only be lxml or etree."
74+
# [X] - UnicodeDecodeError: "'utf-8' codec can't decode byte 0xe9..."
75+
# [X] - UnicodeError: "UTF-16 stream does not start with BOM"
76+
# [X] - BadZipFile: "File is not a zip file"
77+
# [X] - OSError: "Invalid data stream"
78+
# [X] - LZMAError: "Input format not supported by decoder"
79+
# [X] - ValueError: "Unrecognized compression type"
80+
# [X] - PermissionError: "Forbidden"
8381

8482
geom_df = DataFrame(
8583
{

pandas/tests/series/indexing/test_datetime.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,7 @@ def test_datetime_indexing():
274274
assert s[stamp] == 0
275275

276276

277-
"""
278-
test duplicates in time series
279-
"""
277+
# test duplicates in time series
280278

281279

282280
def test_indexing_with_duplicate_datetimeindex(

pandas/tests/series/indexing/test_indexing.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,7 @@ def test_multilevel_preserve_name(lexsorted_two_level_string_multiindex, indexer
286286
assert result.name == ser.name
287287

288288

289-
"""
290-
miscellaneous methods
291-
"""
289+
# miscellaneous methods
292290

293291

294292
@pytest.mark.parametrize(

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ disable = [
146146
"global-statement",
147147
"invalid-overridden-method",
148148
"keyword-arg-before-vararg",
149-
"pointless-string-statement",
150149
"possibly-unused-variable",
151150
"protected-access",
152151
"raise-missing-from",

0 commit comments

Comments
 (0)