-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ERR: between_time now checks for argument types #11832
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
Conversation
do you think passing non-time like strings are also an error? e.g. |
Unfortunately, I don't know how to check that. How it currently works is the dateutil parser is used to parse the time string but a datetime.datetime is returned regardless if it's a time string or date string.
|
I see what your idea is but I'm just not sure that the
|
the timedelta parser is a bit strick for this, can prob make a mini one by doing something like:
|
Seems like we should also do a milliseconds parse for safe measure.
|
don't use dateutil.parse we want a time only |
My only comment was that it's currently supported so we need that additionally. |
easiest might be to loop thru a list of allowed formats until u match (or exhaust the list and raise) using strptime is strict (which is good) |
09bfda3
to
2fef431
Compare
I'm confused as to why this fails on 2.6. I created a 2.6 environment and the test works fine there.
|
2fef431
to
b42e96b
Compare
Ah, it's because that test uses the am/pm from it_IT locale. Skipped if there is a locale present. |
@@ -1769,13 +1782,34 @@ def indexer_between_time(self, start_time, end_time, include_start=True, | |||
------- | |||
values_between_time : TimeSeries | |||
""" | |||
from dateutil.parser import parse | |||
def _parse_time_string(time_object): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can u factor this routine out and out it in tseries/tools.py (eg next to the datetime parsing ones)
thrn just call it from here (u can also move the these to the corresponding testing module)
b42e96b
to
4009405
Compare
arg : compat.string_types | ||
format : str, list-like, default None | ||
Format used to convert arg into a time object. If None, default formats | ||
are used. To add an additional format use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we allowing 'adding' time formats? your list seems like enough, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More for backwards compatibility. Our formats are a subset of dateutil's so want to ensure that the code still works for those that may have used a different format historically.
de83d7c
to
c764bbd
Compare
return _convert_listlike(arg, format) | ||
|
||
return _convert_listlike(np.array([arg]), format)[0] | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't really like these blanket excepts. What hits this? why is it necessary. Rather catch these things inside _convert_listlike
on a specific basis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's to cover the "ignore"
case for casting errors in which case arg
is returned. I did it here as things are cast to a numpy array and so your original argument really isn't returned. However, for now I can remove that casting and then check for "ignore"
when the casting fails and return the unmolested arg
at that point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or I can just catch the ValueError
and return arg at that point which might make more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first soln is better - then if an uncaught error it will show up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way it is currently written it will raise any exceptions that occur within _convert_listlike
so you won't have any uncaught errors.
4b26ac9
to
e480401
Compare
Hopefully we are all good here. |
@@ -205,7 +205,8 @@ other anchored offsets like ``MonthBegin`` and ``YearBegin``. | |||
Other API Changes | |||
^^^^^^^^^^^^^^^^^ | |||
|
|||
|
|||
- DataFrame between_time now only parses a fixed set of time strings. Parsing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use double backticks DataFrame.between_time
(though this also applies to Series
, yes? I would put a mini-example here as well.
start_time : datetime.time or string | ||
end_time : datetime.time or string | ||
start_time, end_time : datetime.time or string | ||
Time or string in appropriate format (e.g., "%H:%M", "%I%M%p") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
datetime.time
or string in appropriate time-like format (and include the formats you have above)
small comments. pls run: this looks really good. I think we could expose this via ping when green. |
33cc8f2
to
eb827c4
Compare
eb827c4
to
eadc308
Compare
@jreback Green. I feel more comfortable leaving the ability to add another format given that we do not know how much people were relying on dateutil's parser. It's two lines of code and innocuous. |
merged via 9c71dbf thanks. |
Closes #11818