Skip to content

Commit 82a3cb5

Browse files
committed
Add doc-strings to to_dataframe
1 parent 6d0f23d commit 82a3cb5

File tree

8 files changed

+195
-0
lines changed

8 files changed

+195
-0
lines changed

adaptive/learner/average_learner.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,30 @@ def to_dataframe(
8989
seed_name: str = "seed",
9090
y_name: str = "y",
9191
) -> pandas.DataFrame:
92+
"""Return the data as a `pandas.DataFrame`.
93+
94+
Parameters
95+
----------
96+
with_default_function_args : bool, optional
97+
Include the ``learner.function``'s default arguments as a
98+
column, by default True
99+
function_prefix : str, optional
100+
Prefix to the ``learner.function``'s default arguments' names,
101+
by default "function."
102+
seed_name : str, optional
103+
Name of the ``seed`` parameter, by default "seed"
104+
y_name : str, optional
105+
Name of the output value, by default "y"
106+
107+
Returns
108+
-------
109+
pandas.DataFrame
110+
111+
Raises
112+
------
113+
ImportError
114+
If `pandas` is not installed.
115+
"""
92116
if not with_pandas:
93117
raise ImportError("pandas is not installed.")
94118
df = pandas.DataFrame(sorted(self.data.items()), columns=[seed_name, y_name])

adaptive/learner/average_learner1D.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,32 @@ def to_dataframe(
157157
x_name: str = "x",
158158
y_name: str = "y",
159159
) -> pandas.DataFrame:
160+
"""Return the data as a `pandas.DataFrame`.
161+
162+
Parameters
163+
----------
164+
with_default_function_args : bool, optional
165+
Include the ``learner.function``'s default arguments as a
166+
column, by default True
167+
function_prefix : str, optional
168+
Prefix to the ``learner.function``'s default arguments' names,
169+
by default "function."
170+
seed_name : str, optional
171+
Name of the ``seed`` parameter, by default "seed"
172+
x_name : str, optional
173+
Name of the ``x`` parameter, by default "x"
174+
y_name : str, optional
175+
Name of the output value, by default "y"
176+
177+
Returns
178+
-------
179+
pandas.DataFrame
180+
181+
Raises
182+
------
183+
ImportError
184+
If `pandas` is not installed.
185+
"""
160186
if not with_pandas:
161187
raise ImportError("pandas is not installed.")
162188
if mean:

adaptive/learner/balancing_learner.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,22 @@ def from_product(cls, f, learner_type, learner_kwargs, combos):
390390
return cls(learners, cdims=arguments)
391391

392392
def to_dataframe(self, **kwargs):
393+
"""Return the data as a concatenated `pandas.DataFrame` from child learners.
394+
395+
Parameters
396+
----------
397+
**kwargs : dict
398+
Keyword arguments passed to each ``child_learner.to_dataframe(**kwargs)``.
399+
400+
Returns
401+
-------
402+
pandas.DataFrame
403+
404+
Raises
405+
------
406+
ImportError
407+
If `pandas` is not installed.
408+
"""
393409
if not with_pandas:
394410
raise ImportError("pandas is not installed.")
395411
dfs = [learner.to_dataframe(**kwargs) for learner in self.learners]

adaptive/learner/integrator_learner.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,32 @@ def to_dataframe(
565565
x_name: str = "x",
566566
y_name: str = "y",
567567
) -> pandas.DataFrame:
568+
"""Return the data as a `pandas.DataFrame`.
569+
570+
Parameters
571+
----------
572+
with_default_function_args : bool, optional
573+
Include the ``learner.function``'s default arguments as a
574+
column, by default True
575+
function_prefix : str, optional
576+
Prefix to the ``learner.function``'s default arguments' names,
577+
by default "function."
578+
seed_name : str, optional
579+
Name of the seed parameter, by default "seed"
580+
x_name : str, optional
581+
Name of the input value, by default "x"
582+
y_name : str, optional
583+
Name of the output value, by default "y"
584+
585+
Returns
586+
-------
587+
pandas.DataFrame
588+
589+
Raises
590+
------
591+
ImportError
592+
If `pandas` is not installed.
593+
"""
568594
if not with_pandas:
569595
raise ImportError("pandas is not installed.")
570596
df = pandas.DataFrame(sorted(self.data.items()), columns=[x_name, y_name])

