Skip to content

Commit 534784b

Browse files
committed
Merge pull request #7954 from cpcloud/drop-np16
CI: Drop numpy 1.6 support
2 parents 1eb9955 + 9ca4a0d commit 534784b

37 files changed

+179
-472
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pip install pandas
9090
```
9191

9292
## Dependencies
93-
- [NumPy](http://www.numpy.org): 1.6.1 or higher
93+
- [NumPy](http://www.numpy.org): 1.7.0 or higher
9494
- [python-dateutil](http://labix.org/python-dateutil): 1.5 or higher
9595
- [pytz](http://pytz.sourceforge.net)
9696
- Needed for time zone support with ``pandas.date_range``

ci/requirements-2.6.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
numpy==1.6.1
1+
numpy==1.7.0
22
cython==0.19.1
33
python-dateutil==1.5
44
pytz==2013b

ci/requirements-2.7_LOCALE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ xlwt==0.7.5
44
openpyxl==1.6.2
55
xlsxwriter==0.4.6
66
xlrd==0.9.2
7-
numpy==1.6.1
7+
numpy==1.7.1
88
cython==0.19.1
99
bottleneck==0.6.0
1010
matplotlib==1.3.0

doc/source/install.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ installed), make sure you have `nose
247247
Dependencies
248248
------------
249249

250-
* `NumPy <http://www.numpy.org>`__: 1.6.1 or higher
250+
* `NumPy <http://www.numpy.org>`__: 1.7.0 or higher
251251
* `python-dateutil <http://labix.org/python-dateutil>`__ 1.5
252252
* `pytz <http://pytz.sourceforge.net/>`__
253253
* Needed for time zone support

doc/source/timeseries.rst

-20
Original file line numberDiff line numberDiff line change
@@ -1685,23 +1685,3 @@ yields another ``timedelta64[ns]`` dtypes Series.
16851685
16861686
td * -1
16871687
td * Series([1,2,3,4])
1688-
1689-
Numpy < 1.7 Compatibility
1690-
~~~~~~~~~~~~~~~~~~~~~~~~~
1691-
1692-
Numpy < 1.7 has a broken ``timedelta64`` type that does not correctly work
1693-
for arithmetic. pandas bypasses this, but for frequency conversion as above,
1694-
you need to create the divisor yourself. The ``np.timetimedelta64`` type only
1695-
has 1 argument, the number of **micro** seconds.
1696-
1697-
The following are equivalent statements in the two versions of numpy.
1698-
1699-
.. code-block:: python
1700-
1701-
from distutils.version import LooseVersion
1702-
if LooseVersion(np.__version__) <= '1.6.2':
1703-
y / np.timedelta(86400*int(1e6))
1704-
y / np.timedelta(int(1e6))
1705-
else:
1706-
y / np.timedelta64(1,'D')
1707-
y / np.timedelta64(1,'s')

doc/source/v0.15.0.txt

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ This is a major release from 0.14.1 and includes a small number of API changes,
77
enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
88
users upgrade to this version.
99

10+
.. warning::
11+
12+
pandas >= 0.15.0 will no longer support compatibility with NumPy versions <
13+
1.7.0. If you want to use the latest versions of pandas, please upgrade to
14+
NumPy >= 1.7.0.
15+
1016
- Highlights include:
1117

1218
- The ``Categorical`` type was integrated as a first-class pandas type, see :ref:`here <whatsnew_0150.cat>`

pandas/__init__.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pylint: disable-msg=W0614,W0401,W0611,W0622
22

3+
34
__docformat__ = 'restructuredtext'
45

56
try:
@@ -18,6 +19,7 @@
1819
from datetime import datetime
1920
import numpy as np
2021

22+
2123
# XXX: HACK for NumPy 1.5.1 to suppress warnings
2224
try:
2325
np.seterr(all='ignore')
@@ -27,14 +29,20 @@
2729
# numpy versioning
2830
from distutils.version import LooseVersion
2931
_np_version = np.version.short_version
30-
_np_version_under1p6 = LooseVersion(_np_version) < '1.6'
31-
_np_version_under1p7 = LooseVersion(_np_version) < '1.7'
3232
_np_version_under1p8 = LooseVersion(_np_version) < '1.8'
3333
_np_version_under1p9 = LooseVersion(_np_version) < '1.9'
3434

