Skip to content

Commit a313131

Browse files
committed
TST: fix python3.3 build issues (on linux at least) #2331
1 parent 5fdae30 commit a313131

File tree

8 files changed

+38
-17
lines changed

8 files changed

+38
-17
lines changed

pandas/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
__docformat__ = 'restructuredtext'
44

5-
from datetime import datetime
6-
7-
import numpy as np
8-
95
try:
106
from . import hashtable, tslib, lib
117
except Exception: # pragma: no cover
@@ -19,6 +15,9 @@
1915
else:
2016
raise
2117

18+
from datetime import datetime
19+
import numpy as np
20+
2221
from pandas.version import version as __version__
2322
from pandas.info import __doc__
2423

pandas/algos.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cdef extern from "math.h":
4444
double sqrt(double x)
4545
double fabs(double)
4646

47-
import lib
47+
from . import lib
4848

4949
include "skiplist.pyx"
5050

pandas/hashtable.pyx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ cnp.import_ufunc()
1818

1919
cdef int64_t iNaT = util.get_nat()
2020

21-
from . import algos
22-
2321
cdef extern from "datetime.h":
2422
bint PyDateTime_Check(object o)
2523
void PyDateTime_IMPORT()

pandas/index.pyx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ cimport util
1313

1414
import numpy as np
1515

16-
import algos
17-
1816
cimport tslib
19-
from tslib import Timestamp
20-
import tslib
21-
2217
from hashtable cimport *
23-
import hashtable as _hash
18+
from . import algos, tslib, hashtable as _hash
19+
from .tslib import Timestamp
20+
2421

2522
from datetime cimport (get_datetime64_value, _pydatetime_to_dts,
2623
pandas_datetimestruct)

pandas/tests/test_graphics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
from numpy.testing.decorators import slow
1515
import pandas.tools.plotting as plotting
1616

17+
18+
def _skip_if_no_scipy():
19+
try:
20+
import scipy
21+
except ImportError:
22+
raise nose.SkipTest
23+
24+
1725
class TestSeriesPlots(unittest.TestCase):
1826

1927
@classmethod
@@ -136,6 +144,7 @@ def test_hist(self):
136144

137145
@slow
138146
def test_kde(self):
147+
_skip_if_no_scipy()
139148
_check_plot_works(self.ts.plot, kind='kde')
140149
_check_plot_works(self.ts.plot, kind='density')
141150
ax = self.ts.plot(kind='kde', logy=True)
@@ -380,6 +389,7 @@ def test_boxplot(self):
380389

381390
@slow
382391
def test_kde(self):
392+
_skip_if_no_scipy()
383393
df = DataFrame(np.random.randn(100, 4))
384394
_check_plot_works(df.plot, kind='kde')
385395
_check_plot_works(df.plot, kind='kde', subplots=True)
@@ -435,6 +445,8 @@ def test_hist(self):
435445

436446
@slow
437447
def test_scatter(self):
448+
_skip_if_no_scipy()
449+
438450
df = DataFrame(np.random.randn(100, 4))
439451
import pandas.tools.plotting as plt
440452
def scat(**kwds):

pandas/tools/plotting.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,15 @@ def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds):
372372
import random
373373
import matplotlib
374374
import matplotlib.pyplot as plt
375-
data = series.values
375+
376+
# random.sample(ndarray, int) fails on python 3.3, sigh
377+
data = list(series.values)
376378
samplings = [random.sample(data, size) for _ in range(samples)]
379+
377380
means = np.array([np.mean(sampling) for sampling in samplings])
378381
medians = np.array([np.median(sampling) for sampling in samplings])
379-
midranges = np.array([(min(sampling) + max(sampling)) * 0.5 for sampling in samplings])
382+
midranges = np.array([(min(sampling) + max(sampling)) * 0.5
383+
for sampling in samplings])
380384
if fig == None:
381385
fig = plt.figure()
382386
x = range(samples)

pandas/tseries/tests/test_plotting.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
from pandas.util.testing import assert_series_equal
1919
import pandas.util.testing as tm
2020

21+
22+
def _skip_if_no_scipy():
23+
try:
24+
import scipy
25+
except ImportError:
26+
raise nose.SkipTest
27+
28+
2129
class TestTSPlot(unittest.TestCase):
2230

2331
@classmethod
@@ -530,6 +538,8 @@ def test_secondary_y_ts(self):
530538

531539
@slow
532540
def test_secondary_kde(self):
541+
_skip_if_no_scipy()
542+
533543
import matplotlib.pyplot as plt
534544
plt.close('all')
535545
ser = Series(np.random.randn(10))

pandas/tslib.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# cython: profile=False
2-
cimport numpy as np
32

3+
cimport numpy as np
44
from numpy cimport (int32_t, int64_t, import_array, ndarray,
55
NPY_INT64, NPY_DATETIME)
6+
import numpy as np
7+
68
from cpython cimport *
79

810
from libc.stdlib cimport free
@@ -14,7 +16,6 @@ from datetime cimport *
1416
from khash cimport *
1517
cimport cython
1618

17-
import numpy as np
1819
from datetime import timedelta, datetime
1920
from dateutil.parser import parse as parse_date
2021

0 commit comments

Comments
 (0)