Skip to content

Commit c807f81

Browse files
committed
BUG: test suite passes, though negative ordinals broken
1 parent b3c0eb0 commit c807f81

File tree

2 files changed

+45
-23
lines changed

2 files changed

+45
-23
lines changed

pandas/src/period.c

+32-11
Original file line numberDiff line numberDiff line change
@@ -392,20 +392,29 @@ static npy_int64 asfreq_StoD(npy_int64 ordinal, char relation, asfreq_info *af_i
392392

393393
static npy_int64 asfreq_StoA(npy_int64 ordinal, char relation, asfreq_info *af_info)
394394
{ return asfreq_DtoA(asfreq_StoD(ordinal, relation, &NULL_AF_INFO), relation, af_info); }
395+
395396
static npy_int64 asfreq_StoQ(npy_int64 ordinal, char relation, asfreq_info *af_info)
396397
{ return asfreq_DtoQ(asfreq_StoD(ordinal, relation, &NULL_AF_INFO), relation, af_info); }
398+
397399
static npy_int64 asfreq_StoM(npy_int64 ordinal, char relation, asfreq_info *af_info)
398400
{ return asfreq_DtoM(asfreq_StoD(ordinal, relation, &NULL_AF_INFO), relation, &NULL_AF_INFO); }
401+
399402
static npy_int64 asfreq_StoW(npy_int64 ordinal, char relation, asfreq_info *af_info)
400403
{ return asfreq_DtoW(asfreq_StoD(ordinal, relation, &NULL_AF_INFO), relation, af_info); }
404+
401405
static npy_int64 asfreq_StoB(npy_int64 ordinal, char relation, asfreq_info *af_info)
402406
{ return asfreq_DtoB(asfreq_StoD(ordinal, relation, &NULL_AF_INFO), relation, &NULL_AF_INFO); }
407+
403408
static npy_int64 asfreq_StoB_forConvert(npy_int64 ordinal, char relation, asfreq_info *af_info)
404409
{ return asfreq_DtoB_forConvert(asfreq_StoD(ordinal, relation, &NULL_AF_INFO), relation, &NULL_AF_INFO); }
405-
static npy_int64 asfreq_StoT(npy_int64 ordinal, char relation, asfreq_info *af_info)
406-
{ return (ordinal - 1)/60 + 1; }
407-
static npy_int64 asfreq_StoH(npy_int64 ordinal, char relation, asfreq_info *af_info)
408-
{ return (ordinal - 1)/(60*60) + 1; }
410+
411+
static npy_int64 asfreq_StoT(npy_int64 ordinal, char relation, asfreq_info *af_info) {
412+
return ordinal / 60;
413+
}
414+
415+
static npy_int64 asfreq_StoH(npy_int64 ordinal, char relation, asfreq_info *af_info) {
416+
return ordinal / (60*60);
417+
}
409418

410419
//************ FROM MINUTELY ***************
411420

@@ -426,11 +435,17 @@ static npy_int64 asfreq_TtoB(npy_int64 ordinal, char relation, asfreq_info *af_i
426435
static npy_int64 asfreq_TtoB_forConvert(npy_int64 ordinal, char relation, asfreq_info *af_info)
427436
{ return asfreq_DtoB_forConvert(asfreq_TtoD(ordinal, relation, &NULL_AF_INFO), relation, &NULL_AF_INFO); }
428437

429-
static npy_int64 asfreq_TtoH(npy_int64 ordinal, char relation, asfreq_info *af_info)
430-
{ return (ordinal - 1)/60 + 1; }
438+
static npy_int64 asfreq_TtoH(npy_int64 ordinal, char relation, asfreq_info *af_info) {
439+
return ordinal / 60;
440+
}
441+
431442
static npy_int64 asfreq_TtoS(npy_int64 ordinal, char relation, asfreq_info *af_info) {
432-
if (relation == 'S') { return ordinal*60 - 59; }
433-
else { return ordinal*60; }}
443+
if (relation == 'S') {
444+
return ordinal*60; }
445+
else {
446+
return ordinal*60 + 59;
447+
}
448+
}
434449

435450
//************ FROM HOURLY ***************
436451

@@ -453,9 +468,15 @@ static npy_int64 asfreq_HtoB_forConvert(npy_int64 ordinal, char relation, asfreq
453468
// calculation works out the same as TtoS, so we just call that function for HtoT
454469
static npy_int64 asfreq_HtoT(npy_int64 ordinal, char relation, asfreq_info *af_info)
455470
{ return asfreq_TtoS(ordinal, relation, &NULL_AF_INFO); }
471+
456472
static npy_int64 asfreq_HtoS(npy_int64 ordinal, char relation, asfreq_info *af_info) {
457-
if (relation == 'S') { return ordinal*60*60 - 60*60 + 1; }
458-
else { return ordinal*60*60; }}
473+
if (relation == 'S') {
474+
return ordinal*60*60;
475+
}
476+
else {
477+
return (ordinal + 1)*60*60 - 1;
478+
}
479+
}
459480

460481
//************ FROM BUSINESS ***************
461482

@@ -1189,7 +1210,7 @@ char *skts_strftime(npy_int64 ordinal, int freq, PyObject *args)
11891210
daily_ord = toDaily(ordinal, 'E', &af_info);
11901211
abstime = get_abs_time(freq, daily_ord, ordinal);
11911212

1192-
printf("daily_ord: %d, abstime: %f \n", (int) daily_ord, abstime);
1213+
/* printf("daily_ord: %d, abstime: %f \n", (int) daily_ord, abstime); */
11931214

11941215
if(dInfoCalc_SetFromAbsDateTime(&tempDate, daily_ord + ORD_OFFSET, abstime,
11951216
GREGORIAN_CALENDAR)) return NULL;

pandas/tests/test_tseries.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pandas.util.testing import assert_almost_equal
77
import pandas.util.testing as common
88
import pandas._tseries as lib
9+
import pandas._algos as algos
910
from datetime import datetime
1011

1112
class TestTseriesUtil(unittest.TestCase):
@@ -29,15 +30,15 @@ def test_backfill(self):
2930
old = Index([1, 5, 10])
3031
new = Index(range(12))
3132

32-
filler = lib.backfill_int64(old, new)
33+
filler = algos.backfill_int64(old, new)
3334

3435
expect_filler = [0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, -1]
3536
self.assert_(np.array_equal(filler, expect_filler))
3637

3738
# corner case
3839
old = Index([1, 4])
3940
new = Index(range(5, 10))
40-
filler = lib.backfill_int64(old, new)
41+
filler = algos.backfill_int64(old, new)
4142

4243
expect_filler = [-1, -1, -1, -1, -1]
4344
self.assert_(np.array_equal(filler, expect_filler))
@@ -46,23 +47,23 @@ def test_pad(self):
4647
old = Index([1, 5, 10])
4748
new = Index(range(12))
4849

49-
filler = lib.pad_int64(old, new)
50+
filler = algos.pad_int64(old, new)
5051

5152
expect_filler = [-1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2]
5253
self.assert_(np.array_equal(filler, expect_filler))
5354

5455
# corner case
5556
old = Index([5, 10])
5657
new = Index(range(5))
57-
filler = lib.pad_int64(old, new)
58+
filler = algos.pad_int64(old, new)
5859
expect_filler = [-1, -1, -1, -1, -1]
5960
self.assert_(np.array_equal(filler, expect_filler))
6061

6162
def test_left_join_indexer():
6263
a = np.array([1, 2, 3, 4, 5], dtype=np.int64)
6364
b = np.array([2, 2, 3, 4, 4], dtype=np.int64)
6465

65-
result = lib.left_join_indexer_int64(b, a)
66+
result = algos.left_join_indexer_int64(b, a)
6667
expected = np.array([1, 1, 2, 3, 3], dtype=np.int64)
6768
assert(np.array_equal(result, expected))
6869

@@ -91,7 +92,7 @@ def test_inner_join_indexer():
9192
a = np.array([1, 2, 3, 4, 5], dtype=np.int64)
9293
b = np.array([0, 3, 5, 7, 9], dtype=np.int64)
9394

94-
index, ares, bres = lib.inner_join_indexer_int64(a, b)
95+
index, ares, bres = algos.inner_join_indexer_int64(a, b)
9596

9697
index_exp = np.array([3, 5], dtype=np.int64)
9798
assert_almost_equal(index, index_exp)
@@ -105,7 +106,7 @@ def test_outer_join_indexer():
105106
a = np.array([1, 2, 3, 4, 5], dtype=np.int64)
106107
b = np.array([0, 3, 5, 7, 9], dtype=np.int64)
107108

108-
index, ares, bres = lib.outer_join_indexer_int64(a, b)
109+
index, ares, bres = algos.outer_join_indexer_int64(a, b)
109110

110111
index_exp = np.array([0, 1, 2, 3, 4, 5, 7, 9], dtype=np.int64)
111112
assert_almost_equal(index, index_exp)
@@ -233,25 +234,25 @@ def test_pad_backfill_object_segfault():
233234
old = np.array([], dtype='O')
234235
new = np.array([datetime(2010, 12, 31)], dtype='O')
235236

236-
result = lib.pad_object(old, new)
237+
result = algos.pad_object(old, new)
237238
expected = np.array([-1], dtype=np.int64)
238239
assert(np.array_equal(result, expected))
239240

240-
result = lib.pad_object(new, old)
241+
result = algos.pad_object(new, old)
241242
expected = np.array([], dtype=np.int64)
242243
assert(np.array_equal(result, expected))
243244

244-
result = lib.backfill_object(old, new)
245+
result = algos.backfill_object(old, new)
245246
expected = np.array([-1], dtype=np.int64)
246247
assert(np.array_equal(result, expected))
247248

248-
result = lib.backfill_object(new, old)
249+
result = algos.backfill_object(new, old)
249250
expected = np.array([], dtype=np.int64)
250251
assert(np.array_equal(result, expected))
251252

252253
def test_arrmap():
253254
values = np.array(['foo', 'foo', 'bar', 'bar', 'baz', 'qux'], dtype='O')
254-
result = lib.arrmap_object(values, lambda x: x in ['foo', 'bar'])
255+
result = algos.arrmap_object(values, lambda x: x in ['foo', 'bar'])
255256
assert(result.dtype == np.bool_)
256257

257258
def test_series_grouper():

0 commit comments

Comments
 (0)