def testPython2RTypes(self): """Test GGStatement converts many python types properly""" self.check_me(pygg.geom_point(a=1), "geom_point(a=1)") self.check_me(pygg.geom_point(a=None), "geom_point(a=NA)") self.check_me(pygg.geom_point(a=1.0), "geom_point(a=1.0)") self.check_me(pygg.geom_point(a=1e-2), "geom_point(a=0.01)") self.check_me(pygg.geom_point(a="foo"), 'geom_point(a=foo)') self.check_me(pygg.geom_point(a=pygg.esc("foo")), 'geom_point(a="foo")') self.check_me(pygg.geom_point(a=True), 'geom_point(a=TRUE)') self.check_me(pygg.geom_point(a=False), 'geom_point(a=FALSE)') self.check_me(pygg.geom_point(a=[1, 2]), 'geom_point(a=c(1,2))') self.check_me(pygg.geom_point(a={ 'list1': 1, 'list2': 2 }), 'geom_point(a=list(list1=1,list2=2))') self.check_me( pygg.geom_point(1, a=2.0, b=[3, 4], c={ 'list1': pygg.esc('s1'), 'list2': 2 }), 'geom_point(1,a=2.0,b=c(3,4),c=list(list1="s1",list2=2))')
def testPython2RStringEsc(self): """Test GGStatement escapes strings properly""" self.check_me(pygg.geom_point(a="b"), 'geom_point(a=b)') self.check_me(pygg.geom_point(a='b'), 'geom_point(a=b)') self.check_me(pygg.geom_point(a="'b'"), 'geom_point(a=\'b\')') self.check_me(pygg.geom_point(a='"b"'), 'geom_point(a="b")') self.check_me(pygg.geom_point(a={'k': pygg.esc("v")}), 'geom_point(a=list(k="v"))') self.check_me(pygg.geom_point(a=[pygg.esc("a"), pygg.esc("b")]), 'geom_point(a=c("a","b"))')
def testPython2RStringEsc(self): """Test GGStatement escapes strings properly""" self.check_me(pygg.geom_point(a="b"), 'geom_point(a=b)') self.check_me(pygg.geom_point(a='b'), 'geom_point(a=b)') self.check_me(pygg.geom_point(a="'b'"), 'geom_point(a=\'b\')') self.check_me(pygg.geom_point(a='"b"'), 'geom_point(a="b")') self.check_me(pygg.geom_point(a={'k': pygg.esc("v")}), 'geom_point(a=list(k="v"))') self.check_me( pygg.geom_point(a=[pygg.esc("a"), pygg.esc("b")]), 'geom_point(a=c("a","b"))')
def testPython2RTypes(self): """Test GGStatement converts many python types properly""" self.check_me(pygg.geom_point(a=1), "geom_point(a=1)") self.check_me(pygg.geom_point(a=None), "geom_point(a=NA)") self.check_me(pygg.geom_point(a=1.0), "geom_point(a=1.0)") self.check_me(pygg.geom_point(a=1e-2), "geom_point(a=0.01)") self.check_me(pygg.geom_point(a="foo"), 'geom_point(a=foo)') self.check_me(pygg.geom_point(a=pygg.esc("foo")), 'geom_point(a="foo")') self.check_me(pygg.geom_point(a=True), 'geom_point(a=TRUE)') self.check_me(pygg.geom_point(a=False), 'geom_point(a=FALSE)') self.check_me(pygg.geom_point(a=[1, 2]), 'geom_point(a=c(1,2))') self.check_me(pygg.geom_point(a={'list1': 1, 'list2': 2}), 'geom_point(a=list(list1=1,list2=2))') self.check_me(pygg.geom_point(1, a=2.0, b=[3, 4], c={'list1': pygg.esc('s1'), 'list2': 2}), 'geom_point(1,a=2.0,b=c(3,4),c=list(list1="s1",list2=2))')
def testBasicDataggplot(self): data = [dict(x=x, y=y) for x, y in zip(range(10), range(10))] p = pygg.ggplot(data, pygg.aes(x='x', y='y')) p += pygg.geom_point() p += pygg.geom_smooth() p += pygg.ggtitle(pygg.esc('Test title')) self.check_ggsave(p)
def testPandasDF(self): data = pandas.read_csv(StringIO.StringIO(IRIS_DATA_CSV)) self.assertIsInstance(data, pandas.DataFrame) p = pygg.ggplot('data', pygg.aes(x='SepalLength', y='PetalLength', color='Name')) p += pygg.geom_point() p += pygg.geom_smooth() p += pygg.ggtitle(pygg.esc('Test title')) self.check_ggsave(p, data)
def testPandasDFggplot(self): data = pandas.read_csv(StringIO.StringIO(IRIS_DATA_CSV)) self.assertIsInstance(data, pandas.DataFrame) p = pygg.ggplot( data, pygg.aes(x='SepalLength', y='PetalLength', color='Name')) p += pygg.geom_point() p += pygg.geom_smooth() p += pygg.ggtitle(pygg.esc('Test title')) self.check_ggsave(p)