From: Scott Gasch Date: Thu, 13 Oct 2022 19:14:13 +0000 (-0700) Subject: More work on improving docs. X-Git-Url: https://wannabe.guru.org/gitweb/?a=commitdiff_plain;h=eb7d4fcb7edb2f6d405cbfbba6bb2df484af4d94;p=pyutils.git More work on improving docs. --- diff --git a/examples/parallelize_config/.remote_worker_records b/examples/parallelize_config/.remote_worker_records new file mode 100644 index 0000000..1a41fbf --- /dev/null +++ b/examples/parallelize_config/.remote_worker_records @@ -0,0 +1,16 @@ +# This file is a record of remote workers that @parallelize(method=Method.REMOTE) +# may send work to. Each must have the same version of python installed and the +# cloudpickle package available. "username" (see below) must be able to ssh into +# each machine non-interactively (e.g. with a public/private trusted key, see ssh +# documentation). "weight" should be used to indicate the speed of a CPU on the +# target machine and "count" should be used to indicate how many parallel jobs +# (max) to schedule on that machine. +{ + "remote_worker_records": [ + {"username": "scott", "machine": "machine_one", "weight": 24, "count": 5}, + {"username": "scott", "machine": "machine_two", "weight": 10, "count": 2}, + {"username": "scott", "machine": "machine_three", "weight": 14, "count": 1}, + {"username": "scott", "machine": "machine_four", "weight": 9, "count": 2}, + {"username": "scott", "machine": "machine_five", "weight": 9, "count": 2}, + ] +} diff --git a/src/pyutils/collectionz/shared_dict.py b/src/pyutils/collectionz/shared_dict.py index ef74f93..ec17d9f 100644 --- a/src/pyutils/collectionz/shared_dict.py +++ b/src/pyutils/collectionz/shared_dict.py @@ -4,6 +4,7 @@ The MIT License (MIT) Copyright (c) 2020 LuizaLabs + Additions/Modifications Copyright (c) 2022 Scott Gasch Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/src/pyutils/datetimez/datetime_utils.py b/src/pyutils/datetimez/datetime_utils.py index ed76c9e..c47d38c 100644 --- a/src/pyutils/datetimez/datetime_utils.py +++ b/src/pyutils/datetimez/datetime_utils.py @@ -391,44 +391,54 @@ def n_timeunits_from_base( >>> base = string_to_datetime("2021/09/10 11:24:51AM-0700")[0] The next (1) Monday from the base datetime: + >>> n_timeunits_from_base(+1, TimeUnit.MONDAYS, base) datetime.datetime(2021, 9, 13, 11, 24, 51, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200))) Ten (10) years after the base datetime: + >>> n_timeunits_from_base(10, TimeUnit.YEARS, base) datetime.datetime(2031, 9, 10, 11, 24, 51, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200))) Fifty (50) working days (M..F, not counting holidays) after base datetime: + >>> n_timeunits_from_base(50, TimeUnit.WORKDAYS, base) datetime.datetime(2021, 11, 23, 11, 24, 51, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200))) Fifty (50) days (including weekends and holidays) after base datetime: + >>> n_timeunits_from_base(50, TimeUnit.DAYS, base) datetime.datetime(2021, 10, 30, 11, 24, 51, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200))) Fifty (50) months before (note negative count) base datetime: + >>> n_timeunits_from_base(-50, TimeUnit.MONTHS, base) datetime.datetime(2017, 7, 10, 11, 24, 51, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200))) Fifty (50) hours after base datetime: + >>> n_timeunits_from_base(50, TimeUnit.HOURS, base) datetime.datetime(2021, 9, 12, 13, 24, 51, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200))) Fifty (50) minutes before base datetime: + >>> n_timeunits_from_base(-50, TimeUnit.MINUTES, base) datetime.datetime(2021, 9, 10, 10, 34, 51, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200))) Fifty (50) seconds from base datetime: + >>> n_timeunits_from_base(50, TimeUnit.SECONDS, base) datetime.datetime(2021, 9, 10, 11, 25, 41, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200))) Next month corner case -- it will try to make Feb 31, 2022 then count backwards. + >>> base = string_to_datetime("2022/01/31 11:24:51AM-0700")[0] >>> n_timeunits_from_base(1, TimeUnit.MONTHS, base) datetime.datetime(2022, 2, 28, 11, 24, 51, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200))) Last month with the same corner case + >>> base = string_to_datetime("2022/03/31 11:24:51AM-0700")[0] >>> n_timeunits_from_base(-1, TimeUnit.MONTHS, base) datetime.datetime(2022, 2, 28, 11, 24, 51, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200))) diff --git a/src/pyutils/string_utils.py b/src/pyutils/string_utils.py index 575e64e..69ab837 100644 --- a/src/pyutils/string_utils.py +++ b/src/pyutils/string_utils.py @@ -4,6 +4,7 @@ """The MIT License (MIT) Copyright (c) 2016-2020 Davide Zanotti + Modifications Copyright (c) 2021-2022 Scott Gasch Permission is hereby granted, free of charge, to any person obtaining a copy @@ -1680,7 +1681,7 @@ def sprintf(*args, **kwargs) -> str: Returns: An interpolated string capturing print output, like man(3) - :code:sprintf. + `sprintf`. """ ret = "" @@ -2033,7 +2034,11 @@ def ngrams_presplit(words: Sequence[str], n: int): def bigrams(txt: str): - """Generates the bigrams (n=2) of the given string.""" + """Generates the bigrams (n=2) of the given string. + + >>> [x for x in bigrams('this is a test')] + ['this is', 'is a', 'a test'] + """ return ngrams(txt, 2)