You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/06/04 19:23:30 UTC

[GitHub] [arrow] pitrou commented on a change in pull request #7349: ARROW-8766: [Python] Allow implementing filesystems in Python

pitrou commented on a change in pull request #7349:
URL: https://github.com/apache/arrow/pull/7349#discussion_r435496748



##########
File path: python/pyarrow/_fs.pyx
##########
@@ -55,24 +56,56 @@ def _normalize_path(FileSystem filesystem, path):
     return frombytes(c_path_normalized)
 
 
+cdef object _wrap_file_type(CFileType ty):
+    return FileType(<int8_t> ty)
+
+
+cdef CFileType _unwrap_file_type(FileType ty) except *:
+    if ty == FileType.Unknown:
+        return CFileType_Unknown
+    elif ty == FileType.NotFound:
+        return CFileType_NotFound
+    elif ty == FileType.File:
+        return CFileType_File
+    elif ty == FileType.Directory:
+        return CFileType_Directory
+    assert 0
+
+
 cdef class FileInfo:
     """
     FileSystem entry info.
     """
 
-    def __init__(self):
-        raise TypeError("FileInfo cannot be instantiated directly, use "
-                        "FileSystem.get_file_info method instead.")
+    def __init__(self, path, FileType type=FileType.Unknown, *,
+                 mtime=None, size=None):
+        self.info.set_path(tobytes(path))
+        self.info.set_type(_unwrap_file_type(type))
+        if mtime is not None:
+            if isinstance(mtime, datetime):
+                self.info.set_mtime(PyDateTime_to_TimePoint(
+                    <PyDateTime_DateTime*> mtime))
+            else:
+                self.info.set_mtime(TimePoint_from_ns(mtime))

Review comment:
       Note to self: should instead add a separate `mtime_ns` argument.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org