Skip to content

Commit

Permalink
SNOW-1635365: Update snowpark pandas imports in method documentation (#…
Browse files Browse the repository at this point in the history
…2204)

<!---
Please answer these questions before creating your pull request. Thanks!
--->

1. Which Jira issue is this PR addressing? Make sure that there is an
accompanying issue to your PR.

   <!---
   In this section, please add a Snowflake Jira issue number.
   
Note that if a corresponding GitHub issue exists, you should still
include
   the Snowflake Jira issue number. For example, for GitHub issue
#1400, you should
   add "SNOW-1335071" here.
    --->

   Fixes SNOW-1635365 (resolves #2139)

2. Fill out the following pre-review checklist:

- [ ] I am adding a new automated test(s) to verify correctness of my
new code
- [ ] If this test skips Local Testing mode, I'm requesting review from
@snowflakedb/local-testing
   - [ ] I am adding new logging messages
   - [ ] I am adding a new telemetry message
   - [ ] I am adding new credentials
   - [ ] I am adding a new dependency
- [ ] If this is a new feature/behavior, I'm adding the Local Testing
parity changes.

3. Please describe how your code solves the related issue.

A few methods in documentation had an outdated import method for
Snowpark pandas (`import snowflake.snowpark.modin.pandas as pd`). This
PR updates docstrings to use the correct method (`import modin.pandas as
pd; import snowflake.snowpark.modin.plugin`).
  • Loading branch information
sfc-gh-joshi authored Sep 5, 2024
1 parent 5dcf20b commit 3a2f1a1
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 47 deletions.
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 @@ -122,7 +122,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 @@ -134,7 +134,6 @@
read_gbq,
read_hdf,
read_html,
read_json,
read_orc,
read_parquet,
read_pickle,
Expand Down Expand Up @@ -164,6 +163,7 @@
Index,
DatetimeIndex,
TimedeltaIndex,
read_json,
)

# Record which attributes are defined on an upstream object, and which are defined on a vendored
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 @@ -3792,7 +3792,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",
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

0 comments on commit 3a2f1a1

Please sign in to comment.