diff --git a/bigframes/session/__init__.py b/bigframes/session/__init__.py index 2bc612bdbe..40831292de 100644 --- a/bigframes/session/__init__.py +++ b/bigframes/session/__init__.py @@ -916,6 +916,12 @@ def read_pandas(self, pandas_dataframe: pandas.DataFrame) -> dataframe.DataFrame def _read_pandas( self, pandas_dataframe: pandas.DataFrame, api_name: str ) -> dataframe.DataFrame: + if isinstance(pandas_dataframe, dataframe.DataFrame): + raise ValueError( + "read_pandas() expects a pandas.DataFrame, but got a " + "bigframes.pandas.DataFrame." + ) + if ( pandas_dataframe.size < MAX_INLINE_DF_SIZE # TODO(swast): Workaround data types limitation in inline data. diff --git a/tests/unit/session/test_io_pandas.py b/tests/unit/session/test_io_pandas.py index 959cccd80e..81d02466ef 100644 --- a/tests/unit/session/test_io_pandas.py +++ b/tests/unit/session/test_io_pandas.py @@ -13,7 +13,9 @@ # limitations under the License. import datetime +import re from typing import Dict, Union +import unittest.mock as mock import geopandas # type: ignore import numpy @@ -24,8 +26,11 @@ import pytest import bigframes.features +import bigframes.pandas import bigframes.session._io.pandas +from .. import resources + _LIST_OF_SCALARS = [ [1, 2, 3], [], @@ -475,3 +480,13 @@ def test_arrow_to_pandas_wrong_size_dtypes( ): with pytest.raises(ValueError, match=f"Number of types {len(dtypes)}"): bigframes.session._io.pandas.arrow_to_pandas(arrow_table, dtypes) + + +def test_read_pandas_with_bigframes_dataframe(): + session = resources.create_bigquery_session() + df = mock.create_autospec(bigframes.pandas.DataFrame, instance=True) + + with pytest.raises( + ValueError, match=re.escape("read_pandas() expects a pandas.DataFrame") + ): + session.read_pandas(df)