-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
ENH: enable pd.cut to handle i8 convertibles #14714
Comments
@jreback in the above example should the return type of the final object be 'timedelta64'? (the datatype of the original input) |
yes (it should be original dtype) |
@jreback Does it currently return strings? I got the below output by printing typeof over the members of category object returned |
yes it returns strings |
@jreback i am bit confused now, as part of this enhancement we first need convert to a dtype which cut can handle (timedelta64[ms]) and then return the type (timedelta64[ns]) from which we originally started. Though the objects returned will still be strings but they will be strings composed of object types that we initially passed to cut (timedelta64[ns])? |
yes this is a bit tricky. I think you:
|
@jreback thanks, this is what i was thinking |
IF we had an |
@jreback is there an error with the way i am making this round trip I start with s which is timedelta64[ns]. This is what "s". I then convert using the astype conversion used earlier here. Then i convert back to timedelta64[ns] using another as type conversion. But this conversion does not retain data and r is just a list having no time information s = pd.Series(pd.to_timedelta(np.random.randint(0,100,size=10),unit='ms')).sort_values() python data_conversion.py |
no, you will always convert to
then |
@jreback does this code block emulate the change we want to make? import pandas as pd output 1 00:00:00.012000 |
@jreback should a series s of pandas.TimeDelta objects on s.astype('timedelta64[ns]') return a series having a numpy timedelta64 objects with time in seconds. Currently on doing s.astype('timedelta64[ns]') it return back pandas.TimeDelta objects instead of the numpy equivalent |
we always return pandas objects (for timedelta / datetime) |
@jreback is it a good idea to use infer_dtype (from pandas.lib) to test if the object that we are calling cut on is of type datetime or timedelta, to decide if we need to do a conversion to timedelta[64] or datetime[64]? |
no use needs_i8_conversion |
xref #14714, follow-on to #14737 Author: Ajay Saxena <aileronajay@gmail.com> Closes #14798 from aileronajay/cut_timetype_bin and squashes the following commits: 82bffa1 [Ajay Saxena] added method for time type bins in pd cut and modified tests ac919cf [Ajay Saxena] added test for datetime bin type 355e569 [Ajay Saxena] allowing datetime and timedelta datatype in pd cut bins
xref pandas-dev#14714, follow-on to pandas-dev#14737 Author: Ajay Saxena <aileronajay@gmail.com> Closes pandas-dev#14798 from aileronajay/cut_timetype_bin and squashes the following commits: 82bffa1 [Ajay Saxena] added method for time type bins in pd cut and modified tests ac919cf [Ajay Saxena] added test for datetime bin type 355e569 [Ajay Saxena] allowing datetime and timedelta datatype in pd cut bins
so this should work for timedeltas AND datetimes.
Should be straight forward. detect an i8 convertible. turn into i8. do the cut. turn back to the original dtype.
The text was updated successfully, but these errors were encountered: