Skip to content

Commit f6ee3e3

Browse files
Fix issue 203 (#205)
* Map gregorian calendar to standard calendar (not the other way around) * Updated existing unit tests * fixed 2 unit tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1d46964 commit f6ee3e3

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

cf_units/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
#: Where calendars have multiple names, we map the alias to the
131131
#: definitive form.
132132
CALENDAR_ALIASES = {
133-
CALENDAR_STANDARD: CALENDAR_GREGORIAN,
133+
CALENDAR_GREGORIAN: CALENDAR_STANDARD,
134134
CALENDAR_NO_LEAP: CALENDAR_365_DAY,
135135
CALENDAR_ALL_LEAP: CALENDAR_366_DAY,
136136
}
@@ -830,7 +830,7 @@ def __init__(self, unit, calendar=None):
830830
raise value_error from None
831831
if _OP_SINCE in unit.lower():
832832
if calendar is None:
833-
calendar_ = CALENDAR_GREGORIAN
833+
calendar_ = CALENDAR_STANDARD
834834
elif isinstance(calendar, (str,)):
835835
calendar_ = calendar.lower()
836836
if calendar_ in CALENDAR_ALIASES:
@@ -1813,10 +1813,7 @@ def convert(self, value, other, ctype=FLOAT64, inplace=False):
18131813
result = copy.deepcopy(value)
18141814
# Use cftime for converting reference times that are not using a
18151815
# gregorian calendar as it handles these and udunits does not.
1816-
if (
1817-
self.is_time_reference()
1818-
and self.calendar != CALENDAR_GREGORIAN
1819-
):
1816+
if self.is_time_reference() and self.calendar != CALENDAR_STANDARD:
18201817
result_datetimes = cftime.num2date(
18211818
result, self.cftime_unit, self.calendar
18221819
)

cf_units/tests/test_unit.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_calendar_alias(self):
4747

4848
def test_no_calendar(self):
4949
u = Unit("hours since 1970-01-01 00:00:00")
50-
self.assertEqual(u.calendar, unit.CALENDAR_GREGORIAN)
50+
self.assertEqual(u.calendar, unit.CALENDAR_STANDARD)
5151

5252
def test_unsupported_calendar(self):
5353
with self.assertRaisesRegex(ValueError, "unsupported calendar"):
@@ -576,9 +576,9 @@ def test___repr___basic(self):
576576

577577
def test___repr___time_unit(self):
578578
u = Unit(
579-
"hours since 2007-01-15 12:06:00", calendar=unit.CALENDAR_STANDARD
579+
"hours since 2007-01-15 12:06:00", calendar=unit.CALENDAR_GREGORIAN
580580
)
581-
exp = "Unit('hours since 2007-01-15 12:06:00', calendar='gregorian')"
581+
exp = "Unit('hours since 2007-01-15 12:06:00', calendar='standard')"
582582
self.assertEqual(repr(u), exp)
583583

584584

@@ -949,11 +949,11 @@ def test_decode_time(self):
949949
class TestNumsAndDates(unittest.TestCase):
950950
def test_num2date(self):
951951
u = Unit(
952-
"hours since 2010-11-02 12:00:00", calendar=unit.CALENDAR_STANDARD
952+
"hours since 2010-11-02 12:00:00", calendar=unit.CALENDAR_GREGORIAN
953953
)
954954
res = u.num2date(1)
955955
self.assertEqual(str(res), "2010-11-02 13:00:00")
956-
self.assertEqual(res.calendar, "gregorian")
956+
self.assertEqual(res.calendar, "standard")
957957
self.assertIsInstance(res, cftime.datetime)
958958

959959
def test_num2date_py_datetime_type(self):

cf_units/tests/unit/unit/test_Unit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
class Test___init__(unittest.TestCase):
1717
def test_capitalised_calendar(self):
18-
calendar = "GrEgoRian"
19-
expected = cf_units.CALENDAR_GREGORIAN
18+
calendar = "StAnDaRd"
19+
expected = cf_units.CALENDAR_STANDARD
2020
u = Unit("hours since 1970-01-01 00:00:00", calendar=calendar)
2121
self.assertEqual(u.calendar, expected)
2222

cf_units/tests/unit/unit/test_as_unit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ def test_cf_unit(self):
4646
def test_non_cf_unit_no_calendar(self):
4747
# On passing as_unit a cf_unit.Unit-like object (not a cf_unit.Unit
4848
# object) with no calendar, ensure that a cf_unit.Unit is returned
49-
# with default calendar (Gregorian).
49+
# with default calendar (standard).
5050
unit = StubUnit()
5151
result = as_unit(unit)
5252

53-
self.assertEqual(result.calendar, "gregorian")
53+
self.assertEqual(result.calendar, "standard")
5454
self.assertIsInstance(result, Unit)
5555

5656
def test_non_cf_unit_with_calendar(self):

0 commit comments

Comments
 (0)