Skip to content

Commit a9719fa

Browse files
committed
STY: remove unneeded cruft
1 parent 3bcc6b5 commit a9719fa

File tree

1 file changed

+0
-164
lines changed

1 file changed

+0
-164
lines changed

pandas/tslib.pyx

-164
Original file line numberDiff line numberDiff line change
@@ -2650,169 +2650,5 @@ def _calc_julian_from_U_or_W(year, week_of_year, day_of_week, week_starts_Mon):
26502650
days_to_week = week_0_length + (7 * (week_of_year - 1))
26512651
return 1 + days_to_week + day_of_week
26522652

2653-
2654-
cdef _strptime(object data_string, object format, pandas_datetimestruct *dts):
2655-
"""Return a time struct based on the input string and the format string."""
2656-
global _TimeRE_cache, _regex_cache
2657-
with _cache_lock:
2658-
if _getlang() != _TimeRE_cache.locale_time.lang:
2659-
_TimeRE_cache = TimeRE()
2660-
_regex_cache.clear()
2661-
if len(_regex_cache) > _CACHE_MAX_SIZE:
2662-
_regex_cache.clear()
2663-
locale_time = _TimeRE_cache.locale_time
2664-
format_regex = _regex_cache.get(format)
2665-
if not format_regex:
2666-
try:
2667-
format_regex = _TimeRE_cache.compile(format)
2668-
# KeyError raised when a bad format is found; can be specified as
2669-
# \\, in which case it was a stray % but with a space after it
2670-
except KeyError, err:
2671-
bad_directive = err.args[0]
2672-
if bad_directive == "\\":
2673-
bad_directive = "%"
2674-
del err
2675-
raise ValueError("'%s' is a bad directive in format '%s'" %
2676-
(bad_directive, format))
2677-
# IndexError only occurs when the format string is "%"
2678-
except IndexError:
2679-
raise ValueError("stray %% in format '%s'" % format)
2680-
_regex_cache[format] = format_regex
2681-
found = format_regex.match(data_string)
2682-
if not found:
2683-
raise ValueError("time data %r does not match format %r" %
2684-
(data_string, format))
2685-
if len(data_string) != found.end():
2686-
raise ValueError("unconverted data remains: %s" %
2687-
data_string[found.end():])
2688-
year = 1900
2689-
month = day = 1
2690-
hour = minute = second = fraction = 0
2691-
tz = -1
2692-
# Default to -1 to signify that values not known; not critical to have,
2693-
# though
2694-
week_of_year = -1
2695-
week_of_year_start = -1
2696-
# weekday and julian defaulted to -1 so as to signal need to calculate
2697-
# values
2698-
weekday = julian = -1
2699-
found_dict = found.groupdict()
2700-
for group_key in found_dict.iterkeys():
2701-
# Directives not explicitly handled below:
2702-
# c, x, X
2703-
# handled by making out of other directives
2704-
# U, W
2705-
# worthless without day of the week
2706-
if group_key == 'y':
2707-
year = int(found_dict['y'])
2708-
# Open Group specification for strptime() states that a %y
2709-
#value in the range of [00, 68] is in the century 2000, while
2710-
#[69,99] is in the century 1900
2711-
if year <= 68:
2712-
year += 2000
2713-
else:
2714-
year += 1900
2715-
elif group_key == 'Y':
2716-
year = int(found_dict['Y'])
2717-
elif group_key == 'm':
2718-
month = int(found_dict['m'])
2719-
elif group_key == 'B':
2720-
month = locale_time.f_month.index(found_dict['B'].lower())
2721-
elif group_key == 'b':
2722-
month = locale_time.a_month.index(found_dict['b'].lower())
2723-
elif group_key == 'd':
2724-
day = int(found_dict['d'])
2725-
elif group_key == 'H':
2726-
hour = int(found_dict['H'])
2727-
elif group_key == 'I':
2728-
hour = int(found_dict['I'])
2729-
ampm = found_dict.get('p', '').lower()
2730-
# If there was no AM/PM indicator, we'll treat this like AM
2731-
if ampm in ('', locale_time.am_pm[0]):
2732-
# We're in AM so the hour is correct unless we're
2733-
# looking at 12 midnight.
2734-
# 12 midnight == 12 AM == hour 0
2735-
if hour == 12:
2736-
hour = 0
2737-
elif ampm == locale_time.am_pm[1]:
2738-
# We're in PM so we need to add 12 to the hour unless
2739-
# we're looking at 12 noon.
2740-
# 12 noon == 12 PM == hour 12
2741-
if hour != 12:
2742-
hour += 12
2743-
elif group_key == 'M':
2744-
minute = int(found_dict['M'])
2745-
elif group_key == 'S':
2746-
second = int(found_dict['S'])
2747-
elif group_key == 'f':
2748-
s = found_dict['f']
2749-
# Pad to always return microseconds.
2750-
s += "0" * (6 - len(s))
2751-
fraction = int(s)
2752-
elif group_key == 'A':
2753-
weekday = locale_time.f_weekday.index(found_dict['A'].lower())
2754-
elif group_key == 'a':
2755-
weekday = locale_time.a_weekday.index(found_dict['a'].lower())
2756-
elif group_key == 'w':
2757-
weekday = int(found_dict['w'])
2758-
if weekday == 0:
2759-
weekday = 6
2760-
else:
2761-
weekday -= 1
2762-
elif group_key == 'j':
2763-
julian = int(found_dict['j'])
2764-
elif group_key in ('U', 'W'):
2765-
week_of_year = int(found_dict[group_key])
2766-
if group_key == 'U':
2767-
# U starts week on Sunday.
2768-
week_of_year_start = 6
2769-
else:
2770-
# W starts week on Monday.
2771-
week_of_year_start = 0
2772-
elif group_key == 'Z':
2773-
# Since -1 is default value only need to worry about setting tz if
2774-
# it can be something other than -1.
2775-
found_zone = found_dict['Z'].lower()
2776-
for value, tz_values in enumerate(locale_time.timezone):
2777-
if found_zone in tz_values:
2778-
# Deal with bad locale setup where timezone names are the
2779-
# same and yet time.daylight is true; too ambiguous to
2780-
# be able to tell what timezone has daylight savings
2781-
if (time.tzname[0] == time.tzname[1] and
2782-
time.daylight and found_zone not in ("utc", "gmt")):
2783-
break
2784-
else:
2785-
tz = value
2786-
break
2787-
# If we know the week of the year and what day of that week, we can figure
2788-
# out the Julian day of the year.
2789-
if julian == -1 and week_of_year != -1 and weekday != -1:
2790-
week_starts_Mon = True if week_of_year_start == 0 else False
2791-
julian = _calc_julian_from_U_or_W(year, week_of_year, weekday,
2792-
week_starts_Mon)
2793-
# Cannot pre-calculate datetime_date() since can change in Julian
2794-
# calculation and thus could have different value for the day of the week
2795-
# calculation.
2796-
if julian == -1:
2797-
# Need to add 1 to result since first day of the year is 1, not 0.
2798-
julian = datetime_date(year, month, day).toordinal() - \
2799-
datetime_date(year, 1, 1).toordinal() + 1
2800-
else: # Assume that if they bothered to include Julian day it will
2801-
# be accurate.
2802-
datetime_result = datetime_date.fromordinal((julian - 1) + datetime_date(year, 1, 1).toordinal())
2803-
year = datetime_result.year
2804-
month = datetime_result.month
2805-
day = datetime_result.day
2806-
if weekday == -1:
2807-
weekday = datetime_date(year, month, day).weekday()
2808-
2809-
dts.year = year
2810-
dts.month = month
2811-
dts.day = day
2812-
dts.hour = hour
2813-
dts.min = minute
2814-
dts.sec = second
2815-
dts.us = fraction * 1000000
2816-
28172653
# def _strptime_time(data_string, format="%a %b %d %H:%M:%S %Y"):
28182654
# return _strptime(data_string, format)[0]

0 commit comments

Comments
 (0)