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

ENH: plotting methods can unpack labeled data #4829

Merged
merged 63 commits into from
Sep 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
367b68f
ENH: Make implicit x in plot pandas aware
tacaswell Jul 26, 2015
34b879a
ENH: plotting methods can unpack labeled data
tacaswell Jul 25, 2015
9f145cc
ENH: add white-list of args/kwargs to relpace
tacaswell Jul 26, 2015
a1c9c34
MNT: remove unused rcparam
tacaswell Jul 26, 2015
1e04469
MNT: python 2.6 does not support set literals
tacaswell Jul 27, 2015
d6e177f
ENH: pass at decorator which extracts a label
tacaswell Jul 28, 2015
8a77f90
FIX: fix typo, slightly rename variables
tacaswell Jul 29, 2015
dbd3445
FIX: fix yet more typos
tacaswell Jul 29, 2015
1ae230d
ENH: New version of unpack_labeled_data
jankatins Jul 30, 2015
ab6d39c
FIX: Update .gitignore for pycharm project files
jankatins Jul 30, 2015
6e29d39
ENH: proper arguments for labeled data decorator, part 1
jankatins Aug 2, 2015
f488bc7
ENH: let unpack_labeled_data handle var-length *args
jankatins Aug 2, 2015
1543cde
ENH: proper arguments for labeled data decorator, part 2
jankatins Aug 2, 2015
f4eea6e
FIX: handle 'enough' information about arg names in unpack_labeled_data
jankatins Aug 2, 2015
c4a6044
FIX: unbreak another corner case in unpack_labeled_data
jankatins Aug 3, 2015
4d1ffb8
FIX: fix unwarranted label argument for pie() with unpack_labeled_data
jankatins Aug 3, 2015
c78bb92
FIX: decorate funcs which take 2d data
jankatins Aug 3, 2015
d3331ca
ENH: change 'label_namer' default to None
jankatins Aug 3, 2015
ea3e22d
PEP8: fix some of the PEP8 problems in new code
jankatins Aug 3, 2015
3273673
PEP8: line wrapping fixes
tacaswell Aug 3, 2015
346a014
PEP8: more line length fixes
jankatins Aug 4, 2015
85d0e74
ENH: extract label from input data in `plot`
tacaswell Aug 7, 2015
1f36892
MNT: add a comment about label_naming in plot(...)
jankatins Aug 8, 2015
8dbb2cc
ENH: Append docs in @unpack_labeled_data
jankatins Aug 9, 2015
c768f0d
ENH: accept a function for arg names in @unpack_labeled_data
jankatins Aug 9, 2015
385b8e3
ENH: use the new 'names via function' for @unpack_labeled_data
jankatins Aug 9, 2015
812f74f
FIX: rename test file for @unpack_labeled_data
jankatins Aug 9, 2015
2194e80
FIX: assert_regexp_matches is only in py2.7
jankatins Aug 13, 2015
52d23c9
TST: workaround for unicode prefix in test matching
jankatins Aug 13, 2015
8aa800b
PEP8: line wrapping, spacing
jankatins Aug 13, 2015
ecc91e5
TST: workaround for unpredictable order in list printing
jankatins Aug 13, 2015
b09370e
WIP: review work
tacaswell Aug 20, 2015
0f781a1
TST: test the plot arg replacer directly
jankatins Aug 26, 2015
77be376
FIX: add proper replace_names for some plotting methods
jankatins Aug 26, 2015
7a39ef6
TST: add testcases for some decorated plot methods
jankatins Aug 26, 2015
a0c738e
MNT: regenerate pyplot to get the data kwarg
jankatins Aug 26, 2015
7a6d44d
MNT: make boilerplate.py a bit smarter
tacaswell Aug 27, 2015
bb4b9f7
MNT: add python 3 version of sig parsing
tacaswell Aug 27, 2015
9c1199b
ENH: add 'data' to signature in python 3.3 +
tacaswell Aug 27, 2015
47ff38a
MNT: python 2.6 compatibility fix
tacaswell Aug 27, 2015
00929b9
MNT: yet more compatibility fixes
tacaswell Aug 28, 2015
b6cb12f
ENH: add 'data' kwarg to pyplot
tacaswell Aug 28, 2015
25b1d43
TST: test pyplot.pie with a data kwarg
jankatins Aug 28, 2015
b4f011c
ENH: remove arbitrary long args if used with data
jankatins Aug 28, 2015
61eb622
FIX: small (non-code) fixups
jankatins Aug 31, 2015
e838a25
MNT: put test helper functions into their proper place
jankatins Aug 31, 2015
55ed86e
TST: Test with pandas installed on 2.7
jankatins Aug 31, 2015
9846b9c
DOC: Add a whatsnew entry for labeled data improvements
jankatins Aug 31, 2015
2b2092d
MNT: use IPython's signature if needed + available
tacaswell Sep 8, 2015
572c1e2
Merge pull request #4 from tacaswell/unpack_labeled_data_alternative
jankatins Sep 8, 2015
e2cf264
MNT: use already imported version variables
tacaswell Sep 9, 2015
67fda44
PRF: only try to use IPython if already imported
tacaswell Sep 9, 2015
59f3917
Merge pull request #5 from tacaswell/unpack_labeled_data_alternative
jankatins Sep 10, 2015
1c9feb8
FIX: guard signature import better
tacaswell Sep 11, 2015
1d00767
MNT: use built-in logic for unwrapping
tacaswell Sep 11, 2015
c454983
MNT: rename get_index_y -> index_of
tacaswell Sep 11, 2015
0d6cd40
MNT: enable unpacking on 2D inputs
tacaswell Sep 11, 2015
0734b86
MNT: invert logic of _has_varargs
tacaswell Sep 11, 2015
5fbe4b0
Merge pull request #6 from tacaswell/unpack_labeled_data_alternative
jankatins Sep 11, 2015
f34aed0
MNT: simplify identifying valid style codes
tacaswell Sep 12, 2015
a051b57
MNT: rearrange testing helper functions
tacaswell Sep 12, 2015
8271952
MNT: expose hist(..., weight='key') to data kwarg
tacaswell Sep 12, 2015
0b4fc7c
DOC: edits to whats_new entry
tacaswell Sep 12, 2015
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
.project
.pydevproject
.swp
.idea

