| [ Web Proxy ] |
| Viewing: https://arrow.apache.org/docs/python/generated/../integration/../generated/pyarrow.PythonFile.html | [Back] [Original] |
Bases: NativeFile
A stream backed by a Python file object.
This class allows using Python file objects with arbitrary Arrow functions, including functions written in another language than Python.
As a downside, there is a non-zero redirection cost in translating Arrow stream calls to Python method calls. Furthermore, Pythons Global Interpreter Lock may limit parallelism in some situations.
Examples
>>> import io
>>> import pyarrow as pa
>>> pa.PythonFile(io.BytesIO())
<pyarrow.PythonFile closed=False own_file=False is_seekable=False is_writable=True is_readable=False>
Create a stream for writing:
>>> buf = io.BytesIO()
>>> f = pa.PythonFile(buf, mode = 'w')
>>> f.writable()
True
>>> f.write(b'PythonFile')
10
>>> buf.getvalue()
b'PythonFile'
>>> f.close()
>>> f
<pyarrow.PythonFile closed=True own_file=False is_seekable=False is_writable=True is_readable=False>
Create a stream for reading:
>>> buf = io.BytesIO(b'PythonFile')
>>> f = pa.PythonFile(buf, mode = 'r')
>>> f.mode
'rb'
>>> f.read()
b'PythonFile'
>>> f
<pyarrow.PythonFile closed=False own_file=False is_seekable=True is_writable=False is_readable=True>
>>> f.close()
>>> f
<pyarrow.PythonFile closed=True own_file=False is_seekable=True is_writable=False is_readable=True>
Methods
|
|
|
|
|
Read this file completely to a local path or destination stream. |
|
NOT IMPLEMENTED |
|
Flush the stream, if applicable. |
|
Return an input stream that reads a file segment independent of the state of the file. |
|
|
|
Return file metadata |
|
Read and return up to n bytes. |
|
Read and return up to n bytes. |
|
Read indicated number of bytes at offset from the file |
|
Read from buffer. |
|
|
|
|
|
Read into the supplied buffer |
|
Read and return a line of bytes from the file. |
|
Read lines of the file. |
|
Change current file stream position |
|
|
|
Return file size |
|
Return current stream position |
|
|
|
Write from a source stream to this file. |
|
|
|
Write data to the file. |
|
Write lines to the file. |
Attributes
Read this file completely to a local path or destination stream.
This method first seeks to the beginning of the file.
NOT IMPLEMENTED
Flush the stream, if applicable.
An error is raised if stream is not writable.
Return an input stream that reads a file segment independent of the state of the file.
Allows reading portions of a random access file as an input stream without interfering with each other.
NativeFileReturn file metadata
The file mode. Currently instances of NativeFile may support:
rb: binary read
wb: binary write
rb+: binary read and write
ab: binary append
Read and return up to n bytes.
If nbytes is None, then the entire remaining file contents are read.
Read and return up to n bytes.
Unlike read(), if nbytes is None then a chunk is read, not the entire file.
Read indicated number of bytes at offset from the file
Read from buffer.
int, optionalmaximum number of bytes read
Read into the supplied buffer
A writable buffer object (such as a bytearray).
intnumber of bytes written
Read and return a line of bytes from the file.
If size is specified, read at most size bytes.
intMaximum number of bytes read
Read lines of the file.
intMaximum number of bytes read until we stop
Change current file stream position
intThe new absolute stream position.
Notes
Values of whence: * 0 start of stream (the default); offset should be zero or positive * 1 current stream position; offset may be negative * 2 end of stream; offset is usually negative
Return file size
Return current stream position
Write from a source stream to this file.
Source stream to pipe to this file.
int, optionalThe buffer size to use for data transfers.
| Web Proxy Viewer | New URL | Original Page |