Skip to content

Commit 71695fc

Browse files
committed
Add tests for basic plot input variable parsing
1 parent a00eb2a commit 71695fc

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

doc/releases/v0.9.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
v0.9.0 (Unreleased)
33
-------------------
44

5-
- Final removal of the previously-deprecated ``coefcplot`` and ``interactplot`` functions.
5+
- Final removal of the previously-deprecated ``coefplot`` and ``interactplot`` functions.
66

77
- Updated the testing infrastructure to execute tests with `pytest <https://docs.pytest.org/en/latest/>` (although many individual tests still use nose assertion).

seaborn/basic.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,35 @@ def establish_variables(self, x=None, y=None,
4444
# We will assign the index to x, the values to y,
4545
# and the columns names to both hue and style
4646

47+
# TODO accept a dict and try to coerce to a dataframe?
48+
4749
if isinstance(data, pd.DataFrame):
4850

4951
# Enforce numeric values
5052
try:
5153
data.astype(np.float)
5254
except ValueError:
53-
raise ValueError("A wide-form dataframe must have only "
54-
"numeric values.")
55+
err = "A wide-form input must have only numeric values."
56+
raise ValueError(err)
5557

5658
plot_data = pd.melt(data.assign(x=data.index), "x",
5759
var_name="hue", value_name="y")
5860
plot_data["style"] = plot_data["hue"]
5961

60-
# TODO accept a dict and try to coerce to a dataframe?
61-
6262
# Option 1b:
6363
# The input data is an array or list
6464
# ----------------------------------
6565

6666
else:
6767

68-
if hasattr(data, "shape"):
68+
if np.isscalar(data[0]):
69+
70+
# The input data is a flat list(like):
71+
# We assign a numeric index for x and use the values for y
72+
73+
plot_data = pd.DataFrame(dict(x=np.arange(len(data)),
74+
y=data))
75+
elif hasattr(data, "shape"):
6976

7077
# The input data is an array(like):
7178
# We assign a numeric index to x, the values to y, and
@@ -77,18 +84,10 @@ def establish_variables(self, x=None, y=None,
7784
var_name="hue", value_name="y")
7885
plot_data["style"] = plot_data["hue"]
7986

80-
elif np.isscalar(data[0]):
81-
82-
# The input data is a flat list(like):
83-
# We assign a numeric index for x and use the values for y
84-
85-
plot_data = pd.DataFrame(dict(x=np.arange(len(data)),
86-
y=data))
87-
8887
else:
8988

9089
# The input data is a nested list: We will assign a numeric
91-
# index for x, use the values for, y and use numieric
90+
# index for x, use the values for, y and use numeric
9291
# hue/style identifiers for each entry.
9392

9493
plot_data = pd.concat([

0 commit comments

Comments
 (0)