Skip to content

Commit cac13f3

Browse files
committed
don't use pandas for numpy > 1.23 where loadtxt fast anyway
1 parent 772bd77 commit cac13f3

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

docs/source/gui.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ To run the GUI you need PySide. This is not included in default dependencies, bu
5151

5252
You can also use PySide2, e.g. using `Anaconda <https://www.anaconda.com/distribution/>`_ to make a consistent new environment from conda-forge (which includes PySide2) e.g. ::
5353

54-
conda create -n py39forge -c conda-forge python=3.9 scipy pandas matplotlib PyYAML PySide2
54+
conda create -n py39forge -c conda-forge python=3.9 scipy matplotlib PyYAML PySide2
5555

5656
Once PySide is set up, (re)install getdist and you should then be able to use the getdist-gui script on your path.
5757
On a Mac the installation will also make a GetDist GUI Mac app, which you can find using Spotlight.

getdist/chains.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import numpy as np
33
import re
4+
from packaging import version
45
from getdist.paramnames import ParamNames, ParamInfo, escapeLatex
56
from getdist.convolve import autoConvolve
67
from getdist import cobaya_interface
@@ -16,11 +17,6 @@
1617
_int_types = (int, np.integer)
1718
ParamConfidenceData = namedtuple("ParamConfidenceData", ("paramVec", "norm", "indexes", "cumsum"))
1819

19-
try:
20-
import pandas
21-
except ImportError:
22-
pandas = None
23-
2420

2521
class WeightedSampleError(Exception):
2622
"""
@@ -113,28 +109,28 @@ def hasChainFiles(file_root, ext='.txt'):
113109
return any(chainFiles(file_root, ext=ext, separator=sep, last_chain=1) for sep in ['_', '.'])
114110

115111

116-
_pandas_suggestion = True
117-
118-
119112
def loadNumpyTxt(fname, skiprows=None):
120113
"""
121114
Utility routine to loads numpy array from file.
122-
Uses faster pandas read routine if pandas is installed, or falls back to numpy's loadtxt otherwise
123115
124116
:param fname: The file to load
125117
:param skiprows: The number of rows to skip at the begging of the file
126118
:return: numpy array of the data values
127119
"""
120+
121+
if not hasattr(loadNumpyTxt, 'pandas'):
122+
loadNumpyTxt.pandas = None
123+
try:
124+
if version.parse(np.__version__) < version.parse('1.23'):
125+
import pandas
126+
loadNumpyTxt.pandas = pandas
127+
except ImportError:
128+
logging.warning('Install pandas or numpy 1.23+ for faster reading from text files')
128129
try:
129-
if pandas:
130-
return pandas.read_csv(fname, delim_whitespace=True, header=None, dtype=np.float64,
131-
skiprows=skiprows, comment='#').values
132-
else:
133-
global _pandas_suggestion
134-
if _pandas_suggestion:
135-
_pandas_suggestion = False
136-
logging.warning('Install pandas for faster reading from text files')
137-
return np.atleast_2d(np.loadtxt(fname, skiprows=skiprows or 0))
130+
if loadNumpyTxt.pandas:
131+
return loadNumpyTxt.pandas.read_csv(fname, delim_whitespace=True, header=None, dtype=np.float64,
132+
skiprows=skiprows, comment='#').values
133+
return np.atleast_2d(np.loadtxt(fname, skiprows=skiprows or 0))
138134
except ValueError:
139135
print('Error reading %s' % fname)
140136
raise

getdist/gui/mainwindow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
if not os.path.exists(os.path.join(sys.prefix, 'conda-meta')):
3939
print('Using Anaconda is probably the most reliable method')
4040
print("E.g. make and use a new environment")
41-
print('conda create -n py10side python=3.10 scipy pandas matplotlib')
41+
print('conda create -n py10side python=3.10 scipy matplotlib')
4242
print("then 'pip install PySide6'")
4343

4444
sys.exit(-1)

getdist/tests/getdist_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import matplotlib.pyplot as plt
1515

1616

17-
1817
class GetDistFileTest(unittest.TestCase):
1918
"""test reading files, convergence routines and getdist script"""
2019

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ def run(self):
140140
'scipy (>=1.5.0)',
141141
'PyYAML (>=5.1)'],
142142
# PySide is needed for the GUI
143-
# pandas optional (for faster txt chain file read)
144-
extras_require={'GUI': ["PySide6>=6.10"], 'txt': ["pandas>=1.0"]},
143+
extras_require={'GUI': ["PySide6>=6.10"]},
145144
cmdclass=cmd_class,
146145
classifiers=[
147146
'Development Status :: 5 - Production/Stable',
@@ -152,7 +151,8 @@ def run(self):
152151
'Programming Language :: Python :: 3.7',
153152
'Programming Language :: Python :: 3.8',
154153
'Programming Language :: Python :: 3.9',
155-
'Programming Language :: Python :: 3.10'
154+
'Programming Language :: Python :: 3.10',
155+
'Programming Language :: Python :: 3.11'
156156
],
157157
python_requires='>=3.6',
158158
keywords=['MCMC', 'KDE', 'sample', 'density estimation', 'plot', 'figure']

0 commit comments

Comments
 (0)