|
22 | 22 | notnull, _DATELIKE_DTYPES) |
23 | 23 |
|
24 | 24 | import pandas.lib as lib |
| 25 | +from pandas.lib import Timestamp |
25 | 26 | import pandas.algos as _algos |
26 | 27 | import pandas.hashtable as _hash |
27 | 28 |
|
@@ -257,6 +258,12 @@ def indices(self): |
257 | 258 | """ dict {group name -> group indices} """ |
258 | 259 | return self.grouper.indices |
259 | 260 |
|
| 261 | + def _get_index(self, name): |
| 262 | + """ safe get index """ |
| 263 | + if isinstance(name, Timestamp): |
| 264 | + name = name.value |
| 265 | + return self.indices[name] |
| 266 | + |
260 | 267 | @property |
261 | 268 | def name(self): |
262 | 269 | if self._selection is None: |
@@ -350,7 +357,7 @@ def get_group(self, name, obj=None): |
350 | 357 | if obj is None: |
351 | 358 | obj = self.obj |
352 | 359 |
|
353 | | - inds = self.indices[name] |
| 360 | + inds = self._get_index(name) |
354 | 361 | return obj.take(inds, axis=self.axis, convert=False) |
355 | 362 |
|
356 | 363 | def __iter__(self): |
@@ -1821,7 +1828,7 @@ def transform(self, func, *args, **kwargs): |
1821 | 1828 | # need to do a safe put here, as the dtype may be different |
1822 | 1829 | # this needs to be an ndarray |
1823 | 1830 | result = Series(result) |
1824 | | - result.iloc[self.indices[name]] = res |
| 1831 | + result.iloc[self._get_index(name)] = res |
1825 | 1832 | result = result.values |
1826 | 1833 |
|
1827 | 1834 | # downcast if we can (and need) |
@@ -1860,7 +1867,7 @@ def true_and_notnull(x, *args, **kwargs): |
1860 | 1867 | return b and notnull(b) |
1861 | 1868 |
|
1862 | 1869 | try: |
1863 | | - indices = [self.indices[name] if true_and_notnull(group) else [] |
| 1870 | + indices = [self._get_index(name) if true_and_notnull(group) else [] |
1864 | 1871 | for name, group in self] |
1865 | 1872 | except ValueError: |
1866 | 1873 | raise TypeError("the filter must return a boolean result") |
@@ -2412,7 +2419,7 @@ def filter(self, func, dropna=True, *args, **kwargs): |
2412 | 2419 | res = path(group) |
2413 | 2420 |
|
2414 | 2421 | def add_indices(): |
2415 | | - indices.append(self.indices[name]) |
| 2422 | + indices.append(self._get_index(name)) |
2416 | 2423 |
|
2417 | 2424 | # interpret the result of the filter |
2418 | 2425 | if isinstance(res, (bool, np.bool_)): |
|
0 commit comments