Skip to content

Commit 81169f9

Browse files
committed
BUG: allow integer dtypes in pivot_annual #2019
1 parent 5645be2 commit 81169f9

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

pandas/tseries/tests/test_util.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def test_daily(self):
4040
def test_hourly(self):
4141
rng_hourly = date_range('1/1/1994', periods=(18* 8760 + 4*24), freq='H')
4242
data_hourly = np.random.randint(100, 350, rng_hourly.size)
43-
data_hourly = data_hourly.astype('float64')
4443
ts_hourly = Series(data_hourly, index=rng_hourly)
4544

4645
grouped = ts_hourly.groupby(ts_hourly.index.year)
@@ -51,6 +50,7 @@ def test_hourly(self):
5150

5251
annual = pivot_annual(ts_hourly)
5352

53+
ts_hourly = ts_hourly.astype(float)
5454
for i in [1, 1416, 1417, 1418, 1439, 1440, 1441, 8784]:
5555
subset = ts_hourly[hoy == i]
5656
subset.index = [x.year for x in subset.index]
@@ -103,4 +103,3 @@ def test_normalize_date():
103103
if __name__ == '__main__':
104104
nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],
105105
exit=False)
106-

pandas/tseries/util.py

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

33
import pandas as pd
44

5+
import pandas.core.common as com
56
from pandas.core.frame import DataFrame
67
import pandas.core.nanops as nanops
78

@@ -71,13 +72,8 @@ def pivot_annual(series, freq=None):
7172

7273
flat_index = (year - years.min()) * width + offset
7374

74-
values = np.empty((len(years), width), dtype=series.dtype)
75-
76-
if not np.issubdtype(series.dtype, np.integer):
77-
values.fill(np.nan)
78-
else:
79-
raise Exception('need to upcast')
80-
75+
values = np.empty((len(years), width))
76+
values.fill(np.nan)
8177
values.put(flat_index, series.values)
8278

8379
return DataFrame(values, index=years, columns=columns)

0 commit comments

Comments
 (0)