clockwork 0.1.3__tar.gz → 0.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clockwork
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: Toolkit for time-related operations including scheduling, logging, date manipulation, and more.
5
5
  Home-page: https://github.com/zteinck/clockwork
6
6
  License: MIT
@@ -0,0 +1,4 @@
1
+ from .core import *
2
+
3
+ __version__ = '0.1.4'
4
+ __author__ = 'Zachary Einck <zacharyeinck@gmail.com>'
@@ -1,9 +1,8 @@
1
1
  import datetime
2
2
  import calendar
3
3
  import time
4
- from functools import cached_property
5
4
  from dateutil.relativedelta import relativedelta
6
- import holidays
5
+ import holidays as hd
7
6
  import pandas as pd
8
7
  import numpy as np
9
8
 
@@ -19,6 +18,11 @@ class DateBase(object):
19
18
  --------------------
20
19
  factory : func
21
20
  initializes new instances as the correct subclass
21
+ weekdays : dict
22
+ dictionary where keys are the days of the week and values
23
+ are the corresponding index values
24
+ holidays : holidays.countries.united_states.UnitedStates
25
+ comprehensive list of U.S. holidays
22
26
 
23
27
  Instance Attributes
24
28
  --------------------
@@ -26,6 +30,15 @@ class DateBase(object):
26
30
  date and time (if applicable)
27
31
  '''
28
32
 
33
+ #╭-------------------------------------------------------------------------╮
34
+ #| Class Attributes |
35
+ #╰-------------------------------------------------------------------------╯
36
+
37
+ holidays = hd.UnitedStates()
38
+ weekdays = {k: i for i, k in enumerate(calendar.day_name)}
39
+ weekdays.update({k[:3]: v for k, v in weekdays.items()})
40
+
41
+
29
42
  #╭-------------------------------------------------------------------------╮
30
43
  #| Initialize Instance |
31
44
  #╰-------------------------------------------------------------------------╯
@@ -119,7 +132,7 @@ class DateBase(object):
119
132
  ''' spawn new date instance '''
120
133
 
121
134
  def wrapper(self, *args, **kwargs):
122
- return cls.spawn(func(self, *args, **kwargs))
135
+ return self.spawn(func(self, *args, **kwargs))
123
136
 
124
137
  return wrapper
125
138
 
@@ -145,9 +158,9 @@ class DateBase(object):
145
158
  def wrapper(self, other):
146
159
  try:
147
160
  other = datetime.timedelta(float(other))
148
- return cls.spawn(func(self, other))
161
+ return self.spawn(func(self, other))
149
162
  except:
150
- other = cls.spawn(other).dt
163
+ other = self.spawn(other).dt
151
164
  return func(self, other)
152
165
 
153
166
  return wrapper
@@ -300,20 +313,6 @@ class DateBase(object):
300
313
  ''' returns the current holiday, if applicable '''
301
314
  return self.holidays.get(self.ymd)
302
315
 
303
- @cached_property
304
- def weekdays(self):
305
- ''' dictionary where keys are the days of the week and values are the corresponding index values '''
306
- out = {k: i for i, k in enumerate((
307
- 'Monday','Tuesday','Wednesday','Thursday',
308
- 'Friday','Saturday','Sunday'))}
309
- out.update({k[:3]: v for k, v in out.items()})
310
- return out
311
-
312
- @cached_property
313
- def holidays(self):
314
- ''' comprehensive list of U.S. holidays '''
315
- return holidays.UnitedStates()
316
-
317
316
 
318
317
  #╭-------------------------------------------------------------------------╮
319
318
  #| Magic Methods |
@@ -30,7 +30,7 @@ def Date(arg=None, normalize=False, week_offset=0):
30
30
  • string
31
31
  ► day of the week fully spelled out or first 3 letters (not case sensitive)
32
32
  (e.g. 'Monday', 'monday', 'mon')
33
- ► quarter in #QYY or YYYYQ# format
33
+ ► quarter in #QYY, YYYYQ#, or Q# format
34
34
  ► any string format supported by pd.to_datetime
35
35
  • DateBase object or DateBase polymorphism
36
36
  normalize : bool
@@ -51,15 +51,20 @@ def Date(arg=None, normalize=False, week_offset=0):
51
51
  def qtr_label_to_dt(x):
52
52
  ''' attempts to convert quarter expressed as string to datetime.
53
53
  Suported formats include #QYY and YYYYQ# '''
54
+ x = x.upper()
54
55
  try:
55
- qtr, year = re.findall(r'(\d{1})Q(\d{2})', x)[0]
56
+ qtr, year = re.findall(r'^(\d{1})Q(\d{2})$', x)[0]
56
57
  except:
57
58
  try:
58
- year, qtr = re.findall(r'(\d{4})Q(\d{1})', x)[0]
59
+ year, qtr = re.findall(r'^(\d{4})Q(\d{1})$', x)[0]
59
60
  except:
60
- return
61
+ try:
62
+ qtr = re.findall(r'^Q(\d{1})$', x)[0]
63
+ year = datetime.datetime.now().year
64
+ except:
65
+ return
61
66
 
62
- inverse = {v: k for k,v in qtr_map.items()}
67
+ inverse = {v: k for k, v in qtr_map.items()}
63
68
  month, day = inverse[int(qtr)]
64
69
  out = DateBase.to_datetime(f'{month}-{day}-{year}')
65
70
  return out
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "clockwork"
3
- version = "0.1.3"
3
+ version = "0.1.4"
4
4
  description = "Toolkit for time-related operations including scheduling, logging, date manipulation, and more."
5
5
  authors = ["Zachary Einck <zacharyeinck@gmail.com>"]
6
6
  license = "MIT"
@@ -1,4 +0,0 @@
1
- from .core import *
2
-
3
- __version__ = '0.1.3'
4
- __author__ = 'Zachary Einck <zacharyeinck@gmail.com>'
File without changes
File without changes
File without changes