Skip to content

Commit 886ca6f

Browse files
authored
GH-47179: [Python] Revert FileSystem.from_uri to be a staticmethod again (#47178)
### Rationale for this change It seems as part of #45089 `FileSystem.from_uri` was changed from a static function to a regular method. I believe this to be an error unintentionally introduced as part of the PR, based on the fact that this was not mentioned to be an explicit change, and the documentation attached to the function still shows it being called as a static method. This changed was released as part of version 21.0. Previously, it was a static method on the class. Now, when attempting to call `FileSystem.from_uri`, it breaks in two different cases: 1. Calling it as a class static method with an explicit `uri` argument. 2. Calling it as an instance method. However, calling it as a class static method without an explicit `uri` argument (ex. `FileSystem.from_uri("/abc")`) still works. This PR adds the `@ staticmethod` annotation back to this method. ### What changes are included in this PR? `FileSystem.from_uri` is now a static method again. ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes, to the `FileSystem.from_uri` function. * GitHub Issue: #47179 Authored-by: ff-kamal <[email protected]> Signed-off-by: AlenkaF <[email protected]>
1 parent 940592b commit 886ca6f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

python/pyarrow/_fs.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ cdef class FileSystem(_Weakrefable):
456456
result = CFileSystemFromUriOrPath(c_uri, &c_path)
457457
return FileSystem.wrap(GetResultValue(result)), frombytes(c_path)
458458

459+
@staticmethod
459460
def from_uri(uri):
460461
"""
461462
Create a new FileSystem from URI or Path.

python/pyarrow/tests/test_fs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,23 @@ def test_filesystem_from_uri(uri, expected_klass, expected_path):
16421642
assert path == expected_path
16431643

16441644

1645+
def test_filesystem_from_uri_calling():
1646+
# Call using class staticmethod
1647+
fs, path = FileSystem.from_uri("file:/")
1648+
assert isinstance(fs, LocalFileSystem)
1649+
assert path == "/"
1650+
1651+
# Call using class staticmethod with explicit arguments
1652+
fs, path = FileSystem.from_uri(uri="file:/")
1653+
assert isinstance(fs, LocalFileSystem)
1654+
assert path == "/"
1655+
1656+
# Call using instance method passthrough
1657+
fs, path = LocalFileSystem().from_uri(uri="file:/")
1658+
assert isinstance(fs, LocalFileSystem)
1659+
assert path == "/"
1660+
1661+
16451662
@pytest.mark.parametrize(
16461663
'path',
16471664
['', '/', 'foo/bar', '/foo/bar', __file__]

0 commit comments

Comments
 (0)