Skip to content

Commit c3916be

Browse files
mgmarinoCloseChoice
authored andcommitted
CLN: Change isocalendar to be a method (pandas-dev#33533)
For consistency with `Timestamp.isocalendar`, this should rather be a method. Followup of pandas-dev#33220, see the discussions following the merge
1 parent 1ca8578 commit c3916be

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

doc/source/user_guide/timeseries.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,6 @@ There are several time/date properties that one can access from ``Timestamp`` or
772772
week,"The week ordinal of the year"
773773
dayofweek,"The number of the day of the week with Monday=0, Sunday=6"
774774
weekday,"The number of the day of the week with Monday=0, Sunday=6"
775-
isocalendar,"The ISO 8601 year, week and day of the date"
776775
quarter,"Quarter of the date: Jan-Mar = 1, Apr-Jun = 2, etc."
777776
days_in_month,"The number of days in the month of the datetime"
778777
is_month_start,"Logical indicating if first day of month (defined by frequency)"
@@ -794,7 +793,7 @@ You may obtain the year, week and day components of the ISO year from the ISO 86
794793
.. ipython:: python
795794
796795
idx = pd.date_range(start='2019-12-29', freq='D', periods=4)
797-
idx.to_series().dt.isocalendar
796+
idx.to_series().dt.isocalendar()
798797
799798
.. _timeseries.offsets:
800799

doc/source/whatsnew/v1.1.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Other enhancements
8888
- :class:`Series.str` now has a `fullmatch` method that matches a regular expression against the entire string in each row of the series, similar to `re.fullmatch` (:issue:`32806`).
8989
- :meth:`DataFrame.sample` will now also allow array-like and BitGenerator objects to be passed to ``random_state`` as seeds (:issue:`32503`)
9090
- :meth:`MultiIndex.union` will now raise `RuntimeWarning` if the object inside are unsortable, pass `sort=False` to suppress this warning (:issue:`33015`)
91-
- :class:`Series.dt` and :class:`DatatimeIndex` now have an `isocalendar` accessor that returns a :class:`DataFrame` with year, week, and day calculated according to the ISO 8601 calendar (:issue:`33206`).
91+
- :class:`Series.dt` and :class:`DatatimeIndex` now have an `isocalendar` method that returns a :class:`DataFrame` with year, week, and day calculated according to the ISO 8601 calendar (:issue:`33206`).
9292
- The :meth:`DataFrame.to_feather` method now supports additional keyword
9393
arguments (e.g. to set the compression) that are added in pyarrow 0.17
9494
(:issue:`33422`).

pandas/core/arrays/datetimes.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class DatetimeArray(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps, dtl.DatelikeOps
183183
"microsecond",
184184
"nanosecond",
185185
]
186-
_other_ops = ["date", "time", "timetz", "isocalendar"]
186+
_other_ops = ["date", "time", "timetz"]
187187
_datetimelike_ops = _field_ops + _object_ops + _bool_ops + _other_ops
188188
_datetimelike_methods = [
189189
"to_period",
@@ -1242,7 +1242,6 @@ def date(self):
12421242

12431243
return tslib.ints_to_pydatetime(timestamps, box="date")
12441244

1245-
@property
12461245
def isocalendar(self):
12471246
"""
12481247
Returns a DataFrame with the year, week, and day calculated according to
@@ -1263,13 +1262,13 @@ def isocalendar(self):
12631262
Examples
12641263
--------
12651264
>>> idx = pd.date_range(start='2019-12-29', freq='D', periods=4)
1266-
>>> idx.isocalendar
1265+
>>> idx.isocalendar()
12671266
year week day
12681267
0 2019 52 7
12691268
1 2020 1 1
12701269
2 2020 1 2
12711270
3 2020 1 3
1272-
>>> idx.isocalendar.week
1271+
>>> idx.isocalendar().week
12731272
0 52
12741273
1 1
12751274
2 1

pandas/core/indexes/accessors.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ def to_pydatetime(self) -> np.ndarray:
219219
def freq(self):
220220
return self._get_values().inferred_freq
221221

222-
@property
223222
def isocalendar(self):
224223
"""
225224
Returns a DataFrame with the year, week, and day calculated according to
@@ -240,16 +239,16 @@ def isocalendar(self):
240239
Examples
241240
--------
242241
>>> ser = pd.to_datetime(pd.Series(["2010-01-01", pd.NaT]))
243-
>>> ser.dt.isocalendar
242+
>>> ser.dt.isocalendar()
244243
year week day
245244
0 2009 53 5
246245
1 <NA> <NA> <NA>
247-
>>> ser.dt.isocalendar.week
246+
>>> ser.dt.isocalendar().week
248247
0 53
249248
1 <NA>
250249
Name: week, dtype: UInt32
251250
"""
252-
return self._get_values().isocalendar.set_index(self._parent.index)
251+
return self._get_values().isocalendar().set_index(self._parent.index)
253252

254253

255254
@delegate_names(

pandas/tests/series/test_datetime_values.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def test_dt_namespace_accessor(self):
4949
"ceil",
5050
"day_name",
5151
"month_name",
52+
"isocalendar",
5253
]
5354
ok_for_td = TimedeltaIndex._datetimelike_ops
5455
ok_for_td_methods = [
@@ -678,7 +679,7 @@ def test_setitem_with_different_tz(self):
678679
],
679680
)
680681
def test_isocalendar(self, input_series, expected_output):
681-
result = pd.to_datetime(pd.Series(input_series)).dt.isocalendar
682+
result = pd.to_datetime(pd.Series(input_series)).dt.isocalendar()
682683
expected_frame = pd.DataFrame(
683684
expected_output, columns=["year", "week", "day"], dtype="UInt32"
684685
)

0 commit comments

Comments
 (0)