diff --git a/doc/source/development/contributing.rst b/doc/source/development/contributing.rst index c66ae5e4bc36f..3cdf9b83e96f3 100644 --- a/doc/source/development/contributing.rst +++ b/doc/source/development/contributing.rst @@ -208,7 +208,7 @@ We'll now kick off a three-step process: # Build and install pandas python setup.py build_ext --inplace -j 4 - python -m pip install -e --no-build-isolation . + python -m pip install -e . --no-build-isolation At this point you should be able to import pandas from your locally built version:: @@ -252,7 +252,7 @@ You'll need to have at least python3.5 installed on your system. # Build and install pandas python setup.py build_ext --inplace -j 4 - python -m pip install -e --no-build-isolation . + python -m pip install -e . --no-build-isolation Creating a branch ----------------- diff --git a/pandas/core/arrays/sparse.py b/pandas/core/arrays/sparse.py index 201174b6b1995..24dafd11ae2b7 100644 --- a/pandas/core/arrays/sparse.py +++ b/pandas/core/arrays/sparse.py @@ -245,10 +245,10 @@ def construct_from_string(cls, string): if string.startswith("Sparse"): try: sub_type, has_fill_value = cls._parse_subtype(string) - result = SparseDtype(sub_type) - except Exception: + except ValueError: raise TypeError(msg) else: + result = SparseDtype(sub_type) msg = ( "Could not construct SparseDtype from '{}'.\n\nIt " "looks like the fill_value in the string is not " diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index f75493be2dab1..cf1a602e9e9f2 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -2049,10 +2049,8 @@ def pandas_dtype(dtype): # raise a consistent TypeError if failed try: npdtype = np.dtype(dtype) - except Exception: - # we don't want to force a repr of the non-string - if not isinstance(dtype, str): - raise TypeError("data type not understood") + except SyntaxError: + # np.dtype uses `eval` which can raise SyntaxError raise TypeError("data type '{}' not understood".format(dtype)) # Any invalid dtype (such as pd.Timestamp) should raise an error. diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 1ff3400323e54..4f3f639de5cb1 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -1791,7 +1791,7 @@ def convert(self, values, nan_rep, encoding, errors, start=None, stop=None): # making an Index instance could throw a number of different errors try: self.values = Index(values, **kwargs) - except Exception: # noqa: E722 + except Exception: # if the output freq is different that what we recorded, # it should be None (see also 'doc example part 2') diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 36548f3515a48..db9f647e0f0c7 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -678,7 +678,7 @@ def test__get_dtype_sparse(): (None, "Cannot deduce dtype from null object"), (1, "data type not understood"), (1.2, "data type not understood"), - ("random string", "data type 'random string' not understood"), + ("random string", 'data type "random string" not understood'), (pd.DataFrame([1, 2]), "data type not understood"), ], ) diff --git a/pandas/tests/indexes/interval/test_astype.py b/pandas/tests/indexes/interval/test_astype.py index 91022fef16521..863b8c9082f07 100644 --- a/pandas/tests/indexes/interval/test_astype.py +++ b/pandas/tests/indexes/interval/test_astype.py @@ -67,7 +67,7 @@ def test_astype_cannot_cast(self, index, dtype): index.astype(dtype) def test_astype_invalid_dtype(self, index): - msg = "data type 'fake_dtype' not understood" + msg = 'data type "fake_dtype" not understood' with pytest.raises(TypeError, match=msg): index.astype("fake_dtype") diff --git a/pandas/tests/indexes/interval/test_construction.py b/pandas/tests/indexes/interval/test_construction.py index 82a10d24dad30..98c1f7c6c2a8a 100644 --- a/pandas/tests/indexes/interval/test_construction.py +++ b/pandas/tests/indexes/interval/test_construction.py @@ -164,7 +164,7 @@ def test_generic_errors(self, constructor): constructor(dtype="int64", **filler) # invalid dtype - msg = "data type 'invalid' not understood" + msg = 'data type "invalid" not understood' with pytest.raises(TypeError, match=msg): constructor(dtype="invalid", **filler) diff --git a/pandas/tests/io/parser/test_dtypes.py b/pandas/tests/io/parser/test_dtypes.py index 92c91565e1c23..a68d46e8a6c15 100644 --- a/pandas/tests/io/parser/test_dtypes.py +++ b/pandas/tests/io/parser/test_dtypes.py @@ -79,7 +79,7 @@ def test_invalid_dtype_per_column(all_parsers): 3,4.5 4,5.5""" - with pytest.raises(TypeError, match="data type 'foo' not understood"): + with pytest.raises(TypeError, match='data type "foo" not understood'): parser.read_csv(StringIO(data), dtype={"one": "foo", 1: "int"})