def test_all_numeric_with_no_numeric_columns(self):
     sio = StringIO()
     PandasTools.WriteSDF(self.df, sio, allNumeric=True)
     s = sio.getvalue()
     self.assertFalse(">" in s, s)
     self.assertNotIn("7\n\n", s)  # double-check that the numeric tests don't pass by accident
     self.assertNotIn("8\n\n", s)
Exemple #2
0
 def test_all_numeric_with_no_numeric_columns(self):
     sio = StringIO()
     PandasTools.WriteSDF(self.df, sio, allNumeric=True)
     s = sio.getvalue()
     self.assertFalse(">" in s, s)
     self.assertNotIn("7\n\n", s)  # double-check that the numeric tests don't pass by accident
     self.assertNotIn("8\n\n", s)
 def test_specify_numeric_column(self):
     sio = StringIO()
     df = self.df
     df["len2"] = df["ID"].map(len)
     PandasTools.WriteSDF(df, sio, properties=["len2"])
     s = sio.getvalue()
     self.assertEqual(s.count("<len2>"), 2)
     self.assertIn("7\n\n", s)
     self.assertIn("8\n\n", s)
 def test_specify_numeric_column(self):
     sio = StringIO()
     df = self.df
     df["len2"] = df["ID"].map(len)
     PandasTools.WriteSDF(df, sio, properties=["len2"])
     s = sio.getvalue()
     self.assertEqual(s.count("<len2>"), 2)
     self.assertIn("7\n\n", s)
     self.assertIn("8\n\n", s)
 def test_all_numeric_with_numeric_columns(self):
     sio = StringIO()
     df = self.df
     df["len"] = df["ID"].map(len)
     PandasTools.WriteSDF(df, sio, allNumeric=True)
     s = sio.getvalue()
     self.assertEqual(s.count("<len>"), 2)
     self.assertIn("7\n\n", s)
     self.assertIn("8\n\n", s)
 def test_all_numeric_with_numeric_columns(self):
     sio = StringIO()
     df = self.df
     df["len"] = df["ID"].map(len)
     PandasTools.WriteSDF(df, sio, allNumeric=True)
     s = sio.getvalue()
     self.assertEqual(s.count("<len>"), 2)
     self.assertIn("7\n\n", s)
     self.assertIn("8\n\n", s)
Exemple #7
0
def _get_image(x):
  """displayhook function for PIL Images, rendered as PNG"""
  import pandas as pd
  sio = StringIO()    
  x.save(sio,format='PNG')
  s = b64encode(sio.getvalue())
  pd.set_option('display.max_columns',len(s)+1000)
  pd.set_option('display.max_rows',len(s)+1000)
  if len(s)+100 > pd.get_option("display.max_colwidth"):
    pd.set_option("display.max_colwidth",len(s)+1000)
  return s
Exemple #8
0
 def test2(self):
     fName = os.path.join(RDConfig.RDDataDir, 'NCI', 'first_200.props.sdf')
     suppl = Chem.SDMolSupplier(fName)
     io = StringIO()
     try:
         Convert(suppl, io, keyCol='AMW', stopAfter=5)
     except Exception:
         import traceback
         traceback.print_exc()
         self.fail('conversion failed')
     txt = io.getvalue()
     lines = [line for line in txt.split('\n') if line.strip() != '']
     self.assertTrue(len(lines) == 6, 'bad num lines: %d' % len(lines))
     line0 = lines[0].split(',')
     self.assertEqual(len(line0), 20)
     self.assertTrue(line0[0] == 'AMW')
     self.assertTrue(line0[1] == 'SMILES')
 def test2(self):
   fName = os.path.join(RDConfig.RDDataDir, 'NCI', 'first_200.props.sdf')
   suppl = Chem.SDMolSupplier(fName)
   io = StringIO()
   try:
     Convert(suppl, io, keyCol='AMW', stopAfter=5)
   except Exception:
     import traceback
     traceback.print_exc()
     self.fail('conversion failed')
   txt = io.getvalue()
   lines = [line for line in txt.split('\n') if line.strip() != '']
   self.assertTrue(len(lines) == 6, 'bad num lines: %d' % len(lines))
   line0 = lines[0].split(',')
   self.assertEqual(len(line0), 20)
   self.assertTrue(line0[0] == 'AMW')
   self.assertTrue(line0[1] == 'SMILES')
