Skip to content

Commit a82ddfe

Browse files
committed
Return diagnostic info as dict if pandas not installed (allows removal of pandas dependency); see #15
1 parent 01b5609 commit a82ddfe

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pybobyqa/diagnostic_info.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
from __future__ import absolute_import, division, print_function, unicode_literals
3030

3131
import numpy as np
32-
import pandas as pd
32+
try:
33+
import pandas as pd
34+
HAVE_PANDAS = True
35+
except ImportError:
36+
# If pandas not available, return diagnostic info as a Python dict
37+
HAVE_PANDAS = False
3338
from .util import remove_scaling
3439

3540

@@ -84,7 +89,10 @@ def to_dataframe(self, with_xk=False):
8489
if key == "xk" and not with_xk:
8590
continue # skip
8691
data_to_save[key] = self.data[key]
87-
return pd.DataFrame(data_to_save)
92+
if HAVE_PANDAS:
93+
return pd.DataFrame(data_to_save)
94+
else:
95+
return data_to_save
8896

8997
def to_csv(self, filename):
9098
df = self.to_dataframe()

0 commit comments

Comments
 (0)