Skip to content

Commit 0b6d483

Browse files
authored
ENH: add ntrheads option to feather-format IO (#16476)
ENH: add nthreads option to feather-format IO
1 parent 97ad3fb commit 0b6d483

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Other Enhancements
3535
- ``RangeIndex.append`` now returns a ``RangeIndex`` object when possible (:issue:`16212`)
3636
- :func:`to_pickle` has gained a protocol parameter (:issue:`16252`). By default, this parameter is set to `HIGHEST_PROTOCOL <https://docs.python.org/3/library/pickle.html#data-stream-format>`__
3737
- :func:`api.types.infer_dtype` now infers decimals. (:issue: `15690`)
38+
- :func:`read_feather` has gained the ``nthreads`` parameter for multi-threaded operations (:issue:`16359`)
3839

3940
.. _whatsnew_0210.api_breaking:
4041

pandas/io/feather_format.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def to_feather(df, path):
4343
df : DataFrame
4444
path : string
4545
File path
46+
4647
"""
4748
path = _stringify_path(path)
4849
if not isinstance(df, DataFrame):
@@ -83,7 +84,7 @@ def to_feather(df, path):
8384
feather.write_dataframe(df, path)
8485

8586

86-
def read_feather(path):
87+
def read_feather(path, nthreads=1):
8788
"""
8889
Load a feather-format object from the file path
8990
@@ -93,6 +94,10 @@ def read_feather(path):
9394
----------
9495
path : string
9596
File path
97+
nthreads : int, default 1
98+
Number of CPU threads to use when reading to pandas.DataFrame
99+
100+
.. versionadded 0.21.0
96101
97102
Returns
98103
-------
@@ -102,4 +107,8 @@ def read_feather(path):
102107

103108
feather = _try_import()
104109
path = _stringify_path(path)
105-
return feather.read_dataframe(path)
110+
111+
if feather.__version__ < LooseVersion('0.4.0'):
112+
return feather.read_dataframe(path)
113+
114+
return feather.read_dataframe(path, nthreads=nthreads)

pandas/tests/io/test_feather.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ def check_error_on_write(self, df, exc):
2727
with ensure_clean() as path:
2828
to_feather(df, path)
2929

30-
def check_round_trip(self, df):
30+
def check_round_trip(self, df, **kwargs):
3131

3232
with ensure_clean() as path:
3333
to_feather(df, path)
34-
result = read_feather(path)
34+
result = read_feather(path, **kwargs)
3535
assert_frame_equal(result, df)
3636

3737
def test_error(self):
@@ -98,6 +98,12 @@ def test_unsupported_other(self):
9898
df = pd.DataFrame({'a': pd.period_range('2013', freq='M', periods=3)})
9999
self.check_error_on_write(df, ValueError)
100100

101+
@pytest.mark.skipif(fv < '0.4.0', reason='new in 0.4.0')
102+
def test_rw_nthreads(self):
103+
104+
df = pd.DataFrame({'A': np.arange(100000)})
105+
self.check_round_trip(df, nthreads=2)
106+
101107
def test_write_with_index(self):
102108

103109
df = pd.DataFrame({'A': [1, 2, 3]})

0 commit comments

Comments
 (0)