Dear Stefano,

Thank you for your feedback on the proposal regarding introducing quarterly 
date units.

I appreciate your insight into the existing capabilities already built into 
NumPy.
The support for quarters using the M8[3M] notation is fascinating and new to me.

You've raised good points not to introduce a quarterly date type. There must be 
good reasons it has never been implemented.
I see that there are existing solutions within NumPy, such as using M8[3M], but 
they may not be intuitive or easy to discover for users. 
Here are 4 typical scenarios and solutions a NumPy user could come up with:

1) ChatGPT: Return the start date of the quarter for a numpy array of datetime64

    import numpy as np

    # Assuming dates is your NumPy array of datetime64 objects
    dates = np.array(['2024-01-15', '2024-04-20', '2024-07-05', '2024-10-12'], 
dtype='datetime64')

    # Calculate the start date of the quarter for each date
    quarters_start = dates.astype('datetime64[M]').astype('datetime64[Q]')

    print(quarters_start)

    => Not so great...

2) stackoverflow: https://stackoverflow.com/search?q=numpy+datetime64+quarter

    year_quarter = pd.Period(dates, freq='Q')

    => Just use Pandas...

3) Unfamiliar user (pure Numpy):

    dates = np.asarray(dates, dtype="<M8[M]")
    months_less_one = dates.astype(np.int64) % 12
    diff_months = (months_less_one - months_less_one // 3 * 3).astype("<m8[M]")
    dates -= diff_months

    => Works, but ugly...

4) Advanced user:

    dates = np.asarray(dates, dtype="<M8[3M]")

    => Really, so easy...

As demonstrated in the scenarios provided, it's quite possible that users will 
not find the best and built in path using NumPy.
First of all I am very happy to know there is an alternative using the M8[3M] 
notation. Personally I would prefer to have "Q" instead of "3M" as quarterly 
unit because it is more intuitive and aligns with other libraries like Pandas.
You are moderately negative on this proposal. However, do you see a way to 
improve the user experience?
Thank you for your feedback.

Regards, Oyibo
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to