diff --git a/fsspec/spec.py b/fsspec/spec.py index 3a71b2227..a390bf060 100644 --- a/fsspec/spec.py +++ b/fsspec/spec.py @@ -874,7 +874,7 @@ def cat_ranges( out = [] for p, s, e in zip(paths, starts, ends): try: - out.append(self.cat_file(p, s, e)) + out.append(self.cat_file(p, s, e, **kwargs)) except Exception as e: if on_error == "return": out.append(e) diff --git a/fsspec/tests/test_spec.py b/fsspec/tests/test_spec.py index 8880c255c..7fc828243 100644 --- a/fsspec/tests/test_spec.py +++ b/fsspec/tests/test_spec.py @@ -1456,3 +1456,21 @@ def test_expand_path_with_magic_input(): "bucket/file?.txt", ] assert sorted(paths) == sorted(expected) + + +def test_cat_ranges_forwards_kwargs(): + # See GH#2016: cat_ranges must forward **kwargs to cat_file, otherwise + # parameters such as a cache's block_size are silently dropped. + received = [] + + class RecordingFS(AbstractFileSystem): + cachable = False + + def cat_file(self, path, start=None, end=None, **kwargs): + received.append(kwargs) + return b"" + + fs = RecordingFS() + fs.cat_ranges(["a", "b"], [0, 0], [1, 1], block_size=42) + + assert received == [{"block_size": 42}, {"block_size": 42}]