Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" orc compat """ 

2 

3import distutils 

4from typing import TYPE_CHECKING, List, Optional 

5 

6from pandas._typing import FilePathOrBuffer 

7 

8from pandas.io.common import get_filepath_or_buffer 

9 

10if TYPE_CHECKING: 

11 from pandas import DataFrame 

12 

13 

14def read_orc( 

15 path: FilePathOrBuffer, columns: Optional[List[str]] = None, **kwargs, 

16) -> "DataFrame": 

17 """ 

18 Load an ORC object from the file path, returning a DataFrame. 

19 

20 .. versionadded:: 1.0.0 

21 

22 Parameters 

23 ---------- 

24 path : str, path object or file-like object 

25 Any valid string path is acceptable. The string could be a URL. Valid 

26 URL schemes include http, ftp, s3, and file. For file URLs, a host is 

27 expected. A local file could be: 

28 ``file://localhost/path/to/table.orc``. 

29 

30 If you want to pass in a path object, pandas accepts any 

31 ``os.PathLike``. 

32 

33 By file-like object, we refer to objects with a ``read()`` method, 

34 such as a file handler (e.g. via builtin ``open`` function) 

35 or ``StringIO``. 

36 columns : list, default None 

37 If not None, only these columns will be read from the file. 

38 **kwargs 

39 Any additional kwargs are passed to pyarrow. 

40 

41 Returns 

42 ------- 

43 DataFrame 

44 """ 

45 

46 # we require a newer version of pyarrow than we support for parquet 

47 import pyarrow 

48 

49 if distutils.version.LooseVersion(pyarrow.__version__) < "0.13.0": 

50 raise ImportError("pyarrow must be >= 0.13.0 for read_orc") 

51 

52 import pyarrow.orc 

53 

54 path, _, _, _ = get_filepath_or_buffer(path) 

55 orc_file = pyarrow.orc.ORCFile(path) 

56 result = orc_file.read(columns=columns, **kwargs).to_pandas() 

57 return result