35+
3536
from pandas.version import version as __version__
3637
from pandas.info import __doc__
3738

39+
40+
if LooseVersion(_np_version) < '1.7.0':
41+
raise ImportError('pandas {0} is incompatible with numpy < 1.7.0, '
42+
'your numpy version is {1}. Please upgrade numpy to'
43+
' >= 1.7.0 to use pandas version {0}'.format(__version__,
44+
_np_version))
45+
3846
# let init-time option registration happen
3947
import pandas.core.config_init
4048

pandas/core/base.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,12 @@ def ndim(self):
298298

299299
def item(self):
300300
""" return the first element of the underlying data as a python scalar """
301-
return self.values.item()
301+
try:
302+
return self.values.item()
303+
except IndexError:
304+
# copy numpy's message here because Py26 raises an IndexError
305+
raise ValueError('can only convert an array of size 1 to a '
306+
'Python scalar')
302307

303308
@property
304309
def data(self):

pandas/core/common.py

+9-17
Original file line numberDiff line numberDiff line change
@@ -1848,6 +1848,8 @@ def _possibly_cast_to_datetime(value, dtype, coerce=False):
18481848
""" try to cast the array/value to a datetimelike dtype, converting float
18491849
nan to iNaT
18501850
"""
1851+
from pandas.tseries.timedeltas import _possibly_cast_to_timedelta
1852+
from pandas.tseries.tools import to_datetime
18511853

18521854
if dtype is not None:
18531855
if isinstance(dtype, compat.string_types):
@@ -1886,13 +1888,11 @@ def _possibly_cast_to_datetime(value, dtype, coerce=False):
18861888
elif np.prod(value.shape) and value.dtype != dtype:
18871889
try:
18881890
if is_datetime64:
1889-
from pandas.tseries.tools import to_datetime
18901891
value = to_datetime(value, coerce=coerce).values
18911892
elif is_timedelta64:
1892-
from pandas.tseries.timedeltas import \
1893-
_possibly_cast_to_timedelta
1894-
value = _possibly_cast_to_timedelta(value, coerce='compat', dtype=dtype)
1895-
except:
1893+
value = _possibly_cast_to_timedelta(value,
1894+
dtype=dtype)
1895+
except (AttributeError, ValueError):
18961896
pass
18971897

18981898
else:
@@ -1901,28 +1901,20 @@ def _possibly_cast_to_datetime(value, dtype, coerce=False):
19011901

19021902
# catch a datetime/timedelta that is not of ns variety
19031903
# and no coercion specified
1904-
if (is_array and value.dtype.kind in ['M','m']):
1904+
if is_array and value.dtype.kind in ['M', 'm']:
19051905
dtype = value.dtype
19061906

19071907
if dtype.kind == 'M' and dtype != _NS_DTYPE:
19081908
value = value.astype(_NS_DTYPE)
19091909

19101910
elif dtype.kind == 'm' and dtype != _TD_DTYPE:
1911-
from pandas.tseries.timedeltas import \
1912-
_possibly_cast_to_timedelta
1913-
value = _possibly_cast_to_timedelta(value, coerce='compat')
1911+
value = _possibly_cast_to_timedelta(value)
19141912

19151913
# only do this if we have an array and the dtype of the array is not
19161914
# setup already we are not an integer/object, so don't bother with this
19171915
# conversion
1918-
elif (is_array and not (
1919-
issubclass(value.dtype.type, np.integer) or
1920-
value.dtype == np.object_)):
1921-
pass
1922-
1923-
# try to infer if we have a datetimelike here
1924-
# otherwise pass thru
1925-
else:
1916+
elif not (is_array and not (issubclass(value.dtype.type, np.integer) or
1917+
value.dtype == np.object_)):
19261918
value = _possibly_infer_to_datetimelike(value)
19271919

19281920
return value

