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

Move docs to docstrings and generate documentation with sphinx-autodoc #367

Merged
merged 5 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Copy documentation from api.rst to docstrings
  • Loading branch information
Priyansh121096 committed Oct 10, 2024
commit 0a1b25930feef97964bfff08c37698b0c31c650f
26 changes: 23 additions & 3 deletions src/pantab/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ def frame_from_hyper_query(
return_type: Literal["pandas", "polars", "pyarrow"] = "pandas",
process_params: Optional[dict[str, str]] = None,
):
"""See api.rst for documentation."""
"""
Executes a SQL query and returns the result as a pandas dataframe

:param source: Name / location of the Hyper file to be read or Hyper-API connection.
:param query: SQL query to execute.
:param return_type: The type of DataFrame to be returned
:param process_params: Parameters to pass to the Hyper Process constructor.
"""
if process_params is None:
process_params = {}

Expand Down Expand Up @@ -44,7 +51,14 @@ def frame_from_hyper(
return_type: Literal["pandas", "polars", "pyarrow"] = "pandas",
process_params: Optional[dict[str, str]] = None,
):
"""See api.rst for documentation"""
"""
Extracts a DataFrame from a .hyper extract.

:param source: Name / location of the Hyper file to be read or Hyper-API connection.
:param table: Table to read.
:param return_type: The type of DataFrame to be returned
:param process_params: Parameters to pass to the Hyper Process constructor.
"""
if isinstance(table, (pt_types.TableauName, pt_types.TableauTableName)):
tbl = str(table)
elif isinstance(table, tuple):
Expand All @@ -65,7 +79,13 @@ def frames_from_hyper(
return_type: Literal["pandas", "polars", "pyarrow"] = "pandas",
process_params: Optional[dict[str, str]] = None,
):
"""See api.rst for documentation."""
"""
Extracts tables from a .hyper extract.

:param source: Name / location of the Hyper file to be read or Hyper-API connection.
:param return_type: The type of DataFrame to be returned
:param process_params: Parameters to pass to the Hyper Process constructor.
"""
result = {}

table_names = libpantab.get_table_names(str(source))
Expand Down
25 changes: 23 additions & 2 deletions src/pantab/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ def frame_to_hyper(
geo_columns: Optional[set[str]] = None,
process_params: Optional[dict[str, str]] = None,
) -> None:
"""See api.rst for documentation"""
"""
Convert a DataFrame to a .hyper extract.

:param df: Data to be written out.
:param database: Name / location of the Hyper file to write to.
:param table: Table to write to.
:param table_mode: The mode to open the table with. Default is "w" for write, which truncates the file before writing. Another option is "a", which will append data to the file if it already contains information.
:param not_null_columns: Columns which should be considered "NOT NULL" in the target Hyper database. By default, all columns are considered nullable
:param json_columns: Columns to be written as a JSON data type
:param geo_columns: Columns to be written as a GEOGRAPHY data type
:param process_params: Parameters to pass to the Hyper Process constructor.
"""
frames_to_hyper(
{table: df},
database,
Expand All @@ -79,7 +90,17 @@ def frames_to_hyper(
geo_columns: Optional[set[str]] = None,
process_params: Optional[dict[str, str]] = None,
) -> None:
"""See api.rst for documentation."""
"""
Writes multiple DataFrames to a .hyper extract.

:param dict_of_frames: A dictionary whose keys are valid table identifiers and values are dataframes
:param database: Name / location of the Hyper file to write to.
:param table_mode: The mode to open the table with. Default is "w" for write, which truncates the file before writing. Another option is "a", which will append data to the file if it already contains information.
:param not_null_columns: Columns which should be considered "NOT NULL" in the target Hyper database. By default, all columns are considered nullable
:param json_columns: Columns to be written as a JSON data type
:param geo_columns: Columns to be written as a GEOGRAPHY data type
:param process_params: Parameters to pass to the Hyper Process constructor.
"""
_validate_table_mode(table_mode)

if not_null_columns is None:
Expand Down