Skip to content

Commit f403e8b

Browse files
committed
@wq/analyst
1 parent 7e5c1f8 commit f403e8b

33 files changed

+1876
-57
lines changed

.github/workflows/test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
package:
7777
- pandas
7878
- chart
79+
- analyst
7980
steps:
8081
- uses: actions/checkout@v2
8182
with:

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ DRP is configured by defining one or more [API views][api] and mapping them to U
4242
3. **Data Visualization**
4343
* [@wq/pandas]
4444
* [@wq/chart]
45+
* [@wq/analyst]
4546

4647
[Django REST Framework]: http://django-rest-framework.org
4748
[pandas]: http://pandas.pydata.org
@@ -55,3 +56,4 @@ DRP is configured by defining one or more [API views][api] and mapping them to U
5556
[renderers]: https://django-rest-pandas.wq.io/renderers/
5657
[@wq/pandas]: https://django-rest-pandas.wq.io/@wq/pandas
5758
[@wq/chart]: https://django-rest-pandas.wq.io/@wq/chart
59+
[@wq/analyst]: https://django-rest-pandas.wq.io/@wq/analyst

docs/@wq/analyst.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: "@wq/analyst"
3+
module: Django REST Pandas
4+
---
5+
6+
![@wq/analyst](../images/@wq/analyst.svg)
7+
8+
**@wq/analyst** is a [@wq/app plugin] providing interactive React tables and charts. @wq/analyst is primarily intended as a client for [Django REST Pandas].
9+
10+
## Installation
11+
12+
FIXME
13+
14+
## API
15+
16+
FIXME
17+
18+
[@wq/app plugin]: https://wq.io/plugins/
19+
[Django REST Pandas]: ../index.md

docs/config.md

+71-8
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,65 @@ wq_config:
1111

1212
### URL Configuration
1313

14+
To use [Django REST Pandas] in your project, you will generally need to define an [API view][api] and register it with urls.py as shown below:
15+
1416
```python
1517
# urls.py
16-
from django.conf.urls import patterns, include, url
17-
18+
from django.urls import path
1819
from .views import TimeSeriesView
19-
urlpatterns = patterns('',
20-
url(r'^data', TimeSeriesView.as_view()),
20+
21+
urlpatterns = (
22+
path("data", TimeSeriesView.as_view()),
2123
)
2224

23-
# This is only required to support extension-style formats (e.g. /data.csv)
25+
# The following is required to support extension-style formats (e.g. /data.csv)
2426
from rest_framework.urlpatterns import format_suffix_patterns
2527
urlpatterns = format_suffix_patterns(urlpatterns)
2628
```
2729

30+
When [using DRP with the wq framework][wq-setup], you can instead register a [`PandasViewSet`][PandasViewSet] subclass with [wq.db.rest.router]. wq.db provides extension-style formats by default.
31+
32+
```
33+
from wq.db import rest
34+
from .views import TimeSeriesViewSet
35+
36+
rest.router.add_page(
37+
"data",
38+
{
39+
"url": "data",
40+
"template": "table",
41+
"table": {"url": "/data.csv"},
42+
},
43+
TimeSeriesViewSet,
44+
)
45+
```
46+
2847
### Customizing Renderers
2948

30-
You can override the [default renderers][renderers] by setting `PANDAS_RENDERERS` in your `settings.py`, or by overriding `renderer_classes` in your individual view(s). `PANDAS_RENDERERS` is defined separately from Django REST Framework's own `DEFAULT_RENDERER_CLASSES` setting, in case you want to have DRP-enabled views intermingled with regular DRF views.
49+
DRP provides a set of [default renderers][renderers] that you can oveeride by setting `REST_PANDAS["RENDERERS"]` in your `settings.py`, or by overriding `renderer_classes` in your individual view(s). `REST_PANDAS["RENDERERS"]` should be a list or tuple of string paths pointing to one or more Django REST Framework renderer classes.
50+
51+
The default `REST_PANDAS["RENDERERS"]` setting is as follows:
52+
53+
```python
54+
REST_PANDAS = {
55+
"RENDERERS": (
56+
"rest_pandas.renderers.PandasHTMLRenderer",
57+
"rest_pandas.renderers.PandasCSVRenderer",
58+
"rest_pandas.renderers.PandasTextRenderer",
59+
"rest_pandas.renderers.PandasJSONRenderer",
60+
"rest_pandas.renderers.PandasExcelRenderer",
61+
"rest_pandas.renderers.PandasOldExcelRenderer",
62+
"rest_pandas.renderers.PandasPNGRenderer",
63+
"rest_pandas.renderers.PandasSVGRenderer",
64+
),
65+
)
66+
```
67+
68+
> When [using DRP with the wq framework][wq-setup], `"rest_pandas.renderers.PandasHTMLRenderer"` is automatically replaced with `"wq.db.rest.renderers.HTMLRenderer"` by default.
69+
70+
`REST_PANDAS["RENDERERS"]` is similar to Django REST Framework's own `DEFAULT_RENDERER_CLASSES` setting, but defined separately in case you plan to have DRP-enabled views intermingled with regular DRF views. That said, it is also possible to include DRP renderers in `DEFAULT_RENDERER_CLASSES`. To do so, extend `PandasMixin` in you view or set `Meta.list_serializer_class` explicitly on your serializer. Otherwise, you may get an error saying the serializer output is not a `DataFrame`.
3171

