Comments (5)
Hey Hello there,
I am new to opensource but not to python, however, i might be wrong but here's why the above issue might have occured:
The source code related to the readdate is located in this file: sciris/sciris/sc_utils.py.
In line 1237 readdate function is defined, its implementation is such that it uses datetime module and looks for a format in the below dictinary called formats_to_try :
formats_to_try = {
'date': '%Y-%m-%d', # 2020-03-21
'date-alpha': '%Y-%b-%d', # 2020-Mar-21
'date-numeric': '%Y%m%d', # 20200321
'datetime': '%Y-%m-%d %H:%M:%S', # 2020-03-21 14:35:21
'datetime-alpha': '%Y-%b-%d %H:%M:%S', # 2020-Mar-21 14:35:21
'default': '%Y-%m-%d %H:%M:%S.%f', # 2020-03-21 14:35:21.23483
'ctime': '%a %b %d %H:%M:%S %Y', # Sat Mar 21 23:09:29 2020
}
In our issue case, we are supplying the '%T'
for '15:48:05'
but the code is unable to find it.
Fixing Issue: What we can do is instead of using '%T'
we can use '%H:%M:%S'
as:
sc.readdate("Tue 2020-09-29 15:48:05", dateformat='%a %Y-%m-%d %H:%M:%S')
which is available in the formats_to_try dictionary.
I hope this helps and if not please do let me know
And sorry for bad editing
from sciris.
Hi @appsplash99 , thank you so much for your comment! This indeed does fix it. %T
is a valid time code in some cases (here, git log
) but not for Python. But the real issue is that the way readdate()
is written, it doesn't pass on exceptions. In this case the exception strptime()
raises is quite clear, ValueError: 'T' is a bad directive in format '%a %Y-%m-%d %T'
. This issue will be fixed in the next release of Sciris, hopefully in a few weeks.
from sciris.
Can i do it?
from sciris.
Sure, go ahead! Thank you!
from sciris.
Wait! I don't think there's any error here:
I think our application of using%T
is inapplicable.
The reason why:
Even if i use %T
with datetime as it is , we still get an error:
INPUT:
datetime_str = '09/19/18 10:55:26'
datetime_object = datetime.strptime(datetime_str, '%m/%d/%y %T')
print(datetime_object)
OUTPUT:
ValueError: 'T' is a bad directive in format '%m/%d/%y %T'
So, you can use%X
instead which is Localeβs appropriate time representation. - 21:30:00 (en_US); 21:30:00 (de_DE)
Another Fix:
sc.readdate("Tue 2020-09-29 15:48:05", dateformat='%a %Y-%m-%d %X')
Hope this Helps
from sciris.
Related Issues (20)
- Allow `sc.plot3d` and `sc.scatter3d` to allow 2D input HOT 1
- Fix jsonify for sc.dictobj HOT 1
- Add `sc.readjson()` HOT 1
- Rename v2.2.0 β v3.0.0 HOT 1
- Get readthedocs build working HOT 1
- Fix parallelization on Windows HOT 1
- Additional doc fixes HOT 1
- Add style sheets HOT 1
- parallelizer='serial' or 'thread' doesn't have same deep-copying behaviour as running in parallel if arguments to different threads share objects HOT 3
- Add sc.glob() as an alias for sc.getfilelist()? HOT 1
- Release checklist HOT 1
- Fix conda installation HOT 1
- Allow sc.datedelta() to handle more input formats HOT 1
- Update sc.benchmark() to include parallelization HOT 1
- Show elapsed time in parallel progress HOT 1
- Add option to customize global variable HOT 1
- Update outdated test_parallel.py docstring HOT 1
- Confusing failures using kwarg-based init of dataframes HOT 1
- Improve ultra-robust pickle failures HOT 1
- known_deprecations issues with multiple names HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sciris.