Repository: ownaginatious/mixpanel-jql

Issue:
mixpanel_jql.exceptions.InvalidJavaScriptText
Hi, first of all thanks for this project!

I'm trying to run the first example and I'm getting:
`mixpanel_jql.exceptions.InvalidJavaScriptText: Must be a text type (str, unicode) or wrapped as raw(str||unicode)`

I'm runnning Python 3.6.5 on Ubuntu 18.04

Discussion:
codecov-io: # [Codecov](https://codecov.io/gh/ownaginatious/mixpanel-jql/pull/18?src=pr&el=h1) Report
> Merging [#18](https://codecov.io/gh/ownaginatious/mixpanel-jql/pull/18?src=pr&el=desc) into [master](https://codecov.io/gh/ownaginatious/mixpanel-jql/commit/cad22fecf6220e3857dec5de122c8df8810c9737?src=pr&el=desc) will **increase** coverage by `0.04%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/ownaginatious/mixpanel-jql/pull/18/graphs/tree.svg?width=650&token=xJsxO2WgJp&height=150&src=pr)](https://codecov.io/gh/ownaginatious/mixpanel-jql/pull/18?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #18      +/-   ##
==========================================
+ Coverage   87.08%   87.13%   +0.04%     
==========================================
  Files           2        2              
  Lines         271      272       +1     
  Branches       71       70       -1     
==========================================
+ Hits          236      237       +1     
  Misses         24       24              
  Partials       11       11
```


| [Impacted Files](https://codecov.io/gh/ownaginatious/mixpanel-jql/pull/18?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [mixpanel\_jql/query.py](https://codecov.io/gh/ownaginatious/mixpanel-jql/pull/18/diff?src=pr&el=tree#diff-bWl4cGFuZWxfanFsL3F1ZXJ5LnB5) | `86.94% <100%> (+0.04%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/ownaginatious/mixpanel-jql/pull/18?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/ownaginatious/mixpanel-jql/pull/18?src=pr&el=footer). Last update [cad22fe...cc5066a](https://codecov.io/gh/ownaginatious/mixpanel-jql/pull/18?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/mixpanel_jql/query.py b/mixpanel_jql/query.py
index 919894f..768da83 100644
--- a/mixpanel_jql/query.py
+++ b/mixpanel_jql/query.py
@@ -394,19 +394,19 @@ class JQL(object):
         return jql
 
     def group_by(self, keys, accumulator):
-        if not isinstance(keys, (tuple, set, list)):
-            keys = [keys]
-        jql = self._clone()
-        jql.operations += ("groupBy([%s], %s)"
-                           % (", ".join(_f(k) for k in keys), _f(accumulator)),)
-        return jql
+        return self._group_by(False, keys, accumulator)
 
     def group_by_user(self, keys, accumulator):
+        return self._group_by(True, keys, accumulator)
+
+    def _group_by(self, user, keys, accumulator):
         if not isinstance(keys, (tuple, set, list)):
             keys = [keys]
+        if not isinstance(accumulator, Reducer):
+            accumulator = _f(accumulator)
         jql = self._clone()
-        jql.operations += ("groupByUser([%s], %s)"
-                           % (", ".join(_f(k) for k in keys), _f(accumulator)),)
+        op = "groupByUser" if user else "groupBy"
+        jql.operations += ("%s([%s], %s)" % (op, ", ".join(_f(k) for k in keys), accumulator),)
         return jql
 
     def query_plan(self):


Test patch:
diff --git a/tests/test_transformations.py b/tests/test_transformations.py
index f66c218..e7f3dfc 100644
--- a/tests/test_transformations.py
+++ b/tests/test_transformations.py
@@ -63,6 +63,12 @@ class TestGroupTransformations(unittest.TestCase):
             'function main() { return Events({}).'
             '%s([e.a, e.b, e.c], e.properties.some_accessor); }' % expected_function)
 
+        self.assertEqual(
+            str(grouper([
+                raw('e.a'), raw('e.b'), raw('e.c')], Reducer.count())),
+            'function main() { return Events({}).'
+            '%s([e.a, e.b, e.c], mixpanel.reducer.count()); }' % expected_function)
+
         # Non iterable key.
         self.assertEqual(
             str(grouper(raw('e.a'), raw('e.properties.some_accessor'))),