Python speed testing - Time Difference - milliseconds

What is the proper way to compare 2 times in Python in order to speed test a section of code? I tried reading the API docs. I'm not sure I understand the timedelta thing. So far I have this...

Convert a timedelta to days, hours and minutes

I've got a timedelta. I want the days, hours and minutes from that - either as a tuple or a dictionary... I'm not fussed. I must have done this a dozen times in a dozen languages over the years...

Best way to find the months between two dates

I have the need to be able to accurately find the months between two dates in python. I have a solution that works but its not very good (as in elegant) or fast. dateRange =...

TypeError: unsupported type for timedelta days component: datetime.datetime

I am trying to perform some date arithmetic in a function. from datetime import datetime, timedelta def foo(date1, summing_period): current_period_start_date = date1 -...

Getting "cannot find Symbol" in Java project in Intellij

I make this call to a static singleton instance from the class GameManager.java. HUD.getInstance().update(timeDelta); HUD.java contains the HUD class as well as two other related classes,...

Python pandas dataframe - any way to set frequency programmatically?

I'm trying to process CSV files like this: df = pd.read_csv("raw_hl.csv", index_col='time', parse_dates = True)) df.head(2) high low time 2014-01-01...

Converting datetime to timedelta so they can be added

When subtracting two datetime objects, I understand the result is timedelta object: import datetime AcDepart = 1900-01-01 18:00:00 AcArrival = 1900-01-01 07:00:00 ActualHours = AcDepart -...

Expand date to the beginning and end datetime for the day

Based on the current time (datetime.now()) I want to expand this to cover the whole days time. Right now I have been using: start = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d...

Python: How to add datetime to x-axis in pcolormesh

With matplotlib scatter or line plots I can assign the x-axis as an array of datetimes. from datetime import datetime, timedelta import numpy as np import matplotlib.pyplot as plt size = 10 #...

Is there an easy way to convert ISO 8601 duration to timedelta?

Given a ISO 8601 duration string, how do I convert it into a datetime.timedelta? This didn't work: timedelta("PT1H5M26S", "T%H%M%S") A timedelta object represents a duration, the difference...

finding last business day of a month in python

I'm trying to find last business day of of the month. I wrote the code below for that and it works fine but I was wondering if there is a cleaner way of doing it? from datetime import...

Apache Airflow scheduler does not trigger DAG at schedule time

When I schedule DAGs to run at a specific time everyday, the DAG execution does not take place at all. However, when I restart Airflow webserver and scheduler, the DAGs execute once on the...

Pandas Timedelta in months

How can I calculate the elapsed months using pandas? I have write the following, but this code is not elegant. Could you tell me a better way? import pandas as pd df =...

Passing a command line argument to airflow BashOperator

Is there a way to pass a command line argument to Airflow BashOperator. Currently, I have a python script that accepts a date argument and performs some specific activities like cleaning up...

Airflow BashOperator collect return code

Bear with me since I've just started using Airflow, and what I'm trying to do is to collect the return code from a BashOperator task and save it to a local variable, and then based on that return...

Best way to loop through parameters in Airflow?

I'm trying to get familiar with Airflow and loving it so far. One thing i'm a little unclear on however is how to properly paramterise my dag where i want to run the same dag but in parallel for...

how to run automatically apache airflow tasks

I'm using Apache Airflow to schedule ETL jobs which are python scripts. When I create dags on airflow, it sets dags status on off. My code are like this. import airflow from airflow import...

Python - AttributeError: 'NoneType' object has no attribute 'execute'

I am trying to run a python script that logs into Amazon Redshift DB and then execute a SQL command. I use a tool called Airflow for workflow management. When running the below code, I am able to...

How can I set custom datetime pattern on Bokeh hover formatter?

I'm trying to plot some values respect to the time using a line plot with Bokeh. My issue came when I tried to add a hover that shows the concrete value at some point of the plot. I want to show a...

Using datetime.timedelta to add years

I am doing some time calculations in Python. Goal: Part of this is trying to : Given a date, add time interval (X years, X months, X weeks), return date ie input args: input_time (datetime.date),...

How to fix OverflowError: Overflow in int64 addition

I'm trying to subtract column df['date_of_admission'] from the column df['DOB'] to find the difference between then and store the age value in df['age'] column, however, I'm getting this...

Django: check_password returns false, even if the password was saved as hash

I am using Django==2.1.5 My goal is a simple DRF based create user and login, but instead of login with username (and pw) i want to login with the email address+pw. Therefore I saved...

ValueError: Units 'M' and 'Y' are no longer supported, as they do not represent unambiguous timedelta values durations

I recently upgraded my code from Python 3.3 to Python 3.7, and it's currently throwing an error which says: ValueError: Units 'M' and 'Y' are no longer supported, as they do not represent...

Airflow: DockerOperator fails with Permission Denied error

I'm trying to run a docker container via Airflow but getting Permission Denied errors. I have seen a few related posts and some people seem to have solved it via sudo chmod 777...

How to calculate the total seconds from now plus n days

I want to send a notification on every Tuesday at 12:00pm I want to get an exact time in the future in seconds until Tuesday at 12:00pm import datetime from datetime import date , timedelta today...

Airflow xcom pull only returns string

I have an airflow pipeline where I need to get a filename from a pubsub subscription and then import that file into a cloud sql instance. I use the CloudSqlInstanceImportOperator to import the CSV...

Airflow on_failure_callback

Hello hope you all are doing fine i would like to ask one question recently i have been trying airlfow and playing with it here is the situation everything works fine i have two...

Prefect workflow: How to persist data of previous/every schedule run?

In prefect workflow, I'm trying to persist data of every schedule run. I need to compare data of every previous and current result. I tried Localresult and checkpoint=true but its not working. For...

<<airflow.providers.jdbc>> module named error in Airflow2.x

I am using airflow 2.0. I am trying to connect to redshift, using docker container on mac. Here is my dag.py: from airflow import DAG from datetime import datetime,timedelta from...

"detail": "Authentication credentials were not provided." for general views

I have created a custom user model and apply Djoser authentication and jwt. But after this when I tried to get request for products views, I get this error: "detail": "Authentication credentials...