From 45a39623cecdbdc8ee87eb9d5d3512e45b030c79 Mon Sep 17 00:00:00 2001 From: Ivan Nazarov Date: Thu, 30 Dec 2021 16:22:30 +0300 Subject: [PATCH] FIX incorrect output in the example; minor rewording --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1a01d6b..83fb500 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ language](https://www.r-project.org/), which streamlines dataframe and vector/ma transformations. -## Example +## the Essential Example Below we provide an example, which, we hope, illustrates the cases `plyr` might be useful in. @@ -25,11 +25,11 @@ nt = namedtuple('nt', 'u,v') # add the leaf data in a pair of nested objects plyr.apply( lambda u, v: u + v, - [{'a': (1, 2, 3), 'z': 3.1415}, nt(1, 'abc')], - [{'a': (4, 6, 8), 'z': 2.7128}, nt(4, 'xyz')], + [{'a': (1, 2, 3), 'z': 3.1415}, nt([1, 'u'], 'abc')], + [{'a': (4, 6, 8), 'z': 2.7128}, nt([4, 'v'], 'xyz')], # _star=True, # (default) call fn(d1, d2, **kwargs) ) -# output: [{'a': [5, 8, 11]}, {'b': 5, 'z': 'abcxyz'}] +# output: [{'a': (5, 8, 11), 'z': 5.8543}, nt(u=[5, 'uv'], v='abcxyz')] # join strings in a pair of tuples plyr.apply( @@ -47,7 +47,7 @@ these integrity checks may be turned off by specifying `_safe=False`. Please ref to the docs of `plyr.apply`. -## Other examples +## Other Examples Below we perform something fancy with `numpy`. Specifically, we stack outputs from some experiments (dicts of arrays), to get the standard deviation between the results. @@ -79,5 +79,6 @@ shapes = plyr.apply(lambda x: x.shape, res) plyr.apply(np.std, res, axis=0) ``` -You may notice that `.apply` is very _straightforward_: it applies the specified function -regardless of the leaf data type. +You may notice that `.apply` is very _unsophisticated_: it applies the specified function +to the leaf data regardless of its type, and every dict, list, or tuple is _always_ treated +as a nested container.