Skip to content

TYP: add some types to pandas/io/parquet.py #29972

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

Merged
merged 1 commit into from
Dec 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions pandas/io/parquet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" parquet compat """

from typing import Any, Dict, Optional
from warnings import catch_warnings

from pandas.compat._optional import import_optional_dependency
Expand All @@ -10,7 +11,7 @@
from pandas.io.common import get_filepath_or_buffer, is_gcs_url, is_s3_url


def get_engine(engine):
def get_engine(engine: str) -> "BaseImpl":
""" return our implementation """

if engine == "auto":
Expand All @@ -35,19 +36,15 @@ def get_engine(engine):
"support"
)

if engine not in ["pyarrow", "fastparquet"]:
raise ValueError("engine must be one of 'pyarrow', 'fastparquet'")

if engine == "pyarrow":
return PyArrowImpl()
elif engine == "fastparquet":
return FastParquetImpl()

raise ValueError("engine must be one of 'pyarrow', 'fastparquet'")

class BaseImpl:

api = None # module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just unused?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't appear to be necessary to be declared here. not used by the BaseImpl methods so not technically a mandatory property.

mypy errors were

pandas\io\parquet.py:101: error: "None" has no attribute "Table"
pandas\io\parquet.py:103: error: "None" has no attribute "parquet"
pandas\io\parquet.py:112: error: "None" has no attribute "parquet"


class BaseImpl:
@staticmethod
def validate_dataframe(df):

Expand All @@ -74,7 +71,7 @@ def read(self, path, columns=None, **kwargs):

class PyArrowImpl(BaseImpl):
def __init__(self):
pyarrow = import_optional_dependency(
import_optional_dependency(
"pyarrow", extra="pyarrow is required for parquet support."
)
import pyarrow.parquet
Expand All @@ -87,13 +84,14 @@ def write(
path,
compression="snappy",
coerce_timestamps="ms",
index=None,
index: Optional[bool] = None,
partition_cols=None,
**kwargs,
):
self.validate_dataframe(df)
path, _, _, _ = get_filepath_or_buffer(path, mode="wb")

from_pandas_kwargs: Dict[str, Any]
if index is None:
from_pandas_kwargs = {}
else:
Expand Down Expand Up @@ -203,7 +201,7 @@ def to_parquet(
path,
engine="auto",
compression="snappy",
index=None,
index: Optional[bool] = None,
partition_cols=None,
**kwargs,
):
Expand Down