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

SNOW-1635365: Update snowpark pandas imports in method documentation #2204

Merged
merged 5 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/snowflake/snowpark/modin/pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
value_counts,
wide_to_long,
)
from snowflake.snowpark.modin.pandas.io import (
from snowflake.snowpark.modin.pandas.io import ( # read_json is provided by overrides module
ExcelFile,
HDFStore,
json_normalize,
Expand All @@ -132,7 +132,6 @@
read_gbq,
read_hdf,
read_html,
read_json,
read_orc,
read_parquet,
read_pickle,
Expand Down Expand Up @@ -162,6 +161,7 @@
Index,
DatetimeIndex,
TimedeltaIndex,
read_json,
)

# this must occur before overrides are applied
Expand Down
37 changes: 2 additions & 35 deletions src/snowflake/snowpark/modin/pandas/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
Manually add documentation for methods which are not presented in pandas.
"""

# TODO SNOW-1650875: remove this file since we define everything in pd_overrides.py

from __future__ import annotations

import csv
Expand Down Expand Up @@ -91,7 +93,6 @@
# below logic is to handle circular imports without errors
if TYPE_CHECKING: # pragma: no cover
from .dataframe import DataFrame
from .series import Series

# TODO: SNOW-1265551: add inherit_docstrings decorators once docstring overrides are available

Expand Down Expand Up @@ -359,39 +360,6 @@ def read_parquet(
)


# TODO: SNOW-1265551: add inherit_docstrings decorators once docstring overrides are available
@snowpark_pandas_telemetry_standalone_function_decorator
@expanduser_path_arg("path_or_buf")
def read_json(
path_or_buf,
*,
orient: str | None = None,
typ: Literal["frame", "series"] = "frame",
dtype: DtypeArg | None = None,
convert_axes=None,
convert_dates: bool | list[str] = True,
keep_default_dates: bool = True,
precise_float: bool = False,
date_unit: str | None = None,
encoding: str | None = None,
encoding_errors: str | None = "strict",
lines: bool = False,
chunksize: int | None = None,
compression: CompressionOptions = "infer",
nrows: int | None = None,
storage_options: StorageOptions = None,
dtype_backend: DtypeBackend | NoDefault = no_default,
engine="ujson",
) -> DataFrame | Series | pandas.io.json._json.JsonReader: # pragma: no cover: this function is overridden by plugin/pd_overrides.py
_, _, _, kwargs = inspect.getargvalues(inspect.currentframe())

from snowflake.snowpark.modin.core.execution.dispatching.factories.dispatcher import (
FactoryDispatcher,
)

return ModinObjects.DataFrame(query_compiler=FactoryDispatcher.read_json(**kwargs))


@_inherit_docstrings(pandas.read_gbq, apilink="pandas.read_gbq")
@snowpark_pandas_telemetry_standalone_function_decorator
def read_gbq(
Expand Down Expand Up @@ -1145,7 +1113,6 @@ def to_numpy(
"read_gbq",
"read_hdf",
"read_html",
"read_json",
"read_orc",
"read_parquet",
"read_pickle",
Expand Down
1 change: 0 additions & 1 deletion src/snowflake/snowpark/modin/plugin/docstrings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,6 @@ def nunique():

Examples
--------
>>> import snowflake.snowpark.modin.pandas as pd
>>> df = pd.DataFrame({'A': [4, 5, 6], 'B': [4, 1, 1]})
>>> df.nunique()
A 3
Expand Down
1 change: 0 additions & 1 deletion src/snowflake/snowpark/modin/plugin/docstrings/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3800,7 +3800,6 @@ def nunique():

Examples
--------
>>> import snowflake.snowpark.modin.pandas as pd
>>> import numpy as np
>>> s = pd.Series([1, 3, 5, 7, 7])
>>> s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def read_snowflake(
will have a default index from 0 to n-1, where n is the number of rows in the table,
and have all columns in the Snowflake table as data columns.

>>> import snowflake.snowpark.modin.pandas as pd
>>> import modin.pandas as pd
>>> import snowflake.snowpark.modin.plugin
>>> pd.read_snowflake(table_name) # doctest: +NORMALIZE_WHITESPACE
A B C
0 1 2 3
Expand Down Expand Up @@ -171,7 +172,8 @@ def read_snowflake(
- When ``index_col`` is not specified, a Snowpark pandas DataFrame
will have a default index from 0 to n-1, where n is the number of rows in the table.

>>> import snowflake.snowpark.modin.pandas as pd
>>> import modin.pandas as pd
>>> import snowflake.snowpark.modin.plugin
>>> pd.read_snowflake(f"SELECT * FROM {table_name}") # doctest: +NORMALIZE_WHITESPACE
A B C
0 1 2 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ def read_csv(
>>> with open(f'{temp_dir_name}/data.csv', 'w') as f:
... writer = csv.writer(f)
... writer.writerows([['c1','c2','c3'], [1,2,3], [4,5,6], [7,8,9]])
>>> import snowflake.snowpark.modin.pandas as pd
>>> import modin.pandas as pd
>>> import snowflake.snowpark.modin.plugin
>>> df = pd.read_csv(f'{temp_dir_name}/data.csv')
>>> df
c1 c2 c3
Expand Down Expand Up @@ -369,7 +370,7 @@ def read_json(
path_or_buf: FilePath,
*,
orient: Optional[str] = None,
typ: Optional[Literal["frame", "series"]] = None,
typ: Optional[Literal["frame", "series"]] = "frame",
sfc-gh-azhan marked this conversation as resolved.
Show resolved Hide resolved
dtype: Optional[DtypeArg] = None,
convert_axes: Optional[bool] = None,
convert_dates: Optional[Union[bool, list[str]]] = None,
Expand Down Expand Up @@ -489,7 +490,8 @@ def read_json(
>>> with open(f'{temp_dir_name}/snowpark_pandas.json', 'w') as f:
... json.dump(data, f)

>>> import snowflake.snowpark.modin.pandas as pd
>>> import modin.pandas as pd
>>> import snowflake.snowpark.modin.plugin
>>> df = pd.read_json(f'{temp_dir_name}/snowpark_pandas.json')
>>> df
A B C
Expand Down
4 changes: 2 additions & 2 deletions src/snowflake/snowpark/modin/plugin/io/snow_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def read_json(
path_or_buf: FilePath,
*,
orient: Optional[str] = None,
typ: Optional[Literal["frame", "series"]] = None,
typ: Optional[Literal["frame", "series"]] = "frame",
dtype: Optional[DtypeArg] = None,
convert_axes: Optional[bool] = None,
convert_dates: Optional[Union[bool, list[str]]] = None,
Expand Down Expand Up @@ -463,7 +463,7 @@ def read_json(
)

error_not_implemented_parameter("orient", orient is not None)
error_not_implemented_parameter("typ", typ is not None)
error_not_implemented_parameter("typ", typ != "frame")
error_not_implemented_parameter("dtype", dtype is not None)
error_not_implemented_parameter("convert_axes", convert_axes is not None)
error_not_implemented_parameter("convert_dates", convert_dates is not None)
Expand Down
2 changes: 1 addition & 1 deletion tests/integ/modin/io/test_read_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def test_read_json_malformed_file_negative():
"parameter, argument",
[
("orient", "records"),
("typ", "frame"),
("typ", "series"),
("dtype", True),
("convert_axes", True),
("convert_dates", True),
Expand Down
Loading