@@ -127,7 +127,12 @@ def get_date_field(datetimes, field):
127127 return np .array ([getattr (date , field ) for date in datetimes ], dtype = np .int64 )
128128
129129
130- def _field_accessor (name , docstring = None , min_cftime_version = "0.0" ):
130+ def _field_accessor (
131+ name : str ,
132+ docstring : str | None = None ,
133+ min_cftime_version : str = "0.0" ,
134+ deprecation_pair : tuple [str , str ] | None = None ,
135+ ):
131136 """Adapted from pandas.tseries.index._field_accessor"""
132137
133138 def f (self , min_cftime_version = min_cftime_version ):
@@ -136,6 +141,14 @@ def f(self, min_cftime_version=min_cftime_version):
136141 else :
137142 cftime = attempt_import ("cftime" )
138143
144+ if deprecation_pair is not None :
145+ original , replacement = deprecation_pair
146+ emit_user_level_warning (
147+ f"CFTimeIndex.{ original } is deprecated and will be removed in "
148+ f"a future version. Use CFTimeIndex.{ replacement } instead" ,
149+ FutureWarning ,
150+ )
151+
139152 if Version (cftime .__version__ ) >= Version (min_cftime_version ):
140153 return get_date_field (self ._data , name )
141154 else :
@@ -249,9 +262,23 @@ class CFTimeIndex(pd.Index):
249262 second = _field_accessor ("second" , "The seconds of the datetime" )
250263 microsecond = _field_accessor ("microsecond" , "The microseconds of the datetime" )
251264 dayofyear = _field_accessor (
265+ "dayofyr" ,
266+ "The ordinal day of year of the datetime" ,
267+ "1.0.2.1" ,
268+ ("dayofyear" , "day_of_year" ),
269+ )
270+ dayofweek = _field_accessor (
271+ "dayofwk" ,
272+ "The day of week of the datetime" ,
273+ "1.0.2.1" ,
274+ ("dayofweek" , "day_of_week" ),
275+ )
276+ day_of_year = _field_accessor (
252277 "dayofyr" , "The ordinal day of year of the datetime" , "1.0.2.1"
253278 )
254- dayofweek = _field_accessor ("dayofwk" , "The day of week of the datetime" , "1.0.2.1" )
279+ day_of_week = _field_accessor (
280+ "dayofwk" , "The day of week of the datetime" , "1.0.2.1"
281+ )
255282 days_in_month = _field_accessor (
256283 "daysinmonth" , "The number of days in the month of the datetime" , "1.1.0.0"
257284 )
0 commit comments