Skip to content

CLN: remove unreachable code in tslib.pyx #5067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 1, 2013
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
48 changes: 24 additions & 24 deletions pandas/tseries/tests/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
DateOffset, Week, YearBegin, YearEnd, Hour, Minute, Second, Day, Micro,
Milli, Nano,
WeekOfMonth, format, ole2datetime, QuarterEnd, to_datetime, normalize_date,
get_offset, get_offset_name, inferTimeRule, hasOffsetName,
get_standard_freq)
get_offset, get_offset_name, hasOffsetName, get_standard_freq)

from pandas.tseries.frequencies import _offset_map
from pandas.tseries.index import _to_m8, DatetimeIndex, _daterange_cache
Expand Down Expand Up @@ -532,7 +531,7 @@ def test_repr(self):
self.assertEqual(repr(Week(weekday=0)), "<Week: weekday=0>")
self.assertEqual(repr(Week(n=-1, weekday=0)), "<-1 * Week: weekday=0>")
self.assertEqual(repr(Week(n=-2, weekday=0)), "<-2 * Weeks: weekday=0>")

def test_corner(self):
self.assertRaises(ValueError, Week, weekday=7)
assertRaisesRegexp(ValueError, "Day must be", Week, weekday=-1)
Expand Down Expand Up @@ -905,7 +904,7 @@ def test_onOffset(self):


class TestBQuarterBegin(unittest.TestCase):

def test_repr(self):
self.assertEqual(repr(BQuarterBegin()),"<BusinessQuarterBegin: startingMonth=3>")
self.assertEqual(repr(BQuarterBegin(startingMonth=3)), "<BusinessQuarterBegin: startingMonth=3>")
Expand Down Expand Up @@ -1000,7 +999,7 @@ def test_repr(self):
self.assertEqual(repr(BQuarterEnd()),"<BusinessQuarterEnd: startingMonth=3>")
self.assertEqual(repr(BQuarterEnd(startingMonth=3)), "<BusinessQuarterEnd: startingMonth=3>")
self.assertEqual(repr(BQuarterEnd(startingMonth=1)), "<BusinessQuarterEnd: startingMonth=1>")

def test_isAnchored(self):
self.assert_(BQuarterEnd(startingMonth=1).isAnchored())
self.assert_(BQuarterEnd().isAnchored())
Expand Down Expand Up @@ -1107,7 +1106,7 @@ def test_repr(self):
self.assertEqual(repr(QuarterBegin()), "<QuarterBegin: startingMonth=3>")
self.assertEqual(repr(QuarterBegin(startingMonth=3)), "<QuarterBegin: startingMonth=3>")
self.assertEqual(repr(QuarterBegin(startingMonth=1)),"<QuarterBegin: startingMonth=1>")

def test_isAnchored(self):
self.assert_(QuarterBegin(startingMonth=1).isAnchored())
self.assert_(QuarterBegin().isAnchored())
Expand Down Expand Up @@ -1181,7 +1180,7 @@ def test_repr(self):
self.assertEqual(repr(QuarterEnd()), "<QuarterEnd: startingMonth=3>")
self.assertEqual(repr(QuarterEnd(startingMonth=3)), "<QuarterEnd: startingMonth=3>")
self.assertEqual(repr(QuarterEnd(startingMonth=1)), "<QuarterEnd: startingMonth=1>")

def test_isAnchored(self):
self.assert_(QuarterEnd(startingMonth=1).isAnchored())
self.assert_(QuarterEnd().isAnchored())
Expand Down Expand Up @@ -1631,6 +1630,7 @@ def assertEq(offset, base, expected):
"\nAt Date: %s" %
(expected, actual, offset, base))


def test_Hour():
assertEq(Hour(), datetime(2010, 1, 1), datetime(2010, 1, 1, 1))
assertEq(Hour(-1), datetime(2010, 1, 1, 1), datetime(2010, 1, 1))
Expand Down Expand Up @@ -1698,6 +1698,8 @@ def test_Microsecond():


def test_NanosecondGeneric():
if _np_version_under1p7:
raise nose.SkipTest('numpy >= 1.7 required')
timestamp = Timestamp(datetime(2010, 1, 1))
assert timestamp.nanosecond == 0

Expand All @@ -1710,7 +1712,6 @@ def test_NanosecondGeneric():

def test_Nanosecond():
if _np_version_under1p7:
import nose
raise nose.SkipTest('numpy >= 1.7 required')

timestamp = Timestamp(datetime(2010, 1, 1))
Expand Down Expand Up @@ -1815,8 +1816,6 @@ def setUp(self):
pass

def test_alias_equality(self):
from pandas.tseries.frequencies import _offset_map

for k, v in compat.iteritems(_offset_map):
if v is None:
continue
Expand Down Expand Up @@ -1872,7 +1871,8 @@ def test_freq_offsets():

off = BDay(1, offset=timedelta(0, -1800))
assert(off.freqstr == 'B-30Min')



def get_all_subclasses(cls):
ret = set()
this_subclasses = cls.__subclasses__()
Expand All @@ -1881,40 +1881,41 @@ def get_all_subclasses(cls):
ret | get_all_subclasses(this_subclass)
return ret

class TestCaching(unittest.TestCase):

class TestCaching(unittest.TestCase):
def test_should_cache_month_end(self):
self.assertTrue(MonthEnd()._should_cache())

def test_should_cache_bmonth_end(self):
self.assertTrue(BusinessMonthEnd()._should_cache())

def test_should_cache_week_month(self):
self.assertTrue(WeekOfMonth(weekday=1, week=2)._should_cache())

def test_all_cacheableoffsets(self):
for subclass in get_all_subclasses(CacheableOffset):
if subclass in [WeekOfMonth]:
continue
self.run_X_index_creation(subclass)

def setUp(self):
_daterange_cache.clear()

def run_X_index_creation(self, cls):
inst1 = cls()
if not inst1.isAnchored():
self.assertFalse(inst1._should_cache(), cls)
return

self.assertTrue(inst1._should_cache(), cls)

DatetimeIndex(start=datetime(2013,1,31), end=datetime(2013,3,31), freq=inst1, normalize=True)
self.assertTrue(cls() in _daterange_cache, cls)

def test_month_end_index_creation(self):
DatetimeIndex(start=datetime(2013,1,31), end=datetime(2013,3,31), freq=MonthEnd(), normalize=True)
self.assertTrue(MonthEnd() in _daterange_cache)

def test_bmonth_end_index_creation(self):
DatetimeIndex(start=datetime(2013,1,31), end=datetime(2013,3,29), freq=BusinessMonthEnd(), normalize=True)
self.assertTrue(BusinessMonthEnd() in _daterange_cache)
Expand All @@ -1924,9 +1925,8 @@ def test_week_of_month_index_creation(self):
DatetimeIndex(start=datetime(2013,1,31), end=datetime(2013,3,29), freq=inst1, normalize=True)
inst2 = WeekOfMonth(weekday=1, week=2)
self.assertTrue(inst2 in _daterange_cache)


if __name__ == '__main__':
import nose
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
exit=False)
30 changes: 15 additions & 15 deletions pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class NaTType(_NaT):

def __hash__(self):
return iNaT

def weekday(self):
return -1

Expand Down Expand Up @@ -573,22 +573,22 @@ cdef class _Timestamp(datetime):
dts.us, ts.tzinfo)

def __add__(self, other):
cdef Py_ssize_t other_int

if is_timedelta64_object(other):
return Timestamp(self.value + other.astype('timedelta64[ns]').item(), tz=self.tzinfo)

other_int = other.astype('timedelta64[ns]').astype(int)
return Timestamp(self.value + other_int, tz=self.tzinfo)

if is_integer_object(other):
if self.offset is None:
return Timestamp(self.value + other, tz=self.tzinfo)
msg = ("Cannot add integral value to Timestamp "
"without offset.")
raise ValueError(msg)
else:
return Timestamp((self.offset.__mul__(other)).apply(self))

raise ValueError("Cannot add integral value to Timestamp "
"without offset.")
return Timestamp((self.offset * other).apply(self))

if isinstance(other, timedelta) or hasattr(other, 'delta'):
nanos = _delta_to_nanoseconds(other)
return Timestamp(self.value + nanos, tz=self.tzinfo)

result = datetime.__add__(self, other)
if isinstance(result, datetime):
result = Timestamp(result)
Expand All @@ -597,9 +597,9 @@ cdef class _Timestamp(datetime):

def __sub__(self, other):
if is_integer_object(other):
return self.__add__(-other)
else:
return datetime.__sub__(self, other)
neg_other = -other
return self + neg_other
return super(_Timestamp, self).__sub__(other)

cpdef _get_field(self, field):
out = get_date_field(np.array([self.value], dtype=np.int64), field)
Expand Down Expand Up @@ -2329,7 +2329,7 @@ cpdef int64_t period_asfreq(int64_t period_ordinal, int freq1, int freq2,
"""
cdef:
int64_t retval

if end:
retval = asfreq(period_ordinal, freq1, freq2, END)
else:
Expand Down