def test_timedelta_generic_api(self): cases = [ (T.timedelta(weeks=2), T.week(2)), (T.timedelta(days=3), T.day(3)), (T.timedelta(hours=4), T.hour(4)), (T.timedelta(minutes=5), T.minute(5)), (T.timedelta(seconds=6), T.second(6)), (T.timedelta(milliseconds=7), T.millisecond(7)), (T.timedelta(microseconds=8), T.microsecond(8)), (T.timedelta(nanoseconds=9), T.nanosecond(9)), ] self._check_cases(cases)
def test_upconvert(self): cases = [ (T.day(14), 'w', T.week(2)), (T.hour(72), 'd', T.day(3)), (T.minute(240), 'h', T.hour(4)), (T.second(360), 'm', T.minute(6)), (T.second(3 * 86400), 'd', T.day(3)), (T.millisecond(5000), 's', T.second(5)), (T.microsecond(5000000), 's', T.second(5)), (T.nanosecond(5000000000), 's', T.second(5)), ] for offset, unit, expected in cases: result = offset.to_unit(unit) assert result.equals(expected)
def test_downconvert_day(self): K = 2 week = T.week(K) day = T.day(K) cases = [(week.to_unit('d'), T.day(K * 7)), (week.to_unit('h'), T.hour(K * 7 * 24)), (day.to_unit('d'), T.day(K)), (day.to_unit('h'), T.hour(K * 24)), (day.to_unit('m'), T.minute(K * 1440)), (day.to_unit('s'), T.second(K * 86400)), (day.to_unit('ms'), T.millisecond(K * 86400000)), (day.to_unit('us'), T.microsecond(K * 86400000000)), (day.to_unit('ns'), T.nanosecond(K * 86400000000000))] self._check_cases(cases)
def test_downconvert_day(self): K = 2 week = T.week(K) day = T.day(K) cases = [ (week.to_unit("d"), T.day(K * 7)), (week.to_unit("h"), T.hour(K * 7 * 24)), (day.to_unit("d"), T.day(K)), (day.to_unit("h"), T.hour(K * 24)), (day.to_unit("m"), T.minute(K * 1440)), (day.to_unit("s"), T.second(K * 86400)), (day.to_unit("ms"), T.millisecond(K * 86400000)), (day.to_unit("us"), T.microsecond(K * 86400000000)), (day.to_unit("ns"), T.nanosecond(K * 86400000000000L)), ] self._check_cases(cases)
def test_downconvert_day(self): K = 2 week = T.week(K) day = T.day(K) cases = [ (week.to_unit('d'), T.day(K * 7)), (week.to_unit('h'), T.hour(K * 7 * 24)), (day.to_unit('d'), T.day(K)), (day.to_unit('h'), T.hour(K * 24)), (day.to_unit('m'), T.minute(K * 1440)), (day.to_unit('s'), T.second(K * 86400)), (day.to_unit('ms'), T.millisecond(K * 86400000)), (day.to_unit('us'), T.microsecond(K * 86400000000)), (day.to_unit('ns'), T.nanosecond(K * 86400000000000)) ] self._check_cases(cases)
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import pytest from ibis.common import IbisError import ibis.expr.operations as ops import ibis.expr.types as ir import ibis.expr.temporal as T @pytest.mark.parametrize(('offset', 'unit', 'expected'), [ (T.day(14), 'w', T.week(2)), (T.hour(72), 'd', T.day(3)), (T.minute(240), 'h', T.hour(4)), (T.second(360), 'm', T.minute(6)), (T.second(3 * 86400), 'd', T.day(3)), (T.millisecond(5000), 's', T.second(5)), (T.microsecond(5000000), 's', T.second(5)), (T.nanosecond(5000000000), 's', T.second(5)), ]) def test_upconvert(offset, unit, expected): result = offset.to_unit(unit) assert result.equals(expected) def test_multiply(): offset = T.day(2)