Add semi_month to Datetime Features

Open
#685 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #1092 by @AHMETHAKANBEZIR1 — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
18/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
numpy, pandas, python
Domain
data

Research direction

Start with the two lambda definitions for semi_month_start and semi_month_end in the issue body, and with the boundary rules (days 1-14 versus 15 onward, and 1-15 versus 16 onward). Check open pull request #1092 first, since it already targets this feature and the work may be under way. Done means both features return 24 semi-month values with the boundaries the issue specifies, with tests covering the 15th of February example.

Written by the indexing model from the issue text.

Description

Is your feature request related to a problem? Please describe.
I need to create a "semi month" feature for semi-monthly data. Just like "week" but for semi-months instead of weeks.

Describe the solution you'd like
Pandas supports "SM" (semi-montly, i.e. 15th and end of month) and "SMS" (semi-montly start, i.e. 1st and 15th of the month) frequencies, see: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases

I'd like to have "semi_month" features, for example the 1st of January would be semi_week 1. The 18th of January would be semi_week 2. The 3rd of March would be semi_week 5. Basically you split each month into two semi months and you get 24 semi-months.

In order to be consistent with the SM and SMS pandas frequencies I'd consider:

semi_month_start:

  • Days 1 to 14 included: first half
  • Days 15 to end of month included: second half

semi_month_end:

  • Days 1 to 15 included: first_half
  • Days 16 to end of month included: second half

So, for example, with "semi_month_start", the 15th of February is semi_month 4, while for "semi_month_end" it is semi_month 3.

Describe alternatives you've considered
The only alternative is to have 2 different features for month and day.

P.S.

The feature functions could be something like this:

"semi_month_start": lambda x: (x.dt.day < 15).astype(np.int64) + (x.dt.month - 1) * 2 + 1,
"semi_month_end": lambda x: (x.dt.day <= 15).astype(np.int64) + (x.dt.month - 1) * 2 + 1,
Dominant language
Python
Stars
2.3k
Forks
391
Avg merge
11h 34m
Merged PRs (30d)
11

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from feature-engine/feature_engine

All issues in feature-engine/feature_engine

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.