# Compiled source #
###################
Expand Down
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ env:
- secure: "dfjNqGKzQG5bu3FnDNwLG8H/C4QoieFo4PfFmZPdM2RY7WIzukwKFNT6kiDfOrpwt+2bR7FhzjOGlDECGtlGOtYPN8XuXGjhcP4a4IfakdbDfF+D3NPIpf5VlE6776k0VpvcZBTMYJKNFIMc7QPkOwjvNJ2aXyfe3hBuGlKJzQU="
- BUILD_DOCS=false
- NUMPY=numpy
- PANDAS=
- NPROC=2
- TEST_ARGS=--no-pep8

Expand All @@ -36,7 +37,7 @@ matrix:
- python: 2.6
env: NUMPY=numpy==1.6 MOCK=mock==1.0.1
- python: 2.7
env: MOCK=mock
env: MOCK=mock PANDAS=pandas
- python: 3.3
- python: 3.4
- python: 2.7
Expand All @@ -62,7 +63,7 @@ install:
pip install --upgrade setuptools
# Install only from travis wheelhouse
- if [ -z "$PRE" ]; then
wheelhouse_pip_install python-dateutil $NUMPY pyparsing pillow sphinx!=1.3.0;
wheelhouse_pip_install python-dateutil $NUMPY $PANDAS pyparsing pillow sphinx!=1.3.0;
else
pip install $PRE python-dateutil $NUMPY pyparsing pillow sphinx!=1.3.0;
fi
Expand Down
28 changes: 27 additions & 1 deletion boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
itself, whereas the generatable content must be edited via templates in
this file.

This file is python 3 only due to the use of `inspect`
"""
# We did try to do the wrapping the smart way,
# with callable functions and new.function, but could never get the
Expand Down Expand Up @@ -209,7 +210,12 @@ def format_value(value):
mappable = ''

# Get argspec of wrapped function
args, varargs, varkw, defaults = inspect.getargspec(getattr(Axes, func))
base_func = getattr(Axes, func)
has_data = 'data' in inspect.signature(base_func).parameters
work_func = inspect.unwrap(base_func)

args, varargs, varkw, defaults = inspect.getargspec(work_func)

args.pop(0) # remove 'self' argument
if defaults is None:
defaults = ()
Expand All @@ -222,6 +228,15 @@ def format_value(value):
def_edited.append(val)
defaults = tuple(def_edited)

# Add a data keyword argument if needed (fmt is PLOT_TEMPLATE) and
# possible (if *args is used, we can't just add a data
# argument in front of it since it would gobble one of the
# arguments the user means to pass via *args)
# This needs to be done here so that it goes into call
if not varargs and fmt is PLOT_TEMPLATE and has_data:
args.append('data')
defaults = defaults + (None,)

# How to call the wrapped function
call = []
for i, arg in enumerate(args):
Expand All @@ -230,6 +245,14 @@ def format_value(value):
else:
call.append('%s=%s' % (arg, arg))

# remove the data keyword as it was needed above to go into the
# call but should go after `hold` in the signature.
# This is janky as all get out, but hopefully boilerplate will
# be retired soon.
if not varargs and fmt is PLOT_TEMPLATE and has_data:
args.pop()
defaults = defaults[:-1]

if varargs is not None:
call.append('*' + varargs)
if varkw is not None:
Expand All @@ -249,6 +272,9 @@ def format_value(value):
elif fmt is PLOT_TEMPLATE:
args.append('hold')
defaults = defaults + (None,)
if has_data:
args.append('data')
defaults = defaults + (None,)
sethold = ''

# Now we can build the argspec for defining the wrapper
Expand Down
36 changes: 36 additions & 0 deletions doc/users/whats_new/2015-07-30_unpack_labeled_data.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Working with labeled data like pandas DataFrames
------------------------------------------------
Plot methods which take arrays as inputs can now also work with labeled data
and unpack such data.

This means that the following two examples produce the same plot:

Example ::

df = pandas.DataFrame({"var1":[1,2,3,4,5,6], "var2":[1,2,3,4,5,6]})
plt.plot(df["var1"], df["var2"])


Example ::

plt.plot("var1", "var2", data=df)

This works for most plotting methods, which expect arrays/sequences as
inputs. ``data`` can be anything which supports ``__getitem__``
(``dict``, ``pandas.DataFrame``, ``h5py``, ...) to access ``array`` like
values with string keys.

In addition to this, some other changes were made, which makes working with
labeled data (ex ``pandas.Series``) easier:

* For plotting methods with ``label`` keyword argument, one of the
data inputs is designated as the label source. If the user does not
supply a ``label`` that value object will be introspected for a
label, currently by looking for a ``name`` attribute. If the value
object does not have a ``name`` attribute but was specified by as a
key into the ``data`` kwarg, then the key is used. In the above
examples, this results in an implicit ``label="var2"`` for both
cases.

* ``plot()`` now uses the index of a ``Series`` instead of
``np.arange(len(y))``, if no ``x`` argument is supplied.
Loading