Skip to content

Add a new DataFrame.dti accessor #27581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Jul 25, 2019 · 6 comments
Closed

Add a new DataFrame.dti accessor #27581

ghost opened this issue Jul 25, 2019 · 6 comments
Labels
API Design Needs Discussion Requires discussion from core team before further action

Comments

@ghost
Copy link

ghost commented Jul 25, 2019

There's the dt accessor on Series which operates on the Series values:

pd.Series([1,2,3]).dt.day 
#exists. But checks that series *values*  datetime64[ns]

pd.Series([1,2,3]).day
# doesn't exist

There's a top-level method df.first:

Convenience method for subsetting initial periods of time series data
based on a date offset.

which looks like it should live behind dti accessor on DataFrame.

pd.DataFrame().first(0) 
# method is applicable only for datetime, but is in the top DataFrame namespace

There's currently no datetime accessor on dataframe. Would it make sense to move it below a dti accessor on DataFrame?

There's also an unfortunate unfortunate name collision betweenGroupby().first

Compute first of group values.

and DataFrame.first:

Convenience method for subsetting initial periods of time series data
based on a date offset.

Adding a dti accessor to DataFrame would clean that up as well.

@WillAyd
Copy link
Member

WillAyd commented Jul 26, 2019

Not sure about the idea of a data frame accessor. In the Series world when thinking about an accessor it operates on the values; this would essentially operate on the index of the object so I think not super clean from an API perspective.

Agreed though the naming of first isn't intuitive and does clash with other items in the API. Have you thought of anything outside the accessor? Maybe we just need to rename the function (the more verbose first_offset?)

@WillAyd WillAyd added API Design Needs Discussion Requires discussion from core team before further action labels Jul 26, 2019
@ghost
Copy link
Author

ghost commented Jul 26, 2019

That's a good point. I was thinking of accessors as a way to offer methods conditionally, which fits here.

this would essentially operate on the index of the object

it would slice the DataFrame object based on the index, yes. But does that count or not?

i = pd.date_range('2018-04-09', periods=4, freq='2D')
ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
# Get the rows for the first 3 days:

ts.first('3D')
            A
2018-04-09  1
2018-04-11  2

For one method, doing this wouldn't make sense. I'll see if there are others, and if not perhaps a name change really is the simplest solution. Thanks.

@WillAyd
Copy link
Member

WillAyd commented Jul 26, 2019

Yea my wording was slightly off but I think we are on the same page. If you find others lmk otherwise maybe we just repurpose this issue to focus solely on the first naming inconsistency

@ghost
Copy link
Author

ghost commented Jul 26, 2019

ok, sounds good.

@ghost
Copy link
Author

ghost commented Jul 28, 2019

first       
asfreq
asof 
at_time
between_time
tshift 
tz_convert
tz_localize 

all the above are DataFrame methods which are candidates for moving beneath a dti accessor.

We might want to rename first even if it were moved.

@mroeschke
Copy link
Member

Thanks for the suggestion, but sounds like the community and other core devs have not expressed further interest in a dti accessor. Closing but happy to reopen if theres further interest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

No branches or pull requests

2 participants