pandas/core/generic.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from pandas.core.internals import BlockManager
1717
import pandas.core.common as com
1818
import pandas.core.datetools as datetools
19-
from pandas import compat, _np_version_under1p7
19+
from pandas import compat
2020
from pandas.compat import map, zip, lrange, string_types, isidentifier, lmap
2121
from pandas.core.common import (isnull, notnull, is_list_like,
2222
_values_from_object, _maybe_promote,
@@ -3613,21 +3613,6 @@ def abs(self):
36133613
-------
36143614
abs: type of caller
36153615
"""
3616-
3617-
# suprimo numpy 1.6 hacking
3618-
# for timedeltas
3619-
if _np_version_under1p7:
3620-
3621-
def _convert_timedeltas(x):
3622-
if x.dtype.kind == 'm':
3623-
return np.abs(x.view('i8')).astype(x.dtype)
3624-
return np.abs(x)
3625-
3626-
if self.ndim == 1:
3627-
return _convert_timedeltas(self)
3628-
elif self.ndim == 2:
3629-
return self.apply(_convert_timedeltas)
3630-
36313616
return np.abs(self)
36323617

36333618
_shared_docs['describe'] = """

pandas/core/groupby.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
is_timedelta64_dtype, is_datetime64_dtype,
2727
is_categorical_dtype, _values_from_object)
2828
from pandas.core.config import option_context
29-
from pandas import _np_version_under1p7
3029
import pandas.lib as lib
3130
from pandas.lib import Timestamp
3231
import pandas.tslib as tslib
@@ -2764,18 +2763,21 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
27642763

27652764
# normally use vstack as its faster than concat
27662765
# and if we have mi-columns
2767-
if not _np_version_under1p7 or isinstance(v.index,MultiIndex) or key_index is None:
2768-
stacked_values = np.vstack([np.asarray(x) for x in values])
2769-
result = DataFrame(stacked_values,index=key_index,columns=index)
2766+
if isinstance(v.index, MultiIndex) or key_index is None:
2767+
stacked_values = np.vstack(map(np.asarray, values))
2768+
result = DataFrame(stacked_values, index=key_index,
2769+
columns=index)
27702770
else:
27712771
# GH5788 instead of stacking; concat gets the dtypes correct
27722772
from pandas.tools.merge import concat
2773-
result = concat(values,keys=key_index,names=key_index.names,
2773+
result = concat(values, keys=key_index,
2774+
names=key_index.names,
27742775
axis=self.axis).unstack()
27752776
result.columns = index
27762777
else:
2777-
stacked_values = np.vstack([np.asarray(x) for x in values])
2778-
result = DataFrame(stacked_values.T,index=v.index,columns=key_index)
2778+
stacked_values = np.vstack(map(np.asarray, values))
2779+
result = DataFrame(stacked_values.T, index=v.index,
2780+
columns=key_index)
27792781

27802782
except (ValueError, AttributeError):
27812783
# GH1738: values is list of arrays of unequal lengths fall

pandas/core/internals.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from pandas.util.decorators import cache_readonly
2626

2727
from pandas.tslib import Timestamp
28-
from pandas import compat, _np_version_under1p7
28+
from pandas import compat
2929
from pandas.compat import range, map, zip, u
3030
from pandas.tseries.timedeltas import _coerce_scalar_to_timedelta_type
3131

@@ -1298,10 +1298,8 @@ def to_native_types(self, slicer=None, na_rep=None, **kwargs):
12981298
def get_values(self, dtype=None):
12991299
# return object dtypes as datetime.timedeltas
13001300
if dtype == object:
1301-
if _np_version_under1p7:
1302-
return self.values.astype('object')
13031301
return lib.map_infer(self.values.ravel(),
1304-
lambda x: timedelta(microseconds=x.item()/1000)
1302+
lambda x: timedelta(microseconds=x.item() / 1000)
13051303
).reshape(self.values.shape)
13061304
return self.values
13071305

pandas/core/ops.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,7 @@ def __init__(self, left, right, name):
258258
self.is_datetime_lhs = com.is_datetime64_dtype(left)
259259
self.is_integer_lhs = left.dtype.kind in ['i', 'u']
260260
self.is_datetime_rhs = com.is_datetime64_dtype(rvalues)
261-
self.is_timedelta_rhs = (com.is_timedelta64_dtype(rvalues)
262-
or (not self.is_datetime_rhs
263-
and pd._np_version_under1p7))
261+
self.is_timedelta_rhs = com.is_timedelta64_dtype(rvalues)
264262
self.is_integer_rhs = rvalues.dtype.kind in ('i', 'u')
265263

266264
self._validate()
@@ -318,7 +316,7 @@ def _convert_to_array(self, values, name=None, other=None):
318316
"""converts values to ndarray"""
319317
from pandas.tseries.timedeltas import _possibly_cast_to_timedelta
320318

321-
coerce = 'compat' if pd._np_version_under1p7 else True
319+
coerce = True
322320
if not is_list_like(values):
323321
values = np.array([values])
324322
inferred_type = lib.infer_dtype(values)
@@ -648,13 +646,7 @@ def _radd_compat(left, right):
648646
try:
649647
output = radd(left, right)
650648
except TypeError:
651-
cond = (pd._np_version_under1p6 and
652-
left.dtype == np.object_)
653-
if cond: # pragma: no cover
654-
output = np.empty_like(left)
655-
output.flat[:] = [radd(x, right) for x in left.flat]
656-
else:
657-
raise
649+
raise
658650

659651
return output
660652

pandas/io/pytables.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import numpy as np
1616
from pandas import (Series, TimeSeries, DataFrame, Panel, Panel4D, Index,
17-
MultiIndex, Int64Index, Timestamp, _np_version_under1p7)
17+
MultiIndex, Int64Index, Timestamp)
1818
from pandas.sparse.api import SparseSeries, SparseDataFrame, SparsePanel
1919
from pandas.sparse.array import BlockIndex, IntIndex
2020
from pandas.tseries.api import PeriodIndex, DatetimeIndex
@@ -1721,9 +1721,6 @@ def set_atom(self, block, block_items, existing_col, min_itemsize,
17211721
if inferred_type == 'datetime64':
17221722
self.set_atom_datetime64(block)
17231723
elif dtype == 'timedelta64[ns]':
1724-
if _np_version_under1p7:
1725-
raise TypeError(
1726-
"timdelta64 is not supported under under numpy < 1.7")
17271724
self.set_atom_timedelta64(block)
17281725
elif inferred_type == 'date':
17291726
raise TypeError(
@@ -2240,9 +2237,6 @@ def read_array(self, key):
22402237
if dtype == u('datetime64'):
22412238
ret = np.array(ret, dtype='M8[ns]')
22422239
elif dtype == u('timedelta64'):
2243-
if _np_version_under1p7:
2244-
raise TypeError(
2245-
"timedelta64 is not supported under under numpy < 1.7")
22462240
ret = np.array(ret, dtype='m8[ns]')
22472241

22482242
if transposed:

pandas/io/tests/test_json/test_pandas.py

-2
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,6 @@ def test_url(self):
601601
self.assertEqual(result[c].dtype, 'datetime64[ns]')
602602

603603
def test_timedelta(self):
604-
tm._skip_if_not_numpy17_friendly()
605-
606604
from datetime import timedelta
607605
converter = lambda x: pd.to_timedelta(x,unit='ms')
608606

pandas/io/tests/test_pytables.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
assert_frame_equal,
2323
assert_series_equal)
2424
from pandas import concat, Timestamp
25-
from pandas import compat, _np_version_under1p7
25+
from pandas import compat
2626
from pandas.compat import range, lrange, u
2727
from pandas.util.testing import assert_produces_warning
2828

@@ -2159,8 +2159,6 @@ def setTZ(tz):
21592159
setTZ(orig_tz)
21602160

21612161
def test_append_with_timedelta(self):
2162-
tm._skip_if_not_numpy17_friendly()
2163-
21642162
# GH 3577
21652163
# append timedelta
21662164

pandas/io/tests/test_sql.py

-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
import pandas.io.sql as sql
3838
import pandas.util.testing as tm
39-
from pandas import _np_version_under1p7
4039

4140

4241
try:
@@ -509,8 +508,6 @@ def test_date_and_index(self):
509508

510509
def test_timedelta(self):
511510
# see #6921
512-
tm._skip_if_not_numpy17_friendly()
513-
514511
df = to_timedelta(Series(['00:00:01', '00:00:03'], name='foo')).to_frame()
515512
with tm.assert_produces_warning(UserWarning):
516513
df.to_sql('test_timedelta', self.conn)

0 commit comments

Comments
 (0)