|
20 | 20 | is_integer_dtype,
|
21 | 21 | is_datetime64_ns_dtype,
|
22 | 22 | is_period_dtype,
|
23 |
| - is_bool_dtype, |
24 | 23 | is_string_like,
|
25 | 24 | is_list_like,
|
26 | 25 | is_scalar,
|
|
34 | 33 | from pandas.core.arrays import datetimelike as dtl
|
35 | 34 |
|
36 | 35 | from pandas.core.indexes.base import Index, _index_shared_docs
|
37 |
| -from pandas.core.indexes.numeric import Int64Index, Float64Index |
| 36 | +from pandas.core.indexes.numeric import Int64Index |
38 | 37 | import pandas.compat as compat
|
39 | 38 | from pandas.tseries.frequencies import to_offset, Resolution
|
40 | 39 | from pandas.core.indexes.datetimelike import (
|
41 |
| - DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin) |
| 40 | + DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin, |
| 41 | + wrap_field_accessor, wrap_array_method) |
42 | 42 | from pandas.tseries.offsets import (
|
43 | 43 | generate_range, CDay, prefix_mapping)
|
44 | 44 |
|
|
53 | 53 | from pandas._libs.tslibs import (timezones, conversion, fields, parsing,
|
54 | 54 | ccalendar)
|
55 | 55 |
|
56 |
| -# -------- some conversion wrapper functions |
57 |
| - |
58 |
| - |
59 |
| -def _wrap_field_accessor(name): |
60 |
| - fget = getattr(DatetimeArrayMixin, name).fget |
61 |
| - |
62 |
| - def f(self): |
63 |
| - result = fget(self) |
64 |
| - if is_bool_dtype(result): |
65 |
| - return result |
66 |
| - return Index(result, name=self.name) |
67 |
| - |
68 |
| - f.__name__ = name |
69 |
| - f.__doc__ = fget.__doc__ |
70 |
| - return property(f) |
71 |
| - |
72 |
| - |
73 |
| -def _wrap_in_index(name): |
74 |
| - meth = getattr(DatetimeArrayMixin, name) |
75 |
| - |
76 |
| - def func(self, *args, **kwargs): |
77 |
| - result = meth(self, *args, **kwargs) |
78 |
| - return Index(result, name=self.name) |
79 |
| - |
80 |
| - func.__doc__ = meth.__doc__ |
81 |
| - func.__name__ = name |
82 |
| - return func |
83 |
| - |
84 |
| - |
85 |
| -def _dt_index_cmp(cls, op): |
86 |
| - """ |
87 |
| - Wrap comparison operations to convert datetime-like to datetime64 |
88 |
| - """ |
89 |
| - opname = '__{name}__'.format(name=op.__name__) |
90 |
| - |
91 |
| - def wrapper(self, other): |
92 |
| - result = getattr(DatetimeArrayMixin, opname)(self, other) |
93 |
| - if is_bool_dtype(result): |
94 |
| - return result |
95 |
| - return Index(result) |
96 |
| - |
97 |
| - return compat.set_function_name(wrapper, opname, cls) |
98 |
| - |
99 | 56 |
|
100 | 57 | def _new_DatetimeIndex(cls, d):
|
101 | 58 | """ This is called upon unpickling, rather than the default which doesn't
|
@@ -233,16 +190,6 @@ def _join_i8_wrapper(joinf, **kwargs):
|
233 | 190 | _left_indexer_unique = _join_i8_wrapper(
|
234 | 191 | libjoin.left_join_indexer_unique_int64, with_indexers=False)
|
235 | 192 |
|
236 |
| - @classmethod |
237 |
| - def _add_comparison_methods(cls): |
238 |
| - """ add in comparison methods """ |
239 |
| - cls.__eq__ = _dt_index_cmp(cls, operator.eq) |
240 |
| - cls.__ne__ = _dt_index_cmp(cls, operator.ne) |
241 |
| - cls.__lt__ = _dt_index_cmp(cls, operator.lt) |
242 |
| - cls.__gt__ = _dt_index_cmp(cls, operator.gt) |
243 |
| - cls.__le__ = _dt_index_cmp(cls, operator.le) |
244 |
| - cls.__ge__ = _dt_index_cmp(cls, operator.ge) |
245 |
| - |
246 | 193 | _engine_type = libindex.DatetimeEngine
|
247 | 194 |
|
248 | 195 | tz = None
|
@@ -1273,38 +1220,38 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
|
1273 | 1220 | else:
|
1274 | 1221 | raise
|
1275 | 1222 |
|
1276 |
| - year = _wrap_field_accessor('year') |
1277 |
| - month = _wrap_field_accessor('month') |
1278 |
| - day = _wrap_field_accessor('day') |
1279 |
| - hour = _wrap_field_accessor('hour') |
1280 |
| - minute = _wrap_field_accessor('minute') |
1281 |
| - second = _wrap_field_accessor('second') |
1282 |
| - microsecond = _wrap_field_accessor('microsecond') |
1283 |
| - nanosecond = _wrap_field_accessor('nanosecond') |
1284 |
| - weekofyear = _wrap_field_accessor('weekofyear') |
| 1223 | + year = wrap_field_accessor(DatetimeArrayMixin.year) |
| 1224 | + month = wrap_field_accessor(DatetimeArrayMixin.month) |
| 1225 | + day = wrap_field_accessor(DatetimeArrayMixin.day) |
| 1226 | + hour = wrap_field_accessor(DatetimeArrayMixin.hour) |
| 1227 | + minute = wrap_field_accessor(DatetimeArrayMixin.minute) |
| 1228 | + second = wrap_field_accessor(DatetimeArrayMixin.second) |
| 1229 | + microsecond = wrap_field_accessor(DatetimeArrayMixin.microsecond) |
| 1230 | + nanosecond = wrap_field_accessor(DatetimeArrayMixin.nanosecond) |
| 1231 | + weekofyear = wrap_field_accessor(DatetimeArrayMixin.weekofyear) |
1285 | 1232 | week = weekofyear
|
1286 |
| - dayofweek = _wrap_field_accessor('dayofweek') |
| 1233 | + dayofweek = wrap_field_accessor(DatetimeArrayMixin.dayofweek) |
1287 | 1234 | weekday = dayofweek
|
1288 | 1235 |
|
1289 |
| - weekday_name = _wrap_field_accessor('weekday_name') |
| 1236 | + weekday_name = wrap_field_accessor(DatetimeArrayMixin.weekday_name) |
1290 | 1237 |
|
1291 |
| - dayofyear = _wrap_field_accessor('dayofyear') |
1292 |
| - quarter = _wrap_field_accessor('quarter') |
1293 |
| - days_in_month = _wrap_field_accessor('days_in_month') |
| 1238 | + dayofyear = wrap_field_accessor(DatetimeArrayMixin.dayofyear) |
| 1239 | + quarter = wrap_field_accessor(DatetimeArrayMixin.quarter) |
| 1240 | + days_in_month = wrap_field_accessor(DatetimeArrayMixin.days_in_month) |
1294 | 1241 | daysinmonth = days_in_month
|
1295 |
| - is_month_start = _wrap_field_accessor('is_month_start') |
1296 |
| - is_month_end = _wrap_field_accessor('is_month_end') |
1297 |
| - is_quarter_start = _wrap_field_accessor('is_quarter_start') |
1298 |
| - is_quarter_end = _wrap_field_accessor('is_quarter_end') |
1299 |
| - is_year_start = _wrap_field_accessor('is_year_start') |
1300 |
| - is_year_end = _wrap_field_accessor('is_year_end') |
1301 |
| - is_leap_year = _wrap_field_accessor('is_leap_year') |
1302 |
| - |
1303 |
| - @Appender(DatetimeArrayMixin.normalize.__doc__) |
1304 |
| - def normalize(self): |
1305 |
| - result = DatetimeArrayMixin.normalize(self) |
1306 |
| - result.name = self.name |
1307 |
| - return result |
| 1242 | + is_month_start = wrap_field_accessor(DatetimeArrayMixin.is_month_start) |
| 1243 | + is_month_end = wrap_field_accessor(DatetimeArrayMixin.is_month_end) |
| 1244 | + is_quarter_start = wrap_field_accessor(DatetimeArrayMixin.is_quarter_start) |
| 1245 | + is_quarter_end = wrap_field_accessor(DatetimeArrayMixin.is_quarter_end) |
| 1246 | + is_year_start = wrap_field_accessor(DatetimeArrayMixin.is_year_start) |
| 1247 | + is_year_end = wrap_field_accessor(DatetimeArrayMixin.is_year_end) |
| 1248 | + is_leap_year = wrap_field_accessor(DatetimeArrayMixin.is_leap_year) |
| 1249 | + |
| 1250 | + normalize = wrap_array_method(DatetimeArrayMixin.normalize, True) |
| 1251 | + to_julian_date = wrap_array_method(DatetimeArrayMixin.to_julian_date, |
| 1252 | + False) |
| 1253 | + month_name = wrap_array_method(DatetimeArrayMixin.month_name, True) |
| 1254 | + day_name = wrap_array_method(DatetimeArrayMixin.day_name, True) |
1308 | 1255 |
|
1309 | 1256 | @Substitution(klass='DatetimeIndex')
|
1310 | 1257 | @Appender(_shared_docs['searchsorted'])
|
@@ -1492,20 +1439,8 @@ def indexer_between_time(self, start_time, end_time, include_start=True,
|
1492 | 1439 |
|
1493 | 1440 | return mask.nonzero()[0]
|
1494 | 1441 |
|
1495 |
| - def to_julian_date(self): |
1496 |
| - """ |
1497 |
| - Convert DatetimeIndex to Float64Index of Julian Dates. |
1498 |
| - 0 Julian date is noon January 1, 4713 BC. |
1499 |
| - http://en.wikipedia.org/wiki/Julian_day |
1500 |
| - """ |
1501 |
| - result = DatetimeArrayMixin.to_julian_date(self) |
1502 |
| - return Float64Index(result) |
1503 |
| - |
1504 |
| - month_name = _wrap_in_index("month_name") |
1505 |
| - day_name = _wrap_in_index("day_name") |
1506 |
| - |
1507 | 1442 |
|
1508 |
| -DatetimeIndex._add_comparison_methods() |
| 1443 | +DatetimeIndex._add_comparison_ops() |
1509 | 1444 | DatetimeIndex._add_numeric_methods_disabled()
|
1510 | 1445 | DatetimeIndex._add_logical_methods_disabled()
|
1511 | 1446 | DatetimeIndex._add_datetimelike_methods()
|
|
0 commit comments