Skip to content

Commit

Permalink
FIX incorrect output in the example; minor rewording
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannz committed Dec 30, 2021
1 parent 9a3c301 commit 45a3962
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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(
Expand All @@ -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.
Expand Down Expand Up @@ -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.

0 comments on commit 45a3962

Please sign in to comment.