Repository: crsmithdev/arrow
Pull request #735 (2019-12-11 02:15:11)

allowing plural 'name' arguments to _get_frames
## Pull Request Checklist

Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all *appropriate* boxes:

<!-- Check boxes by placing an x in the brackets: [x] -->
- [x] 🧪 Added **tests** for changed code.
- [x] 🛠️ All tests **pass** when run locally (run `tox` or `make test` to find out!).
- [x] 📚 Updated **documentation** for changed code.
- [x] ⏩ Code is **up-to-date** with the `master` branch.

If you have *any* questions about your code changes or any of the points above, please submit your questions along with the pull request and we will try our best to help!

## Description of Changes
This change allows _get_frames to prase plural forms of the 'frame' argument (e.g. "day" and "days").
This change reduces confusion in users by providing them with more consistent function interfaces that accept both singular and plural 'frames' arguments, instead of the current interface that accepts "weeks" and "quarters" but not "days" or "hours".

Closes: #298 

<!--
Replace with description of code changes.

If your PR has an associated issue, insert the issue number (e.g. #703) or directly link to the GitHub issue (e.g. https://github.com/crsmithdev/arrow/issues/703).

For example, doing the following will automatically close issue #703 when this PR is merged:

Closes: #703
-->


codecov-io: # [Codecov](https://codecov.io/gh/crsmithdev/arrow/pull/735?src=pr&el=h1) Report
> Merging [#735](https://codecov.io/gh/crsmithdev/arrow/pull/735?src=pr&el=desc) into [master](https://codecov.io/gh/crsmithdev/arrow/commit/5395fbbeda82dea6eb92ce095a8f3abbefb00fde?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/crsmithdev/arrow/pull/735/graphs/tree.svg?width=650&token=4EkGnFsIGn&height=150&src=pr)](https://codecov.io/gh/crsmithdev/arrow/pull/735?src=pr&el=tree)

```diff
@@          Coverage Diff          @@
##           master   #735   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           9      9           
  Lines        1678   1665   -13     
  Branches      283    284    +1     
=====================================
- Hits         1678   1665   -13
```


| [Impacted Files](https://codecov.io/gh/crsmithdev/arrow/pull/735?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [arrow/arrow.py](https://codecov.io/gh/crsmithdev/arrow/pull/735/diff?src=pr&el=tree#diff-YXJyb3cvYXJyb3cucHk=) | `100% <100%> (ø)` | :arrow_up: |
| [arrow/parser.py](https://codecov.io/gh/crsmithdev/arrow/pull/735/diff?src=pr&el=tree#diff-YXJyb3cvcGFyc2VyLnB5) | `100% <0%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/crsmithdev/arrow/pull/735?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/crsmithdev/arrow/pull/735?src=pr&el=footer). Last update [5395fbb...4cd20ec](https://codecov.io/gh/crsmithdev/arrow/pull/735?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/arrow/arrow.py b/arrow/arrow.py
index 1099a6d..aff3508 100644
--- a/arrow/arrow.py
+++ b/arrow/arrow.py
@@ -1437,13 +1437,26 @@ class Arrow(object):
 
         if name in cls._ATTRS:
             return name, "{}s".format(name), 1
-
+        elif name[-1] == "s" and name[:-1] in cls._ATTRS:
+            return name[:-1], name, 1
         elif name in ["week", "weeks"]:
             return "week", "weeks", 1
         elif name in ["quarter", "quarters"]:
             return "quarter", "months", 3
 
-        supported = ", ".join(cls._ATTRS + ["week", "weeks"] + ["quarter", "quarters"])
+        supported = ", ".join(
+            [
+                "year(s)",
+                "month(s)",
+                "day(s)",
+                "hour(s)",
+                "minute(s)",
+                "second(s)",
+                "microsecond(s)",
+                "week(s)",
+                "quarter(s)",
+            ]
+        )
         raise AttributeError(
             "range/span over frame {} not supported. Supported frames: {}".format(
                 name, supported


Test patch:
diff --git a/tests/arrow_tests.py b/tests/arrow_tests.py
index c358329..6214ada 100644
--- a/tests/arrow_tests.py
+++ b/tests/arrow_tests.py
@@ -1058,6 +1058,36 @@ class ArrowSpanRangeTests(Chai):
             ],
         )
 
+    def test_days(self):
+
+        result = list(
+            arrow.Arrow.span_range(
+                "days", datetime(2013, 1, 1, 12), datetime(2013, 1, 4, 12)
+            )
+        )
+
+        self.assertEqual(
+            result,
+            [
+                (
+                    arrow.Arrow(2013, 1, 1, 0),
+                    arrow.Arrow(2013, 1, 1, 23, 59, 59, 999999),
+                ),
+                (
+                    arrow.Arrow(2013, 1, 2, 0),
+                    arrow.Arrow(2013, 1, 2, 23, 59, 59, 999999),
+                ),
+                (
+                    arrow.Arrow(2013, 1, 3, 0),
+                    arrow.Arrow(2013, 1, 3, 23, 59, 59, 999999),
+                ),
+                (
+                    arrow.Arrow(2013, 1, 4, 0),
+                    arrow.Arrow(2013, 1, 4, 23, 59, 59, 999999),
+                ),
+            ],
+        )
+
     def test_hour(self):
 
         result = list(