Skip to content

Commit

Permalink
Documentation in data module
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Jun 19, 2021
1 parent d74205f commit 96e8d25
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions seaborn/_core/data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Components for parsing variable assignments and internally representing plot data.
"""
from __future__ import annotations

from collections import abc
Expand All @@ -9,8 +12,33 @@
from seaborn._core.typing import DataSource, VariableSpec


# TODO Repetition in the docstrings should be reduced with interpolation tools

class PlotData:
"""Data table with plot variable schema and mapping to original names."""
"""
Data table with plot variable schema and mapping to original names.
Contains logic for parsing variable specification arguments and updating
the table with layer-specific data and/or mappings.
Parameters
----------
data
Input data where variable names map to vector values.
variables
Keys are names of plot variables (x, y, ...) each value is one of:
- name of a column (or index level, or dictionary entry) in `data`
- vector in any format that can construct a :class:`pandas.DataFrame`
Attributes
----------
frame
Data table with column names having defined plot variables.
names
Dictionary mapping plot variable names to names in source data structure(s).
"""
frame: DataFrame
names: dict[str, str | None]
_source: DataSource
Expand Down Expand Up @@ -73,21 +101,22 @@ def _assign_variables(
variables: dict[str, VariableSpec],
) -> tuple[DataFrame, dict[str, str | None]]:
"""
Define plot variables given long-form data and/or vector inputs.
Assign values for plot variables given long-form data and/or vector inputs.
Parameters
----------
data
Input data where variable names map to vector values.
variables
Keys are seaborn variables (x, y, hue, ...) and values are vectors
in any format that can construct a :class:`pandas.DataFrame` or
names of columns or index levels in ``data``.
Keys are names of plot variables (x, y, ...) each value is one of:
- name of a column (or index level, or dictionary entry) in `data`
- vector in any format that can construct a :class:`pandas.DataFrame`
Returns
-------
frame
Dataframe mapping seaborn variables (x, y, hue, ...) to data vectors.
Table mapping seaborn variables (x, y, hue, ...) to data vectors.
names
Keys are defined seaborn variables; values are names inferred from
the inputs (or None when no name can be determined).
Expand Down Expand Up @@ -179,7 +208,7 @@ def _assign_variables(
# types automatically, aligning on index in case of pandas objects
frame = pd.DataFrame(plot_data)

# Reduce the variables dictionary to fields with valid data
# Build the mapping from plot variables to original names (if available)
names = {
var: name
for var, name in var_names.items()
Expand Down

0 comments on commit 96e8d25

Please sign in to comment.