Repository: sktime/sktime

Issue:
[BUG] `'month_of_quarter'` feature in `DateTimeFeatures` not giving correct output
**Describe the bug**
<!--
A clear and concise description of what the bug is.
-->
The 'month_of_quarter' feature of DateTimeFeatures() is not giving correct output. 

**To Reproduce**
<!--
Add a Minimal, Complete, and Verifiable example (for more details, see e.g. https://stackoverflow.com/help/mcve

If the code is too long, feel free to put it in a public gist and link it in the issue: https://gist.github.com
-->

```python
# importing functions
from sktime.datasets import load_PBS_dataset
from sktime.transformations.series.date import DateTimeFeatures

#Loading data
y = load_PBS_dataset()

# Defining date time feature
FEATURES = ['month_of_quarter']
dt_trafo = DateTimeFeatures( manual_selection=FEATURES)

dt_trafo.fit_transform(y)[:13]
```

**Expected behavior**
<!--
A clear and concise description of what you expected to happen.
-->
As the name suggest, 'month_of_quarter' should be the month number of quarter having value among [1, 2, 3].

**Additional context**
<!--
Add any other context about the problem here.
-->
The output of the above code snippet should look something like below :-
<html>
<body>
<!--StartFragment-->

  | Number of scripts | month_of_quarter
-- | -- | --
'1991-07' | 1.0 | 1
'1991-08' | 1.0 | 2
'1991-09' | 1.0 | 3
'1991-10' | 0.0 | 1
'1991-11' | 0.0 | 2
'1991-12' | 1.0 | 3

<!--EndFragment-->
</body>
</html>

**Versions**
<details>

<!--
Please run the following code snippet and paste the output here:

from sktime import show_versions; show_versions()
-->
System:
    python: 3.9.0 (default, Nov 15 2020, 08:30:55) [MSC v.1916 64 bit (AMD64)]
executable: [c:\Users\vyomkesh.vyas\Anaconda3\envs\effc\python.exe](file:///C:/Users/vyomkesh.vyas/Anaconda3/envs/effc/python.exe)
   machine: Windows-10-10.0.19041-SP0

Python dependencies:
          pip: 23.0.1
   setuptools: 65.6.3
      sklearn: 1.2.2
       sktime: 0.16.0
  statsmodels: 0.13.5
        numpy: 1.23.5
        scipy: 1.8.1
       pandas: 1.5.3
   matplotlib: 3.6.3
       joblib: 1.2.0
        numba: 0.56.4
     pmdarima: 2.0.3
      tsfresh: None
</details>

<!-- Thanks for contributing! -->



Discussion:
Bug confirmed also on 0.18.0, windows.

The output is this, which is odd.

```
Period
1991-07    2
1991-08    3
1991-09    3
1991-10    3
1991-11    3
1991-12    4
1992-01    1
1992-02    1
1992-03    1
1992-04    2
1992-05    2
1992-06    2
1992-07    2
Freq: M, dtype: int64
```

FYI @danbartl, @KishManani 
it looks like the magic is broken, it happens in line 270

```python
cd = (np.floor(date_sequence.month / 4) + 1).astype(np.int64)
```

Resolving patch:
diff --git a/sktime/transformations/series/date.py b/sktime/transformations/series/date.py
--- a/sktime/transformations/series/date.py
+++ b/sktime/transformations/series/date.py
@@ -267,7 +267,7 @@ def _calendar_dummies(x, funcs):
     elif funcs == "week_of_month":
         cd = (date_sequence.day - 1) // 7 + 1
     elif funcs == "month_of_quarter":
-        cd = (np.floor(date_sequence.month / 4) + 1).astype(np.int64)
+        cd = (date_sequence.month.astype(np.int64) + 2) % 3 + 1
     elif funcs == "week_of_quarter":
         col_names = x.columns
         x_columns = col_names.intersection(["year", "quarter", "week"]).to_list()


Test patch:
diff --git a/sktime/transformations/series/tests/test_date.py b/sktime/transformations/series/tests/test_date.py
--- a/sktime/transformations/series/tests/test_date.py
+++ b/sktime/transformations/series/tests/test_date.py
@@ -3,11 +3,12 @@
 # copyright: sktime developers, BSD-3-Clause License (see LICENSE file).
 """Unit tests of DateTimeFeatures functionality."""
 
+import numpy as np
 import pandas as pd
 import pytest
 from pandas.testing import assert_frame_equal
 
-from sktime.datasets import load_airline, load_longley
+from sktime.datasets import load_airline, load_longley, load_PBS_dataset
 from sktime.forecasting.model_selection import temporal_train_test_split
 from sktime.transformations.series.date import DateTimeFeatures
 from sktime.utils._testing.hierarchical import _make_hierarchical
@@ -270,3 +271,19 @@ def test_keep_original_columns(df_panel):
         },
     )
     assert_frame_equal(Xt, expected)
+
+
+@pytest.mark.skipif(
+    not _check_estimator_deps(DateTimeFeatures, severity="none"),
+    reason="skip test if required soft dependencies not available",
+)
+def test_month_of_quarter(df_panel):
+    """Test month_of_quarter for correctness, failure case of bug #4541."""
+    y = load_PBS_dataset()
+
+    FEATURES = ["month_of_quarter"]
+    t = DateTimeFeatures(manual_selection=FEATURES)
+
+    yt = t.fit_transform(y)[:13]
+    expected = np.array([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1])
+    assert (expected == yt.values).all()