Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: deprecate ReadRowsStream.to_dataframe, ReadRowsIterable.to_arrow, ReadRowsIterable.to_dataframe, ReadRowsStream.to_arrow #247

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
# directories to ignore when looking for source files.
exclude_patterns = [
"_build",
"**/.nox/**/*",
"samples/AUTHORING_GUIDE.md",
"samples/CONTRIBUTING.md",
"samples/snippets/README.rst",
Expand Down
48 changes: 44 additions & 4 deletions google/cloud/bigquery_storage_v1/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import collections
import json
import warnings

try:
import fastavro
Expand Down Expand Up @@ -189,11 +190,14 @@ def rows(self, read_session=None):
return ReadRowsIterable(self, read_session=read_session)

def to_arrow(self, read_session=None):
"""Create a :class:`pyarrow.Table` of all rows in the stream.
"""DEPRECATED. Create a :class:`pyarrow.Table` of all rows in the stream.

This method requires the pyarrow library and a stream using the Arrow
format.

.. deprecated:: 2.7.0
Use :func:`ReadRowsPage.to_arrow`, instead.

Args:
read_session ( \
~google.cloud.bigquery_storage_v1.types.ReadSession \
Expand All @@ -208,10 +212,16 @@ def to_arrow(self, read_session=None):
pyarrow.Table:
A table of all rows in the stream.
"""
warnings.warn(
"ReadRowsStream.to_arrow() is deprecated. "
"Use [page.to_arrow() for page in ReadRowsStream.rows().pages], instead.",
DeprecationWarning,
stacklevel=2,
)
return self.rows(read_session=read_session).to_arrow()

def to_dataframe(self, read_session=None, dtypes=None):
"""Create a :class:`pandas.DataFrame` of all rows in the stream.
"""DEPRECATED. Create a :class:`pandas.DataFrame` of all rows in the stream.

This method requires the pandas libary to create a data frame and the
fastavro library to parse row messages.
Expand All @@ -220,6 +230,9 @@ def to_dataframe(self, read_session=None, dtypes=None):
DATETIME columns are not supported. They are currently parsed as
strings.

.. deprecated:: 2.7.0
Use :func:`ReadRowsPage.to_dataframe`, instead.

Args:
read_session ( \
~google.cloud.bigquery_storage_v1.types.ReadSession \
Expand All @@ -244,6 +257,13 @@ def to_dataframe(self, read_session=None, dtypes=None):
if pandas is None:
raise ImportError(_PANDAS_REQUIRED)

warnings.warn(
"ReadRowsStream.to_dataframe() is deprecated. "
"Use [page.to_dataframe() for page in ReadRowsStream.rows().pages], instead.",
DeprecationWarning,
stacklevel=2,
)

return self.rows(read_session=read_session).to_dataframe(dtypes=dtypes)


Expand Down Expand Up @@ -297,15 +317,25 @@ def __iter__(self):
yield row

def to_arrow(self):
"""Create a :class:`pyarrow.Table` of all rows in the stream.
"""DEPRECATED: Create a :class:`pyarrow.Table` of all rows in the stream.

This method requires the pyarrow library and a stream using the Arrow
format.

.. deprecated:: 2.7.0
Use :func:`ReadRowsPage.to_arrow`, instead.

Returns:
pyarrow.Table:
A table of all rows in the stream.
"""
warnings.warn(
"ReadRowsIterable.to_arrow() is deprecated. "
"Use [page.to_arrow() for page in ReadRowsIterable.pages], instead.",
DeprecationWarning,
stacklevel=2,
)

record_batches = []
for page in self.pages:
record_batches.append(page.to_arrow())
Expand All @@ -318,7 +348,7 @@ def to_arrow(self):
return pyarrow.Table.from_batches([], schema=self._stream_parser._schema)

def to_dataframe(self, dtypes=None):
"""Create a :class:`pandas.DataFrame` of all rows in the stream.
"""DEPRECATED: Create a :class:`pandas.DataFrame` of all rows in the stream.

This method requires the pandas libary to create a data frame and the
fastavro library to parse row messages.
Expand All @@ -327,6 +357,9 @@ def to_dataframe(self, dtypes=None):
DATETIME columns are not supported. They are currently parsed as
strings in the fastavro library.

.. deprecated:: 2.7.0
Use :func:`ReadRowsPage.to_dataframe`, instead.

Args:
dtypes ( \
Map[str, Union[str, pandas.Series.dtype]] \
Expand All @@ -343,6 +376,13 @@ def to_dataframe(self, dtypes=None):
if pandas is None:
raise ImportError(_PANDAS_REQUIRED)

warnings.warn(
"ReadRowsIterable.to_dataframe() is deprecated. "
"Use [page.to_dataframe() for page in ReadRowsIterable.pages], instead.",
DeprecationWarning,
stacklevel=2,
)

if dtypes is None:
dtypes = {}

Expand Down