<h3 dir="auto">Describe the workflow you want to enable</h3>
<p dir="auto">Would be cool to have a preprocessor that maps dates (str or unixtime) to its' respective date parts: dayofmonth, dayofweek, hour,etc.</p>
<p dir="auto">There's any reason this is not included in sklearn?<br>
In case not, I could do a PR</p>
<h3 dir="auto">Describe your proposed solution</h3>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">from sklearn import preprocessing<br>
de = preprocessing.DateEncoder(datepart=['month','hour'], cyclic=True)<br>
de.fit(['2022-04-01 17:17:09.175803', '2022-04-01 17:17:09.175803', '2022-04-01 17:17:09.175803'])<br>
DateEncoder()<br>
de.datepart_<br>
array(['month','hour'])<br>
de.transform(['2022-04-01 17:17:09.175803', '2022-01-01 18:17:09.175803', '2022-03-01 02:17:09.175803'])<br>
array([ [cos(04/12), sin(04/12), cos(17/24), sin(17/24)],<br>
[cos(01/12), sin(01/12), cos(18/24), sin(18/24)],<br>
[cos(03/12), sin(03/12), cos(02/24), sin(02/24)]<br>
)</p>
</blockquote>
</blockquote>
</blockquote>
<h3 dir="auto">Describe alternatives you've considered, if relevant</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Additional context</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Describe the workflow you want to enable</h3>
<p dir="auto">Do we want to add a transformer for pandas datetimes?<br>
We haven't really added much based on pandas yet but this would be a pretty natural thing to add.<br>
You could argue that you can do something like <code class="notranslate">FunctionTransformer(lambda X: X.dt.dayofweek)</code> or similar for the other features (year, hour, minute, month...) but the problem with that is that you don't get feature names, which is terrible for interpretation.</p>
<p dir="auto">Featurizing datetimes is super common (the last ~10 datasets I worked on had it) and I think it's a workflow we should make easier.</p>
<h3 dir="auto">Describe your proposed solution</h3>
<p dir="auto">Implement a DateTimeTransformer that takes in maybe just a single column (that would work well with ColumnTransformer but is a bit different from other transformers, but quite similar to the CountVectorizer, so maybe if it takes a single column it should be <code class="notranslate">DateTimeVectorizer</code>) and a list of features to derive, like <code class="notranslate">dayofweek</code>, <code class="notranslate">dayofyear</code> etc, but which creates meaningful feature names.</p>
<h3 dir="auto">Describe alternatives you've considered, if relevant</h3>
<p dir="auto">An alternative would be to improve attaching feature names to <code class="notranslate">FunctionTransformer</code>, but this would still require some non-trivial code for datetimes, and they are just very very common.</p>