32-
You can also include DRP renderers in `DEFAULT_RENDERER_CLASSES`. In that case, extend `PandasMixin` or set `list_serializer_class` on your serializer. Otherwise, you may get an error saying the serializer output is not a `DataFrame`. In short, there are three paths to getting DRP renderers working with your views:
72+
In short, there are three paths to getting DRP renderers working with your views:
3373

3474
1. Extend [PandasView], [PandasSimpleView], or [PandasViewSet], and use the `PANDAS_RENDERERS` setting (which defaults to the list above).
3575
2. Extend [PandasMixin] and customize `REST_FRAMEWORK['DEFAULT_RENDERER_CLASSES']` to add one or more `rest_pandas` renderers.
@@ -45,6 +85,20 @@ class TimeSeriesView(PandasMixin, ListAPIView):
4585
...
4686
```
4787

88+
### Field Labels
89+
90+
By default, Django REST Pandas will update the dataframe columns to use the `label` attribute of defined serializer fields, and/or the `verbose_name` attribute of any underlying model fields. To disable this functionality (and use the field names as column names), set `REST_PANDAS["APPLY_FIELD_LABELS"]` to false.
91+
92+
```python
93+
REST_PANDAS = {
94+
"APPLY_FIELD_LABELS": True, # Default in DRP 2.0
95+
}
96+
97+
REST_PANDAS = {
98+
"APPLY_FIELD_LABELS": False, # Compatible with DRP 1.x
99+
}
100+
```
101+
48102
### Date Formatting
49103

50104
By default, Django REST Framework will serialize dates as strings before they are processed by the renderer classes. In many cases, you may want to preserve the dates as `datetime` objects and let Pandas handle the rendering. To do this, define an explicit [DateTimeField] or [DateField] on your DRF serializer and set `format=None`:
@@ -65,9 +119,18 @@ Alternately, you can disable date serialization globally by setting `DATETIME_FO
65119
DATE_FORMAT = None
66120
```
67121

122+
[Django REST Pandas]: ./index.md
68123
[renderers]: ./renderers/index.md
124+
[wq-setup]: ./guides/integrate-with-wq-framework.md
125+
[api]: ./api/index.md
126+
[PandasViewSet]: ./api/PandasViewSet.md
127+
[PandasView]: ./api/PandasView.md
128+
[PandasSimpleView]: ./api/PandasSimpleView.md
129+
[PandasMixin]: ./api/PandasMixin.md
130+
69131
[#32]: https://github.com/wq/django-rest-pandas/issues/32
70132
[#36]: https://github.com/wq/django-rest-pandas/issues/36
133+
134+
[wq.db.rest.router]: https://wq.io/wq.db/router
71135
[DateField]: http://www.django-rest-framework.org/api-guide/fields/#datefield
72136
[DateTimeField]: http://www.django-rest-framework.org/api-guide/fields/#datetimefield
73-
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
icon: pin
3+
---
4+
5+
# How To: Integrate with the wq Framework
6+
7+
Django REST Pandas has built-in support for integration with the [wq framework].
8+
9+
FIXME
10+
11+
12+
[wq framework]: https://wq.io/

docs/images/@wq/analyst.svg

+1
Loading

docs/packages.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Django REST Pandas is distributed on the Python package index. (Also see the li
1313

1414
Module | Github | PyPI | npm | Description
1515
-----------------------------------------|---------------------------------|-----------------------|-----------------------|-------------
16-
[![Django REST Pandas][drp.svg]][wq/drp] | [wq/django-rest-pandas][gh/drp] | [rest-pandas][py/drp] | [@wq/pandas][npm/drp] | Django application
16+
[![Django REST Pandas][drp.svg]][wq/drp] | [wq/django-rest-pandas][gh/drp] | [rest-pandas][py/drp] | [@wq/analyst][npm/drp] | Django application
1717

1818
[drp.svg]: ../images/icons/django-rest-pandas.svg
1919

@@ -24,4 +24,4 @@ Django REST Pandas is distributed on the Python package index. (Also see the li
2424

2525
[py/drp]: https://pypi.org/project/rest-pandas
2626

27-
[npm/drp]: https://npmjs.com/package/@wq/pandas
27+
[npm/drp]: https://npmjs.com/package/@wq/analyst

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
testMatch: ['**/__tests__/**/*.js?(x)'],
33
transformIgnorePatterns: [
4-
'/node_modules/(?!@wq|d3|internmap|delaunator|robust-predicates)',
4+
'/node_modules/(?!@wq|redux-orm|d3|internmap|delaunator|robust-predicates)',
55
],
66
};

packages/analyst/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[![@wq/analyst][logo]][docs]
2+
3+
**@wq/analyst** is a @wq/app plugin providing interactive React tables and charts. @wq/analyst is primarily intended as a client for [Django REST Pandas].
4+
5+
### [Documentation][docs]
6+
7+
[**Installation**][installation]
8+
•
9+
[**API**][api]
10+
11+
[logo]: https://django-rest-pandas.wq.io/images/@wq/analyst.svg
12+
[docs]: https://django-rest-pandas.wq.io/@wq/analyst
13+
[installation]: https://django-rest-pandas.wq.io/@wq/analyst#installation
14+
[api]: https://django-rest-pandas.wq.io/@wq/analyst#api
15+
16+
[Django REST Pandas]: https://django-rest-pandas.wq.io/

0 commit comments

Comments
 (0)