adaptive/learner/learner1D.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,30 @@ def to_dataframe(
340340
x_name: str = "x",
341341
y_name: str = "y",
342342
) -> pandas.DataFrame:
343+
"""Return the data as a `pandas.DataFrame`.
344+
345+
Parameters
346+
----------
347+
with_default_function_args : bool, optional
348+
Include the ``learner.function``'s default arguments as a
349+
column, by default True
350+
function_prefix : str, optional
351+
Prefix to the ``learner.function``'s default arguments' names,
352+
by default "function."
353+
x_name : str, optional
354+
Name of the input value, by default "x"
355+
y_name : str, optional
356+
Name of the output value, by default "y"
357+
358+
Returns
359+
-------
360+
pandas.DataFrame
361+
362+
Raises
363+
------
364+
ImportError
365+
If `pandas` is not installed.
366+
"""
343367
if not with_pandas:
344368
raise ImportError("pandas is not installed.")
345369
xs, ys = zip(*sorted(self.data.items())) if self.data else ([], [])

adaptive/learner/learner2D.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,34 @@ def to_dataframe(
407407
y_name: str = "y",
408408
z_name: str = "z",
409409
) -> pandas.DataFrame:
410+
"""Return the data as a `pandas.DataFrame`.
411+
412+
Parameters
413+
----------
414+
with_default_function_args : bool, optional
415+
Include the ``learner.function``'s default arguments as a
416+
column, by default True
417+
function_prefix : str, optional
418+
Prefix to the ``learner.function``'s default arguments' names,
419+
by default "function."
420+
seed_name : str, optional
421+
Name of the seed parameter, by default "seed"
422+
x_name : str, optional
423+
Name of the input x value, by default "x"
424+
y_name : str, optional
425+
Name of the input y value, by default "y"
426+
z_name : str, optional
427+
Name of the output value, by default "z"
428+
429+
Returns
430+
-------
431+
pandas.DataFrame
432+
433+
Raises
434+
------
435+
ImportError
436+
If `pandas` is not installed.
437+
"""
410438
if not with_pandas:
411439
raise ImportError("pandas is not installed.")
412440
data = sorted((x, y, z) for (x, y), z in self.data.items())

adaptive/learner/learnerND.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,31 @@ def to_dataframe(
410410
point_names: tuple[str, ...] = ("x", "y", "z"),
411411
value_name: str = "value",
412412
) -> pandas.DataFrame:
413+
"""Return the data as a `pandas.DataFrame`.
414+
415+
Parameters
416+
----------
417+
with_default_function_args : bool, optional
418+
Include the ``learner.function``'s default arguments as a
419+
column, by default True
420+
function_prefix : str, optional
421+
Prefix to the ``learner.function``'s default arguments' names,
422+
by default "function."
423+
point_names : tuple[str, ...], optional
424+
Names of the input points, should be the same length as number
425+
of input parameters by default ("x", "y", "z" )
426+
value_name : str, optional
427+
Name of the output value, by default "value"
428+
429+
Returns
430+
-------
431+
pandas.DataFrame
432+
433+
Raises
434+
------
435+
ImportError
436+
If `pandas` is not installed.
437+
"""
413438
if not with_pandas:
414439
raise ImportError("pandas is not installed.")
415440
if len(point_names) != self.ndim:

adaptive/learner/sequence_learner.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,32 @@ def to_dataframe(
139139
x_name: str = "x",
140140
y_name: str = "y",
141141
) -> pandas.DataFrame:
142+
"""Return the data as a `pandas.DataFrame`.
143+
144+
Parameters
145+
----------
146+
with_default_function_args : bool, optional
147+
Include the ``learner.function``'s default arguments as a
148+
column, by default True
149+
function_prefix : str, optional
150+
Prefix to the ``learner.function``'s default arguments' names,
151+
by default "function."
152+
index_name : str, optional
153+
Name of the index parameter, by default "index"
154+
x_name : str, optional
155+
Name of the input value, by default "x"
156+
y_name : str, optional
157+
Name of the output value, by default "y"
158+
159+
Returns
160+
-------
161+
pandas.DataFrame
162+
163+
Raises
164+
------
165+
ImportError
166+
If `pandas` is not installed.
167+
"""
142168
if not with_pandas:
143169
raise ImportError("pandas is not installed.")
144170
indices, ys = zip(*self.data.items()) if self.data else ([], [])

0 commit comments

Comments
 (0)