Exemple #10
0
 def test1(self):
     fName = os.path.join(RDConfig.RDDataDir, 'NCI', 'first_200.props.sdf')
     suppl = Chem.SDMolSupplier(fName)
     io = StringIO()
     try:
         Convert(suppl, io)
     except Exception:
         import traceback
         traceback.print_exc()
         self.fail('conversion failed')
     txt = io.getvalue()
     lines = txt.split('\n')
     if not lines[-1]:
         del lines[-1]
     self.assertTrue(len(lines) == 201, 'bad num lines: %d' % len(lines))
     line0 = lines[0].split(',')
     self.assertEqual(len(line0), 20)
     self.assertTrue(line0[0] == 'SMILES')
Exemple #11
0
 def test1(self):
   fName = os.path.join(RDConfig.RDDataDir, 'NCI', 'first_200.props.sdf')
   suppl = Chem.SDMolSupplier(fName)
   io = StringIO()
   try:
     Convert(suppl, io)
   except Exception:
     import traceback
     traceback.print_exc()
     self.fail('conversion failed')
   txt = io.getvalue()
   lines = txt.split('\n')
   if not lines[-1]:
     del lines[-1]
   self.assertTrue(len(lines) == 201, 'bad num lines: %d' % len(lines))
   line0 = lines[0].split(',')
   self.assertEqual(len(line0), 20)
   self.assertTrue(line0[0] == 'SMILES')
Exemple #12
0
 def test2(self):
   import os
   from rdkit.six.moves import cStringIO as StringIO  #@UnresolvedImport #pylint: disable=F0401
   fName = os.path.join(RDConfig.RDDataDir, 'NCI', 'first_200.props.sdf')
   suppl = Chem.SDMolSupplier(fName)
   io = StringIO()
   try:
     Convert(suppl, io, keyCol='AMW', stopAfter=5)
   except Exception:
     import traceback
     traceback.print_exc()
     self.fail('conversion failed')
   txt = io.getvalue()
   lines = txt.split('\n')
   if not lines[-1]:
     del lines[-1]
   self.assertTrue(len(lines) == 6, 'bad num lines: %d' % len(lines))
   line0 = lines[0].split(',')
   self.assertEqual(len(line0), 20)
   self.assertTrue(line0[0] == 'AMW')
   self.assertTrue(line0[1] == 'SMILES')
Exemple #13
0
 def test2(self):
   import os
   from rdkit.six.moves import cStringIO as StringIO
   fName = os.path.join(RDConfig.RDDataDir,'NCI','first_200.props.sdf')
   suppl = Chem.SDMolSupplier(fName)
   io = StringIO()
   try:
     Convert(suppl,io,keyCol='AMW',stopAfter=5)
   except:
     import traceback
     traceback.print_exc()
     self.fail('conversion failed')
   txt = io.getvalue()
   lines = txt.split('\n')
   if not lines[-1]:
     del lines[-1]
   self.assertTrue(len(lines)==6,'bad num lines: %d'%len(lines))
   line0 = lines[0].split(',')
   self.assertEqual(len(line0),20)
   self.assertTrue(line0[0]=='AMW')
   self.assertTrue(line0[1]=='SMILES')
Exemple #14
0
    def test1(self):
        import os
        from rdkit.six.moves import cStringIO as StringIO  # @UnresolvedImport #pylint: disable=F0401

        fName = os.path.join(RDConfig.RDDataDir, "NCI", "first_200.props.sdf")
        suppl = Chem.SDMolSupplier(fName)
        io = StringIO()
        try:
            Convert(suppl, io)
        except Exception:
            import traceback

            traceback.print_exc()
            self.fail("conversion failed")
        txt = io.getvalue()
        lines = txt.split("\n")
        if not lines[-1]:
            del lines[-1]
        self.assertTrue(len(lines) == 201, "bad num lines: %d" % len(lines))
        line0 = lines[0].split(",")
        self.assertEqual(len(line0), 20)
        self.assertTrue(line0[0] == "SMILES")
 def test_identifier_from_a_column(self):
     sio = StringIO()
     PandasTools.WriteSDF(self.df, sio, idName="prop2")
     s = sio.getvalue()
     first_line = s.split("\n", 1)[0]
     self.assertEqual(first_line, "qwe")
 def test_default_write_does_not_include_tags(self):
     sio = StringIO()
     PandasTools.WriteSDF(self.df, sio)
     s = sio.getvalue()
     self.assertNotIn(s, "prop2")
Exemple #17
0
 def test_identifier_from_a_column(self):
     sio = StringIO()
     PandasTools.WriteSDF(self.df, sio, idName="prop2")
     s = sio.getvalue()
     first_line = s.split("\n", 1)[0]
     self.assertEqual(first_line, "qwe")
Exemple #18
0
 def test_default_write_does_not_include_tags(self):
     sio = StringIO()
     PandasTools.WriteSDF(self.df, sio)
     s = sio.getvalue()
     self.assertNotIn(s, "prop2")