diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 64bd66bb5fe0d..9772788fe2b9d 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -587,20 +587,18 @@ def _dtype_to_subclass(cls, dtype: DtypeObj): raise NotImplementedError(dtype) - """ - NOTE for new Index creation: + # NOTE for new Index creation: - - _simple_new: It returns new Index with the same type as the caller. - All metadata (such as name) must be provided by caller's responsibility. - Using _shallow_copy is recommended because it fills these metadata - otherwise specified. + # - _simple_new: It returns new Index with the same type as the caller. + # All metadata (such as name) must be provided by caller's responsibility. + # Using _shallow_copy is recommended because it fills these metadata + # otherwise specified. - - _shallow_copy: It returns new Index with the same type (using - _simple_new), but fills caller's metadata otherwise specified. Passed - kwargs will overwrite corresponding metadata. + # - _shallow_copy: It returns new Index with the same type (using + # _simple_new), but fills caller's metadata otherwise specified. Passed + # kwargs will overwrite corresponding metadata. - See each method's docstring. - """ + # See each method's docstring. @classmethod def _simple_new(cls: type[_IndexT], values, name: Hashable = None) -> _IndexT: @@ -3963,10 +3961,7 @@ def is_int(v): is_positional = is_index_slice and ints_are_positional if kind == "getitem": - """ - called from the getitem slicers, validate that we are in fact - integers - """ + # called from the getitem slicers, validate that we are in fact integers if self.is_integer(): if is_frame: # unambiguously positional, no deprecation diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 664e8dfdb4d20..324076cd38917 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -839,12 +839,10 @@ def _get_xticks(self, convert_period: bool = False): self.data = self.data.reindex(index=index.sort_values()) x = self.data.index.to_timestamp()._mpl_repr() elif index.is_numeric(): - """ - Matplotlib supports numeric values or datetime objects as - xaxis values. Taking LBYL approach here, by the time - matplotlib raises exception when using non numeric/datetime - values for xaxis, several actions are already taken by plt. - """ + # Matplotlib supports numeric values or datetime objects as + # xaxis values. Taking LBYL approach here, by the time + # matplotlib raises exception when using non numeric/datetime + # values for xaxis, several actions are already taken by plt. x = index._mpl_repr() elif is_datetype: self.data = self.data[notna(self.data.index)] diff --git a/pandas/tests/frame/methods/test_reset_index.py b/pandas/tests/frame/methods/test_reset_index.py index f179b11c41e43..0ee19ab29c13b 100644 --- a/pandas/tests/frame/methods/test_reset_index.py +++ b/pandas/tests/frame/methods/test_reset_index.py @@ -452,8 +452,10 @@ def test_reset_index_duplicate_columns_allow( tm.assert_frame_equal(result, expected) else: if not flag and allow_duplicates: - msg = "Cannot specify 'allow_duplicates=True' when " - "'self.flags.allows_duplicate_labels' is False" + msg = ( + "Cannot specify 'allow_duplicates=True' when " + "'self.flags.allows_duplicate_labels' is False" + ) else: msg = r"cannot insert \('A', ''\), already exists" with pytest.raises(ValueError, match=msg): diff --git a/pandas/tests/indexes/multi/test_analytics.py b/pandas/tests/indexes/multi/test_analytics.py index 629cd7eac29b0..8803862615858 100644 --- a/pandas/tests/indexes/multi/test_analytics.py +++ b/pandas/tests/indexes/multi/test_analytics.py @@ -15,8 +15,10 @@ def test_shift(idx): # GH8083 test the base class for shift - msg = "This method is only implemented for DatetimeIndex, PeriodIndex and " - "TimedeltaIndex; Got type MultiIndex" + msg = ( + "This method is only implemented for DatetimeIndex, PeriodIndex and " + "TimedeltaIndex; Got type MultiIndex" + ) with pytest.raises(NotImplementedError, match=msg): idx.shift(1) with pytest.raises(NotImplementedError, match=msg): diff --git a/pandas/tests/indexing/interval/test_interval_new.py b/pandas/tests/indexing/interval/test_interval_new.py index 4b89232f9fb12..0d314cd73860a 100644 --- a/pandas/tests/indexing/interval/test_interval_new.py +++ b/pandas/tests/indexing/interval/test_interval_new.py @@ -162,8 +162,10 @@ def test_loc_with_overlap(self, indexer_sl): result = indexer_sl(ser)[Interval(1, 5) : Interval(3, 7)] tm.assert_series_equal(expected, result) - msg = "'can only get slices from an IntervalIndex if bounds are" - " non-overlapping and all monotonic increasing or decreasing'" + msg = ( + "'can only get slices from an IntervalIndex if bounds are " + "non-overlapping and all monotonic increasing or decreasing'" + ) with pytest.raises(KeyError, match=msg): indexer_sl(ser)[Interval(1, 6) : Interval(3, 8)] diff --git a/pandas/tests/io/parser/common/test_read_errors.py b/pandas/tests/io/parser/common/test_read_errors.py index aec0d57bc0fc4..798d64899a43c 100644 --- a/pandas/tests/io/parser/common/test_read_errors.py +++ b/pandas/tests/io/parser/common/test_read_errors.py @@ -241,8 +241,10 @@ def test_bad_header_uniform_error(all_parsers): data = "+++123456789...\ncol1,col2,col3,col4\n1,2,3,4\n" msg = "Expected 2 fields in line 2, saw 4" if parser.engine == "c": - msg = "Could not construct index. Requested to use 1 " - "number of columns, but 3 left to parse." + msg = ( + "Could not construct index. Requested to use 1 " + "number of columns, but 3 left to parse." + ) with pytest.raises(ParserError, match=msg): parser.read_csv(StringIO(data), index_col=0, on_bad_lines="error") diff --git a/pandas/tests/io/xml/test_to_xml.py b/pandas/tests/io/xml/test_to_xml.py index 0f42c7e070c4a..39f4c77cc3a50 100644 --- a/pandas/tests/io/xml/test_to_xml.py +++ b/pandas/tests/io/xml/test_to_xml.py @@ -22,41 +22,39 @@ from pandas.io.common import get_handle from pandas.io.xml import read_xml -""" -CHECKLIST - -[x] - ValueError: "Values for parser can only be lxml or etree." - -etree -[x] - ImportError: "lxml not found, please install or use the etree parser." -[X] - TypeError: "...is not a valid type for attr_cols" -[X] - TypeError: "...is not a valid type for elem_cols" -[X] - LookupError: "unknown encoding" -[X] - KeyError: "...is not included in namespaces" -[X] - KeyError: "no valid column" -[X] - ValueError: "To use stylesheet, you need lxml installed..." -[] - OSError: (NEED PERMISSOIN ISSUE, DISK FULL, ETC.) -[X] - FileNotFoundError: "No such file or directory" -[X] - PermissionError: "Forbidden" - -lxml -[X] - TypeError: "...is not a valid type for attr_cols" -[X] - TypeError: "...is not a valid type for elem_cols" -[X] - LookupError: "unknown encoding" -[] - OSError: (NEED PERMISSOIN ISSUE, DISK FULL, ETC.) -[X] - FileNotFoundError: "No such file or directory" -[X] - KeyError: "...is not included in namespaces" -[X] - KeyError: "no valid column" -[X] - ValueError: "stylesheet is not a url, file, or xml string." -[] - LookupError: (NEED WRONG ENCODING FOR FILE OUTPUT) -[] - URLError: (USUALLY DUE TO NETWORKING) -[] - HTTPError: (NEED AN ONLINE STYLESHEET) -[X] - OSError: "failed to load external entity" -[X] - XMLSyntaxError: "Opening and ending tag mismatch" -[X] - XSLTApplyError: "Cannot resolve URI" -[X] - XSLTParseError: "failed to compile" -[X] - PermissionError: "Forbidden" -""" +# CHECKLIST + +# [x] - ValueError: "Values for parser can only be lxml or etree." + +# etree +# [x] - ImportError: "lxml not found, please install or use the etree parser." +# [X] - TypeError: "...is not a valid type for attr_cols" +# [X] - TypeError: "...is not a valid type for elem_cols" +# [X] - LookupError: "unknown encoding" +# [X] - KeyError: "...is not included in namespaces" +# [X] - KeyError: "no valid column" +# [X] - ValueError: "To use stylesheet, you need lxml installed..." +# [] - OSError: (NEED PERMISSOIN ISSUE, DISK FULL, ETC.) +# [X] - FileNotFoundError: "No such file or directory" +# [X] - PermissionError: "Forbidden" + +# lxml +# [X] - TypeError: "...is not a valid type for attr_cols" +# [X] - TypeError: "...is not a valid type for elem_cols" +# [X] - LookupError: "unknown encoding" +# [] - OSError: (NEED PERMISSOIN ISSUE, DISK FULL, ETC.) +# [X] - FileNotFoundError: "No such file or directory" +# [X] - KeyError: "...is not included in namespaces" +# [X] - KeyError: "no valid column" +# [X] - ValueError: "stylesheet is not a url, file, or xml string." +# [] - LookupError: (NEED WRONG ENCODING FOR FILE OUTPUT) +# [] - URLError: (USUALLY DUE TO NETWORKING) +# [] - HTTPError: (NEED AN ONLINE STYLESHEET) +# [X] - OSError: "failed to load external entity" +# [X] - XMLSyntaxError: "Opening and ending tag mismatch" +# [X] - XSLTApplyError: "Cannot resolve URI" +# [X] - XSLTParseError: "failed to compile" +# [X] - PermissionError: "Forbidden" geom_df = DataFrame( { diff --git a/pandas/tests/io/xml/test_xml.py b/pandas/tests/io/xml/test_xml.py index 0829ece64c451..aeaf2d3b7edbf 100644 --- a/pandas/tests/io/xml/test_xml.py +++ b/pandas/tests/io/xml/test_xml.py @@ -27,59 +27,57 @@ from pandas.io.common import get_handle from pandas.io.xml import read_xml -""" -CHECK LIST - -[x] - ValueError: "Values for parser can only be lxml or etree." - -etree -[X] - ImportError: "lxml not found, please install or use the etree parser." -[X] - TypeError: "expected str, bytes or os.PathLike object, not NoneType" -[X] - ValueError: "Either element or attributes can be parsed not both." -[X] - ValueError: "xpath does not return any nodes..." -[X] - SyntaxError: "You have used an incorrect or unsupported XPath" -[X] - ValueError: "names does not match length of child elements in xpath." -[X] - TypeError: "...is not a valid type for names" -[X] - ValueError: "To use stylesheet, you need lxml installed..." -[] - URLError: (GENERAL ERROR WITH HTTPError AS SUBCLASS) -[X] - HTTPError: "HTTP Error 404: Not Found" -[] - OSError: (GENERAL ERROR WITH FileNotFoundError AS SUBCLASS) -[X] - FileNotFoundError: "No such file or directory" -[] - ParseError (FAILSAFE CATCH ALL FOR VERY COMPLEX XML) -[X] - UnicodeDecodeError: "'utf-8' codec can't decode byte 0xe9..." -[X] - UnicodeError: "UTF-16 stream does not start with BOM" -[X] - BadZipFile: "File is not a zip file" -[X] - OSError: "Invalid data stream" -[X] - LZMAError: "Input format not supported by decoder" -[X] - ValueError: "Unrecognized compression type" -[X] - PermissionError: "Forbidden" - -lxml -[X] - ValueError: "Either element or attributes can be parsed not both." -[X] - AttributeError: "__enter__" -[X] - XSLTApplyError: "Cannot resolve URI" -[X] - XSLTParseError: "document is not a stylesheet" -[X] - ValueError: "xpath does not return any nodes." -[X] - XPathEvalError: "Invalid expression" -[] - XPathSyntaxError: (OLD VERSION IN lxml FOR XPATH ERRORS) -[X] - TypeError: "empty namespace prefix is not supported in XPath" -[X] - ValueError: "names does not match length of child elements in xpath." -[X] - TypeError: "...is not a valid type for names" -[X] - LookupError: "unknown encoding" -[] - URLError: (USUALLY DUE TO NETWORKING) -[X - HTTPError: "HTTP Error 404: Not Found" -[X] - OSError: "failed to load external entity" -[X] - XMLSyntaxError: "Start tag expected, '<' not found" -[] - ParserError: (FAILSAFE CATCH ALL FOR VERY COMPLEX XML -[X] - ValueError: "Values for parser can only be lxml or etree." -[X] - UnicodeDecodeError: "'utf-8' codec can't decode byte 0xe9..." -[X] - UnicodeError: "UTF-16 stream does not start with BOM" -[X] - BadZipFile: "File is not a zip file" -[X] - OSError: "Invalid data stream" -[X] - LZMAError: "Input format not supported by decoder" -[X] - ValueError: "Unrecognized compression type" -[X] - PermissionError: "Forbidden" -""" +# CHECK LIST + +# [x] - ValueError: "Values for parser can only be lxml or etree." + +# etree +# [X] - ImportError: "lxml not found, please install or use the etree parser." +# [X] - TypeError: "expected str, bytes or os.PathLike object, not NoneType" +# [X] - ValueError: "Either element or attributes can be parsed not both." +# [X] - ValueError: "xpath does not return any nodes..." +# [X] - SyntaxError: "You have used an incorrect or unsupported XPath" +# [X] - ValueError: "names does not match length of child elements in xpath." +# [X] - TypeError: "...is not a valid type for names" +# [X] - ValueError: "To use stylesheet, you need lxml installed..." +# [] - URLError: (GENERAL ERROR WITH HTTPError AS SUBCLASS) +# [X] - HTTPError: "HTTP Error 404: Not Found" +# [] - OSError: (GENERAL ERROR WITH FileNotFoundError AS SUBCLASS) +# [X] - FileNotFoundError: "No such file or directory" +# [] - ParseError (FAILSAFE CATCH ALL FOR VERY COMPLEX XML) +# [X] - UnicodeDecodeError: "'utf-8' codec can't decode byte 0xe9..." +# [X] - UnicodeError: "UTF-16 stream does not start with BOM" +# [X] - BadZipFile: "File is not a zip file" +# [X] - OSError: "Invalid data stream" +# [X] - LZMAError: "Input format not supported by decoder" +# [X] - ValueError: "Unrecognized compression type" +# [X] - PermissionError: "Forbidden" + +# lxml +# [X] - ValueError: "Either element or attributes can be parsed not both." +# [X] - AttributeError: "__enter__" +# [X] - XSLTApplyError: "Cannot resolve URI" +# [X] - XSLTParseError: "document is not a stylesheet" +# [X] - ValueError: "xpath does not return any nodes." +# [X] - XPathEvalError: "Invalid expression" +# [] - XPathSyntaxError: (OLD VERSION IN lxml FOR XPATH ERRORS) +# [X] - TypeError: "empty namespace prefix is not supported in XPath" +# [X] - ValueError: "names does not match length of child elements in xpath." +# [X] - TypeError: "...is not a valid type for names" +# [X] - LookupError: "unknown encoding" +# [] - URLError: (USUALLY DUE TO NETWORKING) +# [X - HTTPError: "HTTP Error 404: Not Found" +# [X] - OSError: "failed to load external entity" +# [X] - XMLSyntaxError: "Start tag expected, '<' not found" +# [] - ParserError: (FAILSAFE CATCH ALL FOR VERY COMPLEX XML +# [X] - ValueError: "Values for parser can only be lxml or etree." +# [X] - UnicodeDecodeError: "'utf-8' codec can't decode byte 0xe9..." +# [X] - UnicodeError: "UTF-16 stream does not start with BOM" +# [X] - BadZipFile: "File is not a zip file" +# [X] - OSError: "Invalid data stream" +# [X] - LZMAError: "Input format not supported by decoder" +# [X] - ValueError: "Unrecognized compression type" +# [X] - PermissionError: "Forbidden" geom_df = DataFrame( { diff --git a/pandas/tests/series/indexing/test_datetime.py b/pandas/tests/series/indexing/test_datetime.py index b977c78c635da..48cef368b387d 100644 --- a/pandas/tests/series/indexing/test_datetime.py +++ b/pandas/tests/series/indexing/test_datetime.py @@ -274,9 +274,7 @@ def test_datetime_indexing(): assert s[stamp] == 0 -""" -test duplicates in time series -""" +# test duplicates in time series def test_indexing_with_duplicate_datetimeindex( diff --git a/pandas/tests/series/indexing/test_indexing.py b/pandas/tests/series/indexing/test_indexing.py index c0e4db9f2c295..4efc14be3eb7e 100644 --- a/pandas/tests/series/indexing/test_indexing.py +++ b/pandas/tests/series/indexing/test_indexing.py @@ -286,9 +286,7 @@ def test_multilevel_preserve_name(lexsorted_two_level_string_multiindex, indexer assert result.name == ser.name -""" -miscellaneous methods -""" +# miscellaneous methods @pytest.mark.parametrize( diff --git a/pyproject.toml b/pyproject.toml index ad180ff5d59d5..4a181202922b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -146,7 +146,6 @@ disable = [ "global-statement", "invalid-overridden-method", "keyword-arg-before-vararg", - "pointless-string-statement", "possibly-unused-variable", "protected-access", "raise-missing-from",