diff --git a/pandas/core/util/hashing.py b/pandas/core/util/hashing.py index e0b18047aa0ec..350914cc50556 100644 --- a/pandas/core/util/hashing.py +++ b/pandas/core/util/hashing.py @@ -71,12 +71,14 @@ def combine_hash_arrays( mult = np.uint64(1000003) out = np.zeros_like(first) + np.uint64(0x345678) + last_i = 0 for i, a in enumerate(arrays): inverse_i = num_items - i out ^= a out *= mult mult += np.uint64(82520 + inverse_i + inverse_i) - assert i + 1 == num_items, "Fed in wrong num_items" + last_i = i + assert last_i + 1 == num_items, "Fed in wrong num_items" out += np.uint64(97531) return out diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index d44bdc466aed9..6fb6d72bab099 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -736,7 +736,9 @@ def parse( output = {} + last_sheetname = None for asheetname in sheets: + last_sheetname = asheetname if verbose: print(f"Reading sheet {asheetname}") @@ -888,10 +890,13 @@ def parse( err.args = (f"{err.args[0]} (sheet: {asheetname})", *err.args[1:]) raise err + if last_sheetname is None: + raise ValueError("Sheet name is an empty list") + if ret_dict: return output else: - return output[asheetname] + return output[last_sheetname] @doc(storage_options=_shared_docs["storage_options"]) diff --git a/pandas/tests/frame/methods/test_to_dict_of_blocks.py b/pandas/tests/frame/methods/test_to_dict_of_blocks.py index 9705f24d0286c..cc4860beea491 100644 --- a/pandas/tests/frame/methods/test_to_dict_of_blocks.py +++ b/pandas/tests/frame/methods/test_to_dict_of_blocks.py @@ -20,30 +20,34 @@ def test_copy_blocks(self, float_frame): column = df.columns[0] # use the default copy=True, change a column + _last_df = None blocks = df._to_dict_of_blocks(copy=True) for _df in blocks.values(): + _last_df = _df if column in _df: _df.loc[:, column] = _df[column] + 1 # make sure we did not change the original DataFrame - assert not _df[column].equals(df[column]) + assert _last_df is not None and not _last_df[column].equals(df[column]) def test_no_copy_blocks(self, float_frame, using_copy_on_write): # GH#9607 df = DataFrame(float_frame, copy=True) column = df.columns[0] + _last_df = None # use the copy=False, change a column blocks = df._to_dict_of_blocks(copy=False) for _df in blocks.values(): + _last_df = _df if column in _df: _df.loc[:, column] = _df[column] + 1 if not using_copy_on_write: # make sure we did change the original DataFrame - assert _df[column].equals(df[column]) + assert _last_df is not None and _last_df[column].equals(df[column]) else: - assert not _df[column].equals(df[column]) + assert _last_df is not None and not _last_df[column].equals(df[column]) def test_to_dict_of_blocks_item_cache(request, using_copy_on_write): diff --git a/pandas/tests/io/formats/test_printing.py b/pandas/tests/io/formats/test_printing.py index 3532f979665ec..803ed8d342a2f 100644 --- a/pandas/tests/io/formats/test_printing.py +++ b/pandas/tests/io/formats/test_printing.py @@ -122,14 +122,16 @@ class TestTableSchemaRepr: def test_publishes(self, ip): ipython = ip.instance(config=ip.config) df = pd.DataFrame({"A": [1, 2]}) - objects = [df["A"], df, df] # dataframe / series + objects = [df["A"], df] # dataframe / series expected_keys = [ {"text/plain", "application/vnd.dataresource+json"}, {"text/plain", "text/html", "application/vnd.dataresource+json"}, ] opt = pd.option_context("display.html.table_schema", True) + last_obj = None for obj, expected in zip(objects, expected_keys): + last_obj = obj with opt: formatted = ipython.display_formatter.format(obj) assert set(formatted[0].keys()) == expected @@ -137,7 +139,7 @@ def test_publishes(self, ip): with_latex = pd.option_context("styler.render.repr", "latex") with opt, with_latex: - formatted = ipython.display_formatter.format(obj) + formatted = ipython.display_formatter.format(last_obj) expected = { "text/plain", diff --git a/pyproject.toml b/pyproject.toml index dc237d32c022c..b8a2cb89ff3a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -287,7 +287,6 @@ disable = [ "too-many-public-methods", "too-many-return-statements", "too-many-statements", - "undefined-loop-variable", "unexpected-keyword-arg", "ungrouped-imports", "unsubscriptable-object",