Skip to content

Commit 53920a3

Browse files
committed
small code tweak to work around the irritating module import scope issue pandas is now attached as a private attribute
1 parent ffadf8d commit 53920a3

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

pysces/PyscesModel.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,6 @@
119119
)
120120
)
121121

122-
# Custom datatype check
123-
if __CUSTOM_DATATYPE__ == 'pandas':
124-
if _checkPandas():
125-
import pandas
126-
else:
127-
__CUSTOM_DATATYPE__ = None
128-
129122
_HAVE_ASSIMULO = False
130123
_ASSIMULO_LOAD_ERROR = ''
131124

@@ -1484,12 +1477,21 @@ def __init__(self, File=None, dir=None, loader='file', fString=None, autoload=Tr
14841477
self.piecewise_functions = []
14851478
self.__piecewises__ = {}
14861479
self.__HAS_PIECEWISE__ = False
1480+
14871481
if autoload:
14881482
self.ModelLoad()
14891483
self.__PSC_auto_load = True
14901484
else:
14911485
self.__PSC_auto_load = False
14921486

1487+
# autoload a custom datatype ... currently pandas
1488+
if __CUSTOM_DATATYPE__ == 'pandas':
1489+
if _checkPandas():
1490+
self.enableDataPandas(True)
1491+
else:
1492+
self.enableDataPandas(False)
1493+
1494+
14931495
def enableDataPandas(self, var=True):
14941496
"""
14951497
Toggle custom data type for `mod.sim` and `mod.scan` objects.
@@ -1498,7 +1500,8 @@ def enableDataPandas(self, var=True):
14981500
"""
14991501
if var:
15001502
try:
1501-
import pandas
1503+
import pandas as pandas
1504+
self.__pandas = pandas
15021505
self.__settings__['custom_datatype'] = 'pandas'
15031506
print('Pandas output enabled.')
15041507
except ModuleNotFoundError:
@@ -4830,7 +4833,7 @@ def sim(self):
48304833
if self._sim is None and self.data_sim is not None:
48314834
data = self.data_sim.getAllSimData(lbls=True)
48324835
if self.__settings__['custom_datatype'] == 'pandas':
4833-
self._sim = pandas.DataFrame(data[0], columns=data[1])
4836+
self._sim = self.__pandas.DataFrame(data[0], columns=data[1])
48344837
else:
48354838
self._sim = numpy.rec.fromrecords(data[0], names=data[1])
48364839
return self._sim
@@ -9007,7 +9010,7 @@ def Scan1(self, range1=[], runUF=0):
90079010
def scan(self):
90089011
if self._scan is None and self.scan_res is not None:
90099012
if self.__settings__['custom_datatype'] == 'pandas':
9010-
self._scan = pandas.DataFrame(
9013+
self._scan = self.__pandas.DataFrame(
90119014
self.scan_res, columns=[self.scan_in] + self.scan_out
90129015
)
90139016
else:

0 commit comments

Comments
 (0)