mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 09:05:47 +08:00
Factor out deprecation logic
This commit is contained in:
1 parent
6b685406e3
commit
9639707600
4 files changed
+21
-27
No files matched your search
@@ -26,6 +26,8 @@ from pyarrow.compat import pdapi
|
||||
from pyarrow.lib import FeatherError # noqa
|
||||
from pyarrow.lib import RecordBatch, Table, concat_tables
|
||||
import pyarrow.lib as ext
|
||||
from .util import _deprecate_nthreads
|
||||
|
||||
|
||||
try:
|
||||
infer_dtype = pdapi.infer_dtype
|
||||
@@ -67,10 +69,7 @@ class FeatherReader(ext.FeatherReader):
|
||||
return table
|
||||
|
||||
def read_pandas(self, columns=None, nthreads=None, use_threads=False):
|
||||
if nthreads is not None:
|
||||
warnings.warn("`nthreads` argument is ignored, "
|
||||
"pass `use_threads` instead", FutureWarning,
|
||||
stacklevel=2)
|
||||
use_threads = _deprecate_nthreads(use_threads, nthreads)
|
||||
return self.read_table(columns=columns).to_pandas(
|
||||
use_threads=use_threads)
|
||||
|
||||
@@ -162,10 +161,7 @@ class FeatherDataset(object):
|
||||
pandas.DataFrame
|
||||
Content of the file as a pandas DataFrame (of columns)
|
||||
"""
|
||||
if nthreads is not None:
|
||||
warnings.warn("`nthreads` argument is ignored, "
|
||||
"pass `use_threads` instead", FutureWarning,
|
||||
stacklevel=2)
|
||||
use_threads = _deprecate_nthreads(use_threads, nthreads)
|
||||
return self.read_table(columns=columns).to_pandas(
|
||||
use_threads=use_threads)
|
||||
|
||||
@@ -213,10 +209,7 @@ def read_feather(source, columns=None, nthreads=None, use_threads=False):
|
||||
-------
|
||||
df : pandas.DataFrame
|
||||
"""
|
||||
if nthreads is not None:
|
||||
warnings.warn("`nthreads` argument is ignored, "
|
||||
"pass `use_threads` instead", FutureWarning,
|
||||
stacklevel=2)
|
||||
use_threads = _deprecate_nthreads(use_threads, nthreads)
|
||||
reader = FeatherReader(source)
|
||||
return reader.read_pandas(columns=columns, use_threads=use_threads)
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
|
||||
# Arrow file and stream reader/writer classes, and other messaging tools
|
||||
|
||||
import warnings
|
||||
|
||||
import pyarrow as pa
|
||||
|
||||
from pyarrow.lib import (Message, MessageReader, # noqa
|
||||
@@ -26,6 +24,7 @@ from pyarrow.lib import (Message, MessageReader, # noqa
|
||||
read_tensor, write_tensor,
|
||||
get_record_batch_size, get_tensor_size)
|
||||
import pyarrow.lib as lib
|
||||
from .util import _deprecate_nthreads
|
||||
|
||||
|
||||
class _ReadPandasOption(object):
|
||||
@@ -184,10 +183,7 @@ def deserialize_pandas(buf, nthreads=None, use_threads=False):
|
||||
-------
|
||||
df : pandas.DataFrame
|
||||
"""
|
||||
if nthreads is not None:
|
||||
warnings.warn("`nthreads` argument is ignored, "
|
||||
"pass `use_threads` instead", FutureWarning,
|
||||
stacklevel=2)
|
||||
use_threads = _deprecate_nthreads(use_threads, nthreads)
|
||||
|
||||
buffer_reader = pa.BufferReader(buf)
|
||||
reader = pa.RecordBatchStreamReader(buffer_reader)
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import warnings
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
@@ -28,6 +27,8 @@ except ImportError:
|
||||
else:
|
||||
import pyarrow.pandas_compat as pdcompat
|
||||
|
||||
from .util import _deprecate_nthreads
|
||||
|
||||
|
||||
cdef class ChunkedArray:
|
||||
"""
|
||||
@@ -755,10 +756,7 @@ cdef class RecordBatch:
|
||||
-------
|
||||
pandas.DataFrame
|
||||
"""
|
||||
if nthreads is not None:
|
||||
warnings.warn("`nthreads` argument is ignored, "
|
||||
"pass `use_threads` instead", FutureWarning,
|
||||
stacklevel=2)
|
||||
use_threads = _deprecate_nthreads(use_threads, nthreads)
|
||||
return Table.from_batches([self]).to_pandas(use_threads=use_threads)
|
||||
|
||||
@classmethod
|
||||
@@ -1180,10 +1178,7 @@ cdef class Table:
|
||||
cdef:
|
||||
PandasOptions options
|
||||
|
||||
if nthreads is not None:
|
||||
warnings.warn("`nthreads` argument is ignored, "
|
||||
"pass `use_threads` instead", FutureWarning,
|
||||
stacklevel=2)
|
||||
use_threads = _deprecate_nthreads(use_threads, nthreads)
|
||||
|
||||
options = PandasOptions(
|
||||
strings_to_categorical=strings_to_categorical,
|
||||
|
||||
@@ -35,3 +35,13 @@ def _deprecate_api(old_name, new_name, api, next_version):
|
||||
warnings.warn(msg, FutureWarning)
|
||||
return api(*args)
|
||||
return wrapper
|
||||
|
||||
|
||||
def _deprecate_nthreads(use_threads, nthreads):
|
||||
if nthreads is not None:
|
||||
warnings.warn("`nthreads` argument is deprecated, "
|
||||
"pass `use_threads` instead", FutureWarning,
|
||||
stacklevel=3)
|
||||
if nthreads > 1:
|
||||
use_threads = True
|
||||
return use_threads
|
||||
Reference in new issue
Block a user