From b8a990aea973aa0b2c7b64d28bbb75db3549b3f7 Mon Sep 17 00:00:00 2001 From: Guillaume Thomas Date: Tue, 27 Jan 2015 19:34:31 +0100 Subject: [PATCH] Added tests for ValuesQuerySet --- django_pandas/tests/test_io.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/django_pandas/tests/test_io.py b/django_pandas/tests/test_io.py index d722043..3350f94 100644 --- a/django_pandas/tests/test_io.py +++ b/django_pandas/tests/test_io.py @@ -1,4 +1,5 @@ from django.test import TestCase +from django.db.models import Sum import pandas as pd import numpy as np from .models import MyModel, Trader, Security, TradeLog, MyModelChoice @@ -36,6 +37,15 @@ def test_basic(self): df1 = read_frame(qs, ['col1', 'col2']) self.assertEqual(df1.shape, (qs.count(), 2)) + def test_values(self): + qs = MyModel.objects.all() + qs = qs.extra(select={"ecol1": "col1+1"}) + qs = qs.values("index_col", "ecol1", "col1") + qs = qs.annotate(scol1 = Sum("col1")) + df = read_frame(qs) + self.assertEqual(list(df.columns), [u'index_col', u'col1', u'scol1', u'ecol1']) + self.assertEqual(list(df["col1"]), list(df["scol1"])) + def test_choices(self): MyModelChoice.objects.create(col1=1, col2=9999.99)