Sign in to follow this  
Followers 0
asha91

In Python, what is ceil("1d") in relation to timedeltas?

1 post in this topic

I discovered the following function:

def sub_kpi1_rule(sub_comp_appr_date, date_report_run, greater_of_date_sub_sub_ll):
        if pd.isnull(sub_comp_appr_date) and not alive_for_six_days(date_report_run, greater_of_date_sub_sub_ll):
            return "NA"
        elif (sub_comp_appr_date - greater_of_date_sub_sub_ll).ceil("1d").days <= 6:
            return "PASS"
        else:
            return "FAIL"

Because all of the parameters are date types, I'm assuming

(sub_comp_appr_date - greater_of_date_sub_sub_ll)

..returns a timedelta instance. I am confused about this ceil(syntax)

elif (sub_comp_appr_date - greater_of_date_sub_sub_ll).ceil("1d").days <= 6:

because when I try to subtract two dates using this method, I get the following error:

from datetime import date
a = date(2022, 10,1)
b = date(2022, 10,15)
(b-a).ceil("1d")


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [36], line 4
      2 a = date(2022, 10,1)
      3 b = date(2022, 10,15)
----> 4 (b-a).ceil("1d")

AttributeError: 'datetime.timedelta' object has no attribute 'ceil'

On a data frame, the function is called:

df["Sub KPI1"] = df.apply(lambda x: sub_kpi1_rule(x["SUBM_LATE_DESTINATION_COMPLIANCE_APPROVAL_DATE"], date_report_run, x["Greater of Date Submitted and Submission LL Created"]), axis=1)

Because date report run is expressly transformed to one, I believe the types are pd.Timestamp:

date_report_run = date(year_report_run, month_report_run, day_report_run)
date_report_run = pd.Timestamp(date_report_run)

I'm assuming I'll receive a pandas. libs.tslibs.timedeltas. Instead of a standard timedelta, use a timedelta back.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.