text
stringlengths
0
20k
import pytest from pandas._libs.tslibs.dtypes import NpyDatetimeUnit from pandas.errors import OutOfBoundsTimedelta from pandas import Timedelta class TestAsUnit: def test_as_unit(self): td = Timedelta(days=1) assert td.as_unit("ns") is td res = td.as_unit("us") assert res._val...
from hypothesis import ( given, strategies as st, ) import numpy as np import pytest from pandas._libs import lib from pandas._libs.tslibs import iNaT from pandas.errors import OutOfBoundsTimedelta from pandas import Timedelta class TestTimedeltaRound: @pytest.mark.parametrize( "freq,s1,s2", ...
from datetime import ( date, time, timedelta, ) import pickle import numpy as np import pytest from pandas._libs.missing import NA from pandas.core.dtypes.common import is_scalar import pandas as pd import pandas._testing as tm def test_singleton(): assert NA is NA new_NA = type(NA)() asse...
from datetime import ( datetime, timedelta, ) import operator import numpy as np import pytest from pandas import Timestamp import pandas._testing as tm class TestTimestampComparison: def test_compare_non_nano_dt64(self): # don't raise when converting dt64 to Timestamp in __richcmp__ dt ...
from datetime import datetime import pprint import dateutil.tz import pytest import pytz # a test below uses pytz but only inside a `eval` call from pandas import Timestamp ts_no_ns = Timestamp( year=2019, month=5, day=18, hour=15, minute=17, second=8, microsecond=132263, ) ts_no_ns_year...
from datetime import ( datetime, timedelta, timezone, ) from dateutil.tz import gettz import numpy as np import pytest import pytz from pandas._libs.tslibs import ( OutOfBoundsDatetime, OutOfBoundsTimedelta, Timedelta, Timestamp, offsets, to_offset, ) import pandas._testing as tm ...
from datetime import ( datetime, timedelta, ) import pytz from pandas._libs.tslibs.timezones import dateutil_gettz as gettz import pandas.util._test_decorators as td from pandas import Timestamp import pandas._testing as tm class TestTimestampToPyDatetime: def test_to_pydatetime_fold(self): # G...
import pytest from pandas._libs.tslibs.dtypes import NpyDatetimeUnit from pandas.errors import OutOfBoundsDatetime from pandas import Timestamp class TestTimestampAsUnit: def test_as_unit(self): ts = Timestamp("1970-01-01").as_unit("ns") assert ts.unit == "ns" assert ts.as_unit("ns") is...
import pytest from pandas._libs.tslibs import Timestamp from pandas._libs.tslibs.dtypes import NpyDatetimeUnit class TestTimestampNormalize: @pytest.mark.parametrize("arg", ["2013-11-30", "2013-11-30 12:00:00"]) @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_normalize(self, tz_naive_f...
from hypothesis import ( given, strategies as st, ) import numpy as np import pytest import pytz from pandas._libs import lib from pandas._libs.tslibs import ( NaT, OutOfBoundsDatetime, Timedelta, Timestamp, iNaT, to_offset, ) from pandas._libs.tslibs.dtypes import NpyDatetimeUnit from ...
# NB: This is for the Timestamp.timestamp *method* specifically, not # the Timestamp class in general. from pytz import utc from pandas._libs.tslibs import Timestamp import pandas.util._test_decorators as td import pandas._testing as tm class TestTimestampMethod: @td.skip_if_windows def test_timestamp(self...
from pandas import Timestamp class TestTimestampToJulianDate: def test_compare_1700(self): ts = Timestamp("1700-06-23") res = ts.to_julian_date() assert res == 2_342_145.5 def test_compare_2000(self): ts = Timestamp("2000-04-12") res = ts.to_julian_date() asser...
from datetime import datetime from dateutil.tz import gettz import numpy as np import pytest import pytz from pandas._libs.tslibs import ( OutOfBoundsDatetime, Timestamp, conversion, ) from pandas._libs.tslibs.dtypes import NpyDatetimeUnit import pandas.util._test_decorators as td import pandas._testing ...
from datetime import timedelta import re from dateutil.tz import gettz import pytest import pytz from pytz.exceptions import ( AmbiguousTimeError, NonExistentTimeError, ) from pandas._libs.tslibs.dtypes import NpyDatetimeUnit from pandas.errors import OutOfBoundsDatetime from pandas import ( NaT, Tim...
import dateutil import pytest from pandas._libs.tslibs import timezones import pandas.util._test_decorators as td from pandas import Timestamp class TestTimestampTZConvert: @pytest.mark.parametrize("tzstr", ["US/Eastern", "dateutil/US/Eastern"]) def test_astimezone(self, tzstr): # astimezone is an a...
""" Tests for Timestamp timezone-related methods """ from datetime import datetime from pandas._libs.tslibs import timezones from pandas import Timestamp class TestTimestampTZOperations: # ------------------------------------------------------------------ def test_timestamp_timetz_equivalent_with_datetime_...
import numpy as np import pytest from pandas import ( Interval, Timedelta, Timestamp, ) @pytest.fixture def interval(): return Interval(0, 1) class TestInterval: def test_properties(self, interval): assert interval.closed == "right" assert interval.left == 0 assert inter...
import pytest from pandas import ( Interval, Timedelta, Timestamp, ) @pytest.fixture( params=[ (Timedelta("0 days"), Timedelta("1 day")), (Timestamp("2018-01-01"), Timedelta("1 day")), (0, 1), ], ids=lambda x: type(x[0]).__name__, ) def start_shift(request): """ ...
import pytest from pandas import ( Interval, Period, Timestamp, ) class TestIntervalConstructors: @pytest.mark.parametrize( "left, right", [ ("a", "z"), (("a", "b"), ("c", "d")), (list("AB"), list("ab")), (Interval(0, 1), Interval(1, 2))...
from pandas import Interval def test_interval_repr(): interval = Interval(0, 1) assert repr(interval) == "Interval(0, 1, closed='right')" assert str(interval) == "(0, 1]" interval_left = Interval(0, 1, closed="left") assert repr(interval_left) == "Interval(0, 1, closed='left')" assert str(int...
import pytest from pandas import ( Interval, Timedelta, Timestamp, ) class TestContains: def test_contains(self): interval = Interval(0, 1) assert 0.5 in interval assert 1 in interval assert 0 not in interval interval_both = Interval(0, 1, "both") asse...
from datetime import timedelta import numpy as np import pytest from pandas import ( Interval, Timedelta, Timestamp, ) import pandas._testing as tm class TestIntervalArithmetic: def test_interval_add(self, closed): interval = Interval(0, 1, closed=closed) expected = Interval(1, 2, cl...
from datetime import ( datetime, timedelta, ) import operator import numpy as np import pytest import pytz from pandas._libs.tslibs import iNaT from pandas.compat.numpy import np_version_gte1p24p3 from pandas import ( DatetimeIndex, DatetimeTZDtype, Index, NaT, Period, Series, Tim...
import pytest from pandas._config import config as cf from pandas._config.config import OptionError import pandas as pd import pandas._testing as tm class TestConfig: @pytest.fixture(autouse=True) def clean_config(self, monkeypatch): with monkeypatch.context() as m: m.setattr(cf, "_globa...
import codecs import locale import os import pytest from pandas._config.localization import ( can_set_locale, get_locales, set_locale, ) from pandas.compat import ISMUSL import pandas as pd _all_locales = get_locales() _current_locale = locale.setlocale(locale.LC_ALL) # getlocale() is wrong, see GH#46...
from datetime import datetime import pytest from pandas.tseries.holiday import ( after_nearest_workday, before_nearest_workday, nearest_workday, next_monday, next_monday_or_tuesday, next_workday, previous_friday, previous_workday, sunday_to_monday, weekend_to_monday, ) _WEDNES...
from datetime import datetime from pandas import DatetimeIndex import pandas._testing as tm from pandas.tseries.holiday import ( AbstractHolidayCalendar, USFederalHolidayCalendar, USMartinLutherKingJr, USMemorialDay, ) def test_no_mlk_before_1986(): # see gh-10278 class MLKCalendar(AbstractH...
from datetime import datetime import pytest from pytz import utc from pandas import ( DatetimeIndex, Series, ) import pandas._testing as tm from pandas.tseries.holiday import ( MO, SA, AbstractHolidayCalendar, DateOffset, EasterMonday, GoodFriday, Holiday, HolidayCalendarFacto...
from datetime import datetime import pytest from pandas import ( DatetimeIndex, offsets, to_datetime, ) import pandas._testing as tm from pandas.tseries.holiday import ( AbstractHolidayCalendar, Holiday, Timestamp, USFederalHolidayCalendar, USLaborDay, USThanksgivingDay, get_c...
from datetime import ( datetime, timedelta, ) import numpy as np import pytest from pandas._libs.tslibs.ccalendar import ( DAYS, MONTHS, ) from pandas._libs.tslibs.offsets import _get_offset from pandas._libs.tslibs.period import INVALID_FREQ_ERR_MSG from pandas.compat import is_platform_windows from...
import pytest from pandas._libs.tslibs import offsets from pandas.tseries.frequencies import ( is_subperiod, is_superperiod, ) @pytest.mark.parametrize( "p1,p2,expected", [ # Input validation. (offsets.MonthEnd(), None, False), (offsets.YearEnd(), None, False), (None,...
import numpy as np import pytest from pandas._libs.tslibs import ( Period, to_offset, ) @pytest.mark.parametrize( "freqstr,exp_freqstr", [("D", "D"), ("W", "D"), ("ME", "D"), ("s", "s"), ("min", "s"), ("h", "s")], ) def test_get_to_timestamp_base(freqstr, exp_freqstr): off = to_offset(freqstr) ...
""" Behavioral based tests for offsets and date_range. This file is adapted from https://github.com/pandas-dev/pandas/pull/18761 - which was more ambitious but less idiomatic in its use of Hypothesis. You may wish to consult the previous version for inspiration on further tests, or when trying to pin down the bugs ex...
""" Tests for offsets.BDay """ from __future__ import annotations from datetime import ( date, datetime, timedelta, ) import numpy as np import pytest from pandas._libs.tslibs.offsets import ( ApplyTypeError, BDay, BMonthEnd, ) from pandas import ( DatetimeIndex, Timedelta, _test...
""" Tests for the following offsets: - CustomBusinessMonthBase - CustomBusinessMonthBegin - CustomBusinessMonthEnd """ from __future__ import annotations from datetime import ( date, datetime, timedelta, ) import numpy as np import pytest from pandas._libs.tslibs.offsets import ( CBMonthBegin, CB...
""" Tests for offset behavior with indices. """ import pytest from pandas import ( Series, date_range, ) from pandas.tseries.offsets import ( BMonthBegin, BMonthEnd, BQuarterBegin, BQuarterEnd, BYearBegin, BYearEnd, MonthBegin, MonthEnd, QuarterBegin, QuarterEnd, Ye...
""" Tests for DateOffset additions over Daylight Savings Time """ from datetime import timedelta import pytest import pytz from pandas._libs.tslibs import Timestamp from pandas._libs.tslibs.offsets import ( BMonthBegin, BMonthEnd, BQuarterBegin, BQuarterEnd, BYearBegin, BYearEnd, CBMonthBe...
""" Tests for the following offsets: - YearBegin - YearEnd """ from __future__ import annotations from datetime import datetime import numpy as np import pytest from pandas import Timestamp from pandas.tests.tseries.offsets.common import ( assert_is_on_offset, assert_offset_equal, ) from pandas.tseries.offs...
""" Tests for offsets.CustomBusinessHour """ from __future__ import annotations from datetime import ( datetime, time as dt_time, ) import numpy as np import pytest from pandas._libs.tslibs import Timestamp from pandas._libs.tslibs.offsets import ( BusinessHour, CustomBusinessHour, Nano, ) from ...
""" Tests for the following offsets: - Week - WeekOfMonth - LastWeekOfMonth """ from __future__ import annotations from datetime import ( datetime, timedelta, ) import pytest from pandas._libs.tslibs import Timestamp from pandas._libs.tslibs.offsets import ( Day, LastWeekOfMonth, Week, WeekOf...
""" Assertion helpers and base class for offsets tests """ from __future__ import annotations def assert_offset_equal(offset, base, expected): actual = offset + base actual_swapped = base + offset actual_apply = offset._apply(base) try: assert actual == expected assert actual_swapped =...
""" Tests for the following offsets: - BMonthBegin - BMonthEnd """ from __future__ import annotations from datetime import datetime import pytest import pandas as pd from pandas.tests.tseries.offsets.common import ( assert_is_on_offset, assert_offset_equal, ) from pandas.tseries.offsets import ( BMonthB...
""" Tests for the following offsets: - BYearBegin - BYearEnd """ from __future__ import annotations from datetime import datetime import pytest from pandas.tests.tseries.offsets.common import ( assert_is_on_offset, assert_offset_equal, ) from pandas.tseries.offsets import ( BYearBegin, BYearEnd, ) ...
""" Tests for the following offsets: - QuarterBegin - QuarterEnd """ from __future__ import annotations from datetime import datetime import pytest import pandas._testing as tm from pandas.tests.tseries.offsets.common import ( assert_is_on_offset, assert_offset_equal, ) from pandas.tseries.offsets import ( ...
from datetime import datetime from dateutil.tz.tz import tzlocal import pytest from pandas._libs.tslibs import ( OutOfBoundsDatetime, Timestamp, ) from pandas.compat import ( IS64, is_platform_windows, ) from pandas.tseries.offsets import ( FY5253, BDay, BMonthBegin, BMonthEnd, BQ...
""" Tests for the following offsets: - Easter """ from __future__ import annotations from datetime import datetime import pytest from pandas.tests.tseries.offsets.common import assert_offset_equal from pandas.tseries.offsets import Easter class TestEaster: @pytest.mark.parametrize( "offset,date,expect...
""" Tests for the following offsets: - BQuarterBegin - BQuarterEnd """ from __future__ import annotations from datetime import datetime import pytest import pandas._testing as tm from pandas.tests.tseries.offsets.common import ( assert_is_on_offset, assert_offset_equal, ) from pandas.tseries.offsets import ...
""" Tests for offsets.CustomBusinessDay / CDay """ from datetime import ( datetime, timedelta, ) import numpy as np import pytest from pandas._libs.tslibs.offsets import CDay from pandas import ( _testing as tm, read_pickle, ) from pandas.tests.tseries.offsets.common import assert_offset_equal from ...
""" Tests for offsets.Tick and subclasses """ from datetime import ( datetime, timedelta, ) from hypothesis import ( assume, example, given, ) import numpy as np import pytest from pandas._libs.tslibs.offsets import delta_to_tick from pandas.errors import OutOfBoundsTimedelta from pandas import (...
""" Tests for statistical reductions of 2nd moment or higher: var, skew, kurt, ... """ import inspect import numpy as np import pytest import pandas as pd from pandas import ( DataFrame, Series, date_range, ) import pandas._testing as tm class TestDatetimeLikeStatReductions: @pytest.mark.parametrize...
""" Tests for reductions where we want to test for matching behavior across Array, Index, Series, and DataFrame methods. """
""" This file contains a minimal set of tests for compliance with the extension array interface test suite, and should contain no other tests. The test suite for the full functionality of the array is located in `pandas/tests/arrays/`. The tests in this file are inherited from the BaseExtensionTests, and only minimal ...
""" This file contains a minimal set of tests for compliance with the extension array interface test suite, and should contain no other tests. The test suite for the full functionality of the array is located in `pandas/tests/arrays/`. The tests in this file are inherited from the BaseExtensionTests, and only minimal ...
""" This file contains a minimal set of tests for compliance with the extension array interface test suite, and should contain no other tests. The test suite for the full functionality of the array is located in `pandas/tests/arrays/`. The tests in this file are inherited from the BaseExtensionTests, and only minimal ...
""" This file contains a minimal set of tests for compliance with the extension array interface test suite, and should contain no other tests. The test suite for the full functionality of the array is located in `pandas/tests/arrays/`. The tests in this file are inherited from the BaseExtensionTests, and only minimal ...
""" Tests for behavior if an author does *not* implement EA methods. """ import numpy as np import pytest from pandas.core.arrays import ExtensionArray class MyEA(ExtensionArray): def __init__(self, values) -> None: self._values = values @pytest.fixture def data(): arr = np.arange(10) return My...
""" This file contains a minimal set of tests for compliance with the extension array interface test suite, and should contain no other tests. The test suite for the full functionality of the array is located in `pandas/tests/arrays/`. The tests in this file are inherited from the BaseExtensionTests, and only minimal ...
from pandas.tests.extension.date.array import ( DateArray, DateDtype, ) __all__ = ["DateArray", "DateDtype"]
from __future__ import annotations import datetime as dt from typing import ( TYPE_CHECKING, Any, cast, ) import numpy as np from pandas.core.dtypes.dtypes import register_extension_dtype from pandas.api.extensions import ( ExtensionArray, ExtensionDtype, ) from pandas.api.types import pandas_dt...
import pytest import pandas as pd from pandas.tests.extension.list.array import ( ListArray, ListDtype, make_data, ) @pytest.fixture def dtype(): return ListDtype() @pytest.fixture def data(): """Length-100 ListArray for semantics test.""" data = make_data() while len(data[0]) == len(d...
from pandas.tests.extension.list.array import ( ListArray, ListDtype, make_data, ) __all__ = ["ListArray", "ListDtype", "make_data"]
""" Test extension array for storing nested data in a pandas container. The ListArray stores an ndarray of lists. """ from __future__ import annotations import numbers import string from typing import TYPE_CHECKING import numpy as np from pandas.core.dtypes.base import ExtensionDtype import pandas as pd from panda...
""" This file contains a minimal set of tests for compliance with the extension array interface test suite, and should contain no other tests. The test suite for the full functionality of the array is located in `pandas/tests/arrays/`. The tests in this file are inherited from the BaseExtensionTests, and only minimal ...
import numpy as np import pytest from pandas.core.dtypes import dtypes from pandas.core.dtypes.common import is_extension_array_dtype import pandas as pd import pandas._testing as tm from pandas.core.arrays import ExtensionArray class DummyDtype(dtypes.ExtensionDtype): pass class DummyArray(ExtensionArray): ...
""" This file contains a minimal set of tests for compliance with the extension array interface test suite, and should contain no other tests. The test suite for the full functionality of the array is located in `pandas/tests/arrays/`. The tests in this file are inherited from the BaseExtensionTests, and only minimal ...
import io import pytest import pandas as pd class BasePrintingTests: """Tests checking the formatting of your EA when printed.""" @pytest.mark.parametrize("size", ["big", "small"]) def test_array_repr(self, data, size): if size == "small": data = data[:5] else: d...
import numpy as np import pytest import pandas as pd import pandas._testing as tm class BaseMissingTests: def test_isna(self, data_missing): expected = np.array([True, False]) result = pd.isna(data_missing) tm.assert_numpy_array_equal(result, expected) result = pd.Series(data_mi...
from __future__ import annotations from typing import final import numpy as np import pytest from pandas.core.dtypes.common import is_string_dtype import pandas as pd import pandas._testing as tm from pandas.core import ops class BaseOpsUtil: series_scalar_exc: type[Exception] | None = TypeError frame_sca...
import warnings import numpy as np import pytest from pandas.compat.numpy import np_version_gt2 from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike from pandas.core.dtypes.common import is_extension_array_dtype from pandas.core.dtypes.dtypes import ExtensionDtype import pandas as pd import p...
from io import StringIO import numpy as np import pytest import pandas as pd import pandas._testing as tm from pandas.core.arrays import ExtensionArray class BaseParsingTests: @pytest.mark.parametrize("engine", ["c", "python"]) def test_EA_types(self, engine, data, request): if isinstance(data.dtype...
import numpy as np import pytest import pandas as pd import pandas._testing as tm class BaseSetitemTests: @pytest.fixture( params=[ lambda x: x.index, lambda x: list(x.index), lambda x: slice(None), lambda x: slice(0, len(x)), lambda x: range(le...
import numpy as np import pytest import pandas as pd import pandas._testing as tm class BaseGetitemTests: """Tests for ExtensionArray.__getitem__.""" def test_iloc_series(self, data): ser = pd.Series(data) result = ser.iloc[:4] expected = pd.Series(data[:4]) tm.assert_series_...
import numpy as np import pytest import pandas.util._test_decorators as td import pandas as pd import pandas._testing as tm from pandas.core.internals.blocks import NumpyBlock class BaseCastingTests: """Casting to and from ExtensionDtypes""" def test_astype_object_series(self, all_data): ser = pd.S...
import numpy as np import pytest import pandas as pd import pandas._testing as tm from pandas.api.types import ( infer_dtype, is_object_dtype, is_string_dtype, ) class BaseDtypeTests: """Base class for ExtensionDtype classes""" def test_name(self, dtype): assert isinstance(dtype.name, st...
class BaseExtensionTests: pass
import re import pytest from pandas.core.dtypes.common import ( is_bool_dtype, is_numeric_dtype, is_object_dtype, is_string_dtype, ) import pandas as pd import pandas._testing as tm @pytest.mark.filterwarnings( "ignore:The default of observed=False is deprecated:FutureWarning" ) class BaseGroup...
import pytest import pandas as pd import pandas._testing as tm class BaseAccumulateTests: """ Accumulation specific tests. Generally these only make sense for numeric/boolean operations. """ def _supports_accumulation(self, ser: pd.Series, op_name: str) -> bool: # Do we expect this accum...
import numpy as np import pytest import pandas as pd import pandas._testing as tm from pandas.api.extensions import ExtensionArray from pandas.core.internals.blocks import EABackedBlock class BaseConstructorsTests: def test_from_sequence_from_cls(self, data): result = type(data)._from_sequence(data, dtyp...
""" Base test suite for extension arrays. These tests are intended for third-party libraries to subclass to validate that their extension arrays and dtypes satisfy the interface. Moving or renaming the tests should not be done lightly. Libraries are expected to implement a few pytest fixtures to provide data for the ...
""" Tests for 2D compatibility. """ import numpy as np import pytest from pandas._libs.missing import is_matching_na from pandas.core.dtypes.common import ( is_bool_dtype, is_integer_dtype, ) import pandas as pd import pandas._testing as tm from pandas.core.arrays.integer import NUMPY_INT_TO_DTYPE class Di...
""" Tests for Indexes backed by arbitrary ExtensionArrays. """ import pandas as pd class BaseIndexTests: """Tests for Index object backed by an ExtensionArray""" def test_index_from_array(self, data): idx = pd.Index(data) assert data.dtype == idx.dtype def test_index_from_listlike_with_d...
from typing import final import pytest import pandas as pd import pandas._testing as tm from pandas.api.types import is_numeric_dtype class BaseReduceTests: """ Reduction specific tests. Generally these only make sense for numeric/boolean operations. """ def _supports_reduction(self, ser: pd.Se...
import itertools import numpy as np import pytest import pandas as pd import pandas._testing as tm from pandas.api.extensions import ExtensionArray from pandas.core.internals.blocks import EABackedBlock class BaseReshapingTests: """Tests for reshaping and concatenation.""" @pytest.mark.parametrize("in_fram...
from pandas.tests.extension.array_with_attr.array import ( FloatAttrArray, FloatAttrDtype, ) __all__ = ["FloatAttrArray", "FloatAttrDtype"]
""" Test extension array that has custom attribute information (not stored on the dtype). """ from __future__ import annotations import numbers from typing import TYPE_CHECKING import numpy as np from pandas.core.dtypes.base import ExtensionDtype import pandas as pd from pandas.core.arrays import ExtensionArray i...
import numpy as np import pandas as pd import pandas._testing as tm from pandas.tests.extension.array_with_attr import FloatAttrArray def test_concat_with_all_na(): # https://github.com/pandas-dev/pandas/pull/47762 # ensure that attribute of the column array is preserved (when it gets # preserved in rein...
import operator import pytest from pandas._config.config import _get_option from pandas import ( Series, options, ) @pytest.fixture def dtype(): """A fixture providing the ExtensionDtype to validate.""" raise NotImplementedError @pytest.fixture def data(): """ Length-100 array for this ty...
from pandas.tests.extension.decimal.array import ( DecimalArray, DecimalDtype, make_data, to_decimal, ) __all__ = ["DecimalArray", "DecimalDtype", "to_decimal", "make_data"]