file.py test.py I get an Error: TypeError: ‘>’ not supported between instances of ‘MagicMock’ and ‘int’ Is there anyway to test this function? Probably the problem is with this part of the last line: (utc_date – namespace_created_date).days Answer I could reproduce and fix. Here is a working unittest file (assuming file.py is accessible): If I use date_now.datetime.utcnow.date.return_value = datetime.datetime(2022,1,1) I
Tag: python-datetime
how can i calculate the difference between two dates and times in python
my code looks like this: listaDivisa looks like this: I want to calculate how much time (better in minutes) the sensor was ON, I tried doing this: but it doesn’t work, another raw alternative I tried was but, not minding about the fact that it doesn’t even work, I don’t think it could be a smart alternative. How could I
why am i getting TypeError: dtype datetime64[ns] cannot be converted to timedelta64[ns]?
The code: i have lots of dates in a column which i want to convert to number of days but i simply keep getting errors. im new to pandas so sorry if the question is silly but why am i getting errors and how to fix them. Thank you Answer To get the number of days to now, use:
Converting arguments to custom objects using dataclasses package
I recently discovered the dataclasses Python package. I’m running into an issue when using custom classes in my type annotation. I’ve got a simple example below. When the Entry class gets passed the location argument, the value of that argument should be used to construct a Location object. Similarly, when the Entry class gets passed a string for the creationDate
Convert ’01-Feb-15′ to Python date 01/02/2015 [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 11 months ago. Improve this question
How to solve datetime format error “time data %r does not match format %r”?
I’m trying to convert a date from string format to a datetime format. I think that I’m using the right format, but the error is still raised. Code example: Error: Answer Your code wasn’t reading the microseconds properly. You can read microseconds with %f Try using this code, this will fix the issue:
How to convert Linux date string to Python Datetime
I am trying to convert the Linux date time ‘Fri Feb 25 16:07:17 UTC 2022’ to python datetime but not able to achieve the same. However, I am able to do using below code, but still looking for the right approach: Input -> Fri Feb 25 16:07:17 UTC 2022 Output -> ‘2022-02-25 16:07:17’ Answer Output 2022-02-25 16:07:17
Pandas: Unable to merge on two date columns
I have two dataframes that look like: df1: df2: Both date columns have been made using the pd.to_datetime() method, and they both supposedly have <M8[ns] data types when using df1.Date.dtype and df2.Date.dtype. However when trying to merge the dataframes with pd.merge(df,hpi,how=”left”,on=”Date”) I get the error: ValueError: You are trying to merge on object and datetime64[ns] columns. If you wish to
python with pandas to parse dates like “0001-11-29 13:00:00 BC”
I am trying to read some sql data using pandas library and one of the column “customer_date” has values like “0001-11-29 13:00:00 BC”. My query fails with error ValueError: year 0 is out of range Please suggest a way to parse such date/timestamps. Here is my code. Error: Answer This is what worked:
Get last friday of each month in python
I want last friday of each month for upcoming three months. This gives me the nearest friday. I want to make sure this is the last friday of this month so that i can add 28 days to get next friday. Answer The easiest way to do this is to use the module dateutil: Don’t assume you can get the