Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pandas/compat/numpy_compat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" support numpy compatiblitiy across versions """

import re
import numpy as np
from distutils.version import LooseVersion
from pandas.compat import string_types, string_and_binary_types
Expand All @@ -24,11 +25,14 @@
'this pandas version'.format(_np_version))


_tz_regex = re.compile('[+-]0000$')


def tz_replacer(s):
if isinstance(s, string_types):
if s.endswith('Z'):
s = s[:-1]
elif s.endswith('-0000'):
elif _tz_regex.search(s):
s = s[:-5]
return s

Expand Down
20 changes: 3 additions & 17 deletions pandas/computation/tests/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,7 @@ def _eval_single_bin(lhs, cmp1, rhs, engine):
try:
return c(lhs, rhs)
except ValueError as e:
try:
msg = e.message
except AttributeError:
msg = e
msg = u(msg)
if msg == u('negative number cannot be raised to a fractional'
' power'):
if str(e).startswith('negative number cannot be raised to a fractional power'):
Copy link
Member

@gfyoung gfyoung Apr 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing one more in this file. Just search for = e.message (deprecated) in your changed file and get rid of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm

return np.nan
raise
return c(lhs, rhs)
Expand Down Expand Up @@ -306,17 +300,9 @@ def get_expected_pow_result(self, lhs, rhs):
try:
expected = _eval_single_bin(lhs, '**', rhs, self.engine)
except ValueError as e:
msg = 'negative number cannot be raised to a fractional power'
try:
emsg = e.message
except AttributeError:
emsg = e

emsg = u(emsg)

if emsg == msg:
if str(e).startswith('negative number cannot be raised to a fractional power'):
if self.engine == 'python':
raise nose.SkipTest(emsg)
raise nose.SkipTest(str(e))
else:
expected = np.nan
else:
Expand Down
24 changes: 11 additions & 13 deletions pandas/io/tests/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2174,19 +2174,17 @@ def check_called(func):
del called_save[:]
del called_write_cells[:]

register_writer(DummyClass)
writer = ExcelWriter('something.test')
tm.assertIsInstance(writer, DummyClass)
df = tm.makeCustomDataframe(1, 1)
panel = tm.makePanel()
func = lambda: df.to_excel('something.test')
check_called(func)
check_called(lambda: panel.to_excel('something.test'))
val = get_option('io.excel.xlsx.writer')
set_option('io.excel.xlsx.writer', 'dummy')
check_called(lambda: df.to_excel('something.xlsx'))
check_called(lambda: df.to_excel('something.xls', engine='dummy'))
set_option('io.excel.xlsx.writer', val)
with pd.option_context('io.excel.xlsx.writer', 'dummy'):
register_writer(DummyClass)
writer = ExcelWriter('something.test')
tm.assertIsInstance(writer, DummyClass)
df = tm.makeCustomDataframe(1, 1)
panel = tm.makePanel()
func = lambda: df.to_excel('something.test')
check_called(func)
check_called(lambda: panel.to_excel('something.test'))
check_called(lambda: df.to_excel('something.xlsx'))
check_called(lambda: df.to_excel('something.xls', engine='dummy'))


if __name__ == '__main__':
Expand Down
3 changes: 2 additions & 1 deletion pandas/io/tests/test_gbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pandas.core.frame import DataFrame
import pandas.io.gbq as gbq
import pandas.util.testing as tm
from pandas.compat.numpy_compat import np_datetime64_compat

PROJECT_ID = None
PRIVATE_KEY_JSON_PATH = None
Expand Down Expand Up @@ -289,7 +290,7 @@ def test_should_return_bigquery_floats_as_python_floats(self):

def test_should_return_bigquery_timestamps_as_numpy_datetime(self):
result = gbq._parse_entry('0e9', 'TIMESTAMP')
tm.assert_equal(result, np.datetime64('1970-01-01T00:00:00Z'))
tm.assert_equal(result, np_datetime64_compat('1970-01-01T00:00:00Z'))

def test_should_return_bigquery_booleans_as_python_booleans(self):
result = gbq._parse_entry('false', 'BOOLEAN')
Expand Down
4 changes: 3 additions & 1 deletion pandas/io/tests/test_packers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import nose

import warnings
import os
import datetime
import numpy as np
Expand Down Expand Up @@ -519,7 +520,8 @@ def test_sparse_frame(self):

def test_sparse_panel(self):

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
with warnings.catch_warnings(record=True):

items = ['x', 'y', 'z']
p = Panel(dict((i, tm.makeDataFrame().ix[:2, :2]) for i in items))
sp = p.to_sparse()
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,11 +848,11 @@ def test_append(self):

# uints - test storage of uints
uint_data = DataFrame({
'u08': Series(np.random.random_integers(0, high=255, size=5),
'u08': Series(np.random.randint(0, high=255, size=5),
dtype=np.uint8),
'u16': Series(np.random.random_integers(0, high=65535, size=5),
'u16': Series(np.random.randint(0, high=65535, size=5),
dtype=np.uint16),
'u32': Series(np.random.random_integers(0, high=2**30, size=5),
'u32': Series(np.random.randint(0, high=2**30, size=5),
dtype=np.uint32),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this a problem, but these function calls aren't quite equivalent (closed vs. open interval for random_integers and randint respectively).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they seem the same.

Copy link
Member

@gfyoung gfyoung Apr 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a moot point if Travis is still happy, but for reference, they are not equivalent by definition.

'u64': Series([2**58, 2**59, 2**60, 2**61, 2**62],
dtype=np.uint64)}, index=np.arange(5))
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import IPython
if IPython.__version__ < LooseVersion('3.0.0'):
div_style = ' style="max-width:1500px;overflow:auto;"'
except ImportError:
except (ImportError, AttributeError):
pass

from pandas import DataFrame, Series, Index, Timestamp, MultiIndex, date_range, NaT
Expand Down
17 changes: 9 additions & 8 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CategoricalIndex, DatetimeIndex, TimedeltaIndex,
PeriodIndex)
from pandas.util.testing import assert_almost_equal
from pandas.compat.numpy_compat import np_datetime64_compat

import pandas.core.config as cf

Expand Down Expand Up @@ -250,18 +251,18 @@ def test_constructor_dtypes(self):

for idx in [Index(np.array([1, 2, 3], dtype=int), dtype='category'),
Index([1, 2, 3], dtype='category'),
Index(np.array([np.datetime64('2011-01-01'),
np.datetime64('2011-01-02')]), dtype='category'),
Index(np.array([np_datetime64_compat('2011-01-01'),
np_datetime64_compat('2011-01-02')]), dtype='category'),
Index([datetime(2011, 1, 1), datetime(2011, 1, 2)], dtype='category')]:
self.assertIsInstance(idx, CategoricalIndex)

for idx in [Index(np.array([np.datetime64('2011-01-01'),
np.datetime64('2011-01-02')])),
for idx in [Index(np.array([np_datetime64_compat('2011-01-01'),
np_datetime64_compat('2011-01-02')])),
Index([datetime(2011, 1, 1), datetime(2011, 1, 2)])]:
self.assertIsInstance(idx, DatetimeIndex)

for idx in [Index(np.array([np.datetime64('2011-01-01'),
np.datetime64('2011-01-02')]), dtype=object),
for idx in [Index(np.array([np_datetime64_compat('2011-01-01'),
np_datetime64_compat('2011-01-02')]), dtype=object),
Index([datetime(2011, 1, 1),
datetime(2011, 1, 2)], dtype=object)]:
self.assertNotIsInstance(idx, DatetimeIndex)
Expand Down Expand Up @@ -442,8 +443,8 @@ def test_nanosecond_index_access(self):

self.assertEqual(
first_value,
x[Timestamp(np.datetime64('2013-01-01 00:00:00.000000050+0000',
'ns'))])
x[Timestamp(np_datetime64_compat('2013-01-01 00:00:00.000000050+0000',
'ns'))])

def test_comparators(self):
index = self.dateIndex
Expand Down
8 changes: 5 additions & 3 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pandas.core.algorithms as algos
import pandas.util.testing as tm
import pandas.hashtable as hashtable
from pandas.compat.numpy_compat import np_array_datetime64_compat


class TestMatch(tm.TestCase):
Expand Down Expand Up @@ -275,9 +276,10 @@ def test_on_index_object(self):

def test_datetime64_dtype_array_returned(self):
# GH 9431
expected = np.array(['2015-01-03T00:00:00.000000000+0000',
'2015-01-01T00:00:00.000000000+0000'],
dtype='M8[ns]')
expected = np_array_datetime64_compat(
['2015-01-03T00:00:00.000000000+0000',
'2015-01-01T00:00:00.000000000+0000'],
dtype='M8[ns]')

dt_index = pd.to_datetime(['2015-01-03T00:00:00.000000000+0000',
'2015-01-01T00:00:00.000000000+0000',
Expand Down
9 changes: 5 additions & 4 deletions pandas/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pandas import (Series, Index, DatetimeIndex, TimedeltaIndex, PeriodIndex,
Timedelta)
from pandas.compat import u, StringIO
from pandas.compat.numpy_compat import np_array_datetime64_compat
from pandas.core.base import (FrozenList, FrozenNDArray, PandasDelegate,
NoNewAttributesMixin)
from pandas.tseries.base import DatetimeIndexOpsMixin
Expand Down Expand Up @@ -663,10 +664,10 @@ def test_value_counts_inferred(self):
expected_s = Series([3, 2, 1], index=idx)
tm.assert_series_equal(s.value_counts(), expected_s)

expected = np.array(['2010-01-01 00:00:00Z',
'2009-01-01 00:00:00Z',
'2008-09-09 00:00:00Z'],
dtype='datetime64[ns]')
expected = np_array_datetime64_compat(['2010-01-01 00:00:00Z',
'2009-01-01 00:00:00Z',
'2008-09-09 00:00:00Z'],
dtype='datetime64[ns]')
if isinstance(s, DatetimeIndex):
expected = DatetimeIndex(expected)
self.assertTrue(s.unique().equals(expected))
Expand Down
22 changes: 13 additions & 9 deletions pandas/tseries/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pandas.compat import u
import pandas.util.testing as tm
from pandas.tseries.offsets import Second, Milli, Micro
from pandas.compat.numpy_compat import np_datetime64_compat

try:
import pandas.tseries.converter as converter
Expand Down Expand Up @@ -50,16 +51,16 @@ def test_conversion(self):
self.assertEqual(rs, xp)

# also testing datetime64 dtype (GH8614)
rs = self.dtc.convert(np.datetime64('2012-01-01'), None, None)
rs = self.dtc.convert(np_datetime64_compat('2012-01-01'), None, None)
self.assertEqual(rs, xp)

rs = self.dtc.convert(np.datetime64(
'2012-01-01 00:00:00+00:00'), None, None)
rs = self.dtc.convert(np_datetime64_compat(
'2012-01-01 00:00:00+0000'), None, None)
self.assertEqual(rs, xp)

rs = self.dtc.convert(np.array([
np.datetime64('2012-01-01 00:00:00+00:00'),
np.datetime64('2012-01-02 00:00:00+00:00')]), None, None)
np_datetime64_compat('2012-01-01 00:00:00+0000'),
np_datetime64_compat('2012-01-02 00:00:00+0000')]), None, None)
self.assertEqual(rs[0], xp)

def test_conversion_float(self):
Expand Down Expand Up @@ -142,16 +143,19 @@ def test_conversion(self):
self.assertEqual(rs, xp)

# FIXME
# rs = self.pc.convert(np.datetime64('2012-01-01'), None, self.axis)
# rs = self.pc.convert(
# np_datetime64_compat('2012-01-01'), None, self.axis)
# self.assertEqual(rs, xp)
#
# rs = self.pc.convert(np.datetime64('2012-01-01 00:00:00+00:00'),
# rs = self.pc.convert(
# np_datetime64_compat('2012-01-01 00:00:00+0000'),
# None, self.axis)
# self.assertEqual(rs, xp)
#
# rs = self.pc.convert(np.array([
# np.datetime64('2012-01-01 00:00:00+00:00'),
# np.datetime64('2012-01-02 00:00:00+00:00')]), None, self.axis)
# np_datetime64_compat('2012-01-01 00:00:00+0000'),
# np_datetime64_compat('2012-01-02 00:00:00+0000')]),
# None, self.axis)
# self.assertEqual(rs[0], xp)

def test_integer_passthrough(self):
Expand Down