class TimestampProperties: _tzs = [None, pytz.timezone('Europe/Amsterdam'), pytz.UTC, dateutil.tz.tzutc()] _freqs = [None, 'B'] params = [_tzs, _freqs] param_names = ['tz', 'freq'] def setup(self, tz, freq): self.ts = Timestamp('2017-08-25 08:16:14', tzinfo=tz, freq=freq) def time_tz(self, tz, freq): self.ts.tz def time_dayofweek(self, tz, freq): self.ts.dayofweek def time_weekday_name(self, tz, freq): self.ts.day_name def time_dayofyear(self, tz, freq): self.ts.dayofyear def time_week(self, tz, freq): self.ts.week def time_quarter(self, tz, freq): self.ts.quarter def time_days_in_month(self, tz, freq): self.ts.days_in_month def time_freqstr(self, tz, freq): self.ts.freqstr def time_is_month_start(self, tz, freq): self.ts.is_month_start def time_is_month_end(self, tz, freq): self.ts.is_month_end def time_is_quarter_start(self, tz, freq): self.ts.is_quarter_start def time_is_quarter_end(self, tz, freq): self.ts.is_quarter_end def time_is_year_start(self, tz, freq): self.ts.is_year_start def time_is_year_end(self, tz, freq): self.ts.is_year_end def time_is_leap_year(self, tz, freq): self.ts.is_leap_year def time_microsecond(self, tz, freq): self.ts.microsecond def time_month_name(self, tz, freq): self.ts.month_name()
class TimestampProperties: _tzs = [None, pytz.timezone("Europe/Amsterdam"), pytz.UTC, dateutil.tz.tzutc()] _freqs = [None, "B"] params = [_tzs, _freqs] param_names = ["tz", "freq"] def setup(self, tz, freq): self.ts = Timestamp("2017-08-25 08:16:14", tzinfo=tz, freq=freq) def time_tz(self, tz, freq): self.ts.tz def time_dayofweek(self, tz, freq): self.ts.dayofweek def time_weekday_name(self, tz, freq): self.ts.day_name def time_dayofyear(self, tz, freq): self.ts.dayofyear def time_week(self, tz, freq): self.ts.week def time_quarter(self, tz, freq): self.ts.quarter def time_days_in_month(self, tz, freq): self.ts.days_in_month def time_freqstr(self, tz, freq): self.ts.freqstr def time_is_month_start(self, tz, freq): self.ts.is_month_start def time_is_month_end(self, tz, freq): self.ts.is_month_end def time_is_quarter_start(self, tz, freq): self.ts.is_quarter_start def time_is_quarter_end(self, tz, freq): self.ts.is_quarter_end def time_is_year_start(self, tz, freq): self.ts.is_year_start def time_is_year_end(self, tz, freq): self.ts.is_year_end def time_is_leap_year(self, tz, freq): self.ts.is_leap_year def time_microsecond(self, tz, freq): self.ts.microsecond def time_month_name(self, tz, freq): self.ts.month_name()
def test_names(self, data, time_locale): # GH 17354 # Test .weekday_name, .day_name(), .month_name with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): assert data.weekday_name == 'Monday' if time_locale is None: expected_day = 'Monday' expected_month = 'August' else: with tm.set_locale(time_locale, locale.LC_TIME): expected_day = calendar.day_name[0].capitalize() expected_month = calendar.month_name[8].capitalize() result_day = data.day_name(time_locale) result_month = data.month_name(time_locale) # Work around https://github.com/pandas-dev/pandas/issues/22342 # different normalizations if not PY2: expected_day = unicodedata.normalize("NFD", expected_day) expected_month = unicodedata.normalize("NFD", expected_month) result_day = unicodedata.normalize("NFD", result_day,) result_month = unicodedata.normalize("NFD", result_month) assert result_day == expected_day assert result_month == expected_month # Test NaT nan_ts = Timestamp(NaT) assert np.isnan(nan_ts.day_name(time_locale)) assert np.isnan(nan_ts.month_name(time_locale))
def test_names(self, data, time_locale): # GH 17354 # Test .day_name(), .month_name if time_locale is None: expected_day = "Monday" expected_month = "August" else: with tm.set_locale(time_locale, locale.LC_TIME): expected_day = calendar.day_name[0].capitalize() expected_month = calendar.month_name[8].capitalize() result_day = data.day_name(time_locale) result_month = data.month_name(time_locale) # Work around https://github.com/pandas-dev/pandas/issues/22342 # different normalizations expected_day = unicodedata.normalize("NFD", expected_day) expected_month = unicodedata.normalize("NFD", expected_month) result_day = unicodedata.normalize("NFD", result_day) result_month = unicodedata.normalize("NFD", result_month) assert result_day == expected_day assert result_month == expected_month # Test NaT nan_ts = Timestamp(NaT) assert np.isnan(nan_ts.day_name(time_locale)) assert np.isnan(nan_ts.month_name(time_locale))
def test_names(self, data, time_locale): # GH 17354 # Test .weekday_name, .day_name(), .month_name with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): assert data.weekday_name == 'Monday' if time_locale is None: expected_day = 'Monday' expected_month = 'August' else: with tm.set_locale(time_locale, locale.LC_TIME): expected_day = calendar.day_name[0].capitalize() expected_month = calendar.month_name[8].capitalize() result_day = data.day_name(time_locale) result_month = data.month_name(time_locale) # Work around https://github.com/pandas-dev/pandas/issues/22342 # different normalizations expected_day = unicodedata.normalize("NFD", expected_day) expected_month = unicodedata.normalize("NFD", expected_month) result_day = unicodedata.normalize( "NFD", result_day, ) result_month = unicodedata.normalize("NFD", result_month) assert result_day == expected_day assert result_month == expected_month # Test NaT nan_ts = Timestamp(NaT) assert np.isnan(nan_ts.day_name(time_locale)) assert np.isnan(nan_ts.month_name(time_locale))
def test_names(self, data, time_locale): # GH 17354 # Test .weekday_name, .day_name(), .month_name with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): assert data.weekday_name == 'Monday' if time_locale is None: expected_day = 'Monday' expected_month = 'August' else: with tm.set_locale(time_locale, locale.LC_TIME): expected_day = calendar.day_name[0].capitalize() expected_month = calendar.month_name[8].capitalize() assert data.day_name(time_locale) == expected_day assert data.month_name(time_locale) == expected_month # Test NaT nan_ts = Timestamp(NaT) assert np.isnan(nan_ts.day_name(time_locale)) assert np.isnan(nan_ts.month_name(time_locale))
def test_month_name(self, dt64, ts): alt = Timestamp(dt64) assert ts.month_name() == alt.month_name()