コード例 #1
0
    def test_today(self):
        ts_from_string = Timestamp('today')
        ts_from_method = Timestamp.today()
        ts_datetime = datetime.today()

        ts_from_string_tz = Timestamp('today', tz='US/Eastern')
        ts_from_method_tz = Timestamp.today(tz='US/Eastern')

        # Check that the delta between the times is less than 1s (arbitrarily
        # small)
        delta = Timedelta(seconds=1)
        assert abs(ts_from_method - ts_from_string) < delta
        assert abs(ts_datetime - ts_from_method) < delta
        assert abs(ts_from_method_tz - ts_from_string_tz) < delta
        assert (abs(ts_from_string_tz.tz_localize(None) -
                    ts_from_method_tz.tz_localize(None)) < delta)
コード例 #2
0
    def test_today(self):
        ts_from_string = Timestamp('today')
        ts_from_method = Timestamp.today()
        ts_datetime = datetime.today()

        ts_from_string_tz = Timestamp('today', tz='US/Eastern')
        ts_from_method_tz = Timestamp.today(tz='US/Eastern')

        # Check that the delta between the times is less than 1s (arbitrarily
        # small)
        delta = Timedelta(seconds=1)
        assert abs(ts_from_method - ts_from_string) < delta
        assert abs(ts_datetime - ts_from_method) < delta
        assert abs(ts_from_method_tz - ts_from_string_tz) < delta
        assert (abs(
            ts_from_string_tz.tz_localize(None) -
            ts_from_method_tz.tz_localize(None)) < delta)
コード例 #3
0
ファイル: preprocess.py プロジェクト: lukegre/dataBrewery
def _netcdf_add_brew_hist(xds, msg, key='history'):
    from pandas import Timestamp

    now = Timestamp.today().strftime('%Y-%m-%dT%H:%M')
    prefix = f'\n[DataBrewery@{now}] '
    msg = prefix + msg
    if key not in xds.attrs:
        xds.attrs[key] = msg
    elif xds.attrs[key] == '':
        xds.attrs[key] = msg
    else:
        xds.attrs[key] += '; ' + msg

    return xds
コード例 #4
0
    def next_month(self):
        # additionally, will return True if the viewed month
        # is the current month, and False otherwise

        this_month = Timestamp.today().replace(day=1).floor('D')
        month = DateOffset(months=1)
        
        cur_view = Timestamp(config.year,config.month,1)
        next_view = cur_view + month

        config.year = next_view.year
        config.month = next_view.month
        self.redraw_cal()

        return (next_view == this_month)
コード例 #5
0
ファイル: test_data.py プロジェクト: ajcr/pandas
    def setUpClass(cls):
        super(TestYahooOptions, cls).setUpClass()
        _skip_if_no_lxml()

        # aapl has monthlies
        cls.aapl = web.Options('aapl', 'yahoo')
        d = (Timestamp.today() + pd.offsets.MonthBegin(1)).normalize()
        cls.year = d.year
        cls.month = d.month
        cls.expiry = d
        cls.expiry2 = d + pd.offsets.MonthBegin(1)
        cls.dirpath = tm.get_data_path()
        cls.html1 = os.path.join(cls.dirpath, 'yahoo_options1.html')
        cls.html2 = os.path.join(cls.dirpath, 'yahoo_options2.html')
        cls.html3 = os.path.join(cls.dirpath, 'yahoo_options3.html') #Empty table GH#22
        cls.data1 = cls.aapl._option_frames_from_url(cls.html1)['puts']
コード例 #6
0
ファイル: test_data.py プロジェクト: Sakampavankumar/pandas-1
    def setUpClass(cls):
        super(TestYahooOptions, cls).setUpClass()
        _skip_if_no_lxml()

        # aapl has monthlies
        cls.aapl = web.Options('aapl', 'yahoo')
        d = (Timestamp.today() + pd.offsets.MonthBegin(1)).normalize()
        cls.year = d.year
        cls.month = d.month
        cls.expiry = d
        cls.expiry2 = d + pd.offsets.MonthBegin(1)
        cls.dirpath = tm.get_data_path()
        cls.html1 = os.path.join(cls.dirpath, 'yahoo_options1.html')
        cls.html2 = os.path.join(cls.dirpath, 'yahoo_options2.html')
        cls.html3 = os.path.join(cls.dirpath,
                                 'yahoo_options3.html')  #Empty table GH#22
        cls.data1 = cls.aapl._option_frames_from_url(cls.html1)['puts']
コード例 #7
0
    def _add_history(self, xds):
        from pandas import Timestamp

        version = ".{__version__}" if __version__ else ""
        now = Timestamp.today().strftime("%Y-%m-%dT%H:%M")
        prefix = f"[OceanDataTools{version}@{now}] "
        msg = prefix + self.msg
        if "history" not in xds.attrs:
            xds.attrs["history"] = msg
        elif xds.attrs["history"] == "":
            xds.attrs["history"] = msg
        else:
            hist = xds.attrs["history"].split(";")
            hist = [h.strip() for h in hist]
            xds.attrs["history"] = "; ".join(hist + [msg])

        return xds
コード例 #8
0
    def __init__(self, date):
        self.date = date
        self.cur_mood = config.visible_cal
        self.rate = config.mood_data.get_rate(self.cur_mood, self.date)
        super().__init__(text=str(self.date.day))

        today = Timestamp.today().floor('D')
        if self.date > today:
            self.disabled = True

        if isnull(self.rate): return

        if config.mood_data.is_negative(self.cur_mood):
            self.rate = 10 - self.rate

        self.background_color = self.rate_to_color()
        self.color = [0.976, 0.969, 0.929, 1]
コード例 #9
0
def init():

    global mood_data
    # can cange file locations here:
    mood_data = Mood("data/rates.csv", "data/weights.json")

    # indicates which mood is viewed in the calendar widget
    global visible_cal
    visible_cal = 'overall'  # can change default here

    # indicate which month is currently being viewed:
    date = Timestamp.today()
    global year
    year = date.year

    global month
    month = date.month
コード例 #10
0
    def test_class_ops_dateutil(self):
        def compare(x, y):
            assert (int(np.round(Timestamp(x).value / 1e9)) == int(
                np.round(Timestamp(y).value / 1e9)))

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now('UTC'), datetime.now(tzutc()))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        compare(Timestamp.utcfromtimestamp(current_time),
                datetime.utcfromtimestamp(current_time))
        compare(Timestamp.fromtimestamp(current_time),
                datetime.fromtimestamp(current_time))

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(Timestamp.combine(date_component, time_component),
                datetime.combine(date_component, time_component))
コード例 #11
0
    def test_class_ops_dateutil(self):
        def compare(x, y):
            assert (int(np.round(Timestamp(x).value / 1e9)) ==
                    int(np.round(Timestamp(y).value / 1e9)))

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now('UTC'), datetime.now(tzutc()))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        compare(Timestamp.utcfromtimestamp(current_time),
                datetime.utcfromtimestamp(current_time))
        compare(Timestamp.fromtimestamp(current_time),
                datetime.fromtimestamp(current_time))

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(Timestamp.combine(date_component, time_component),
                datetime.combine(date_component, time_component))
コード例 #12
0
    def test_class_ops_pytz(self):
        def compare(x, y):
            assert int((Timestamp(x).value - Timestamp(y).value) / 1e9) == 0

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now("UTC"), datetime.now(timezone("UTC")))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        compare(
            Timestamp.utcfromtimestamp(current_time),
            datetime.utcfromtimestamp(current_time),
        )
        compare(Timestamp.fromtimestamp(current_time),
                datetime.fromtimestamp(current_time))

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(
            Timestamp.combine(date_component, time_component),
            datetime.combine(date_component, time_component),
        )
コード例 #13
0
    def counts_data(self):

        ref_date = Timestamp.today().strftime('%Y-%m-%d')

        if ref_date in storage.keys():
            return storage[ref_date]['counts'].copy()

        conn = create_engine(self.connection_string)
        cdata = read_sql('SELECT * FROM app__scholar_attrition__counts', conn)
        sdata = read_sql('SELECT * FROM app__scholar_attrition__similarities', conn)
        sdata = sdata.set_index(['school_name_row', 'grade_row', 'school_name_col', 'grade_col'])['similarity'].\
            unstack(['school_name_col', 'grade_col'])
        sdata.index.names = [r.replace('_row', '') for r in sdata.index.names]
        sdata.columns.names = [c.replace('_col', '') for c in sdata.columns.names]
        conn.dispose()

        for k in storage.keys():
            _ = storage.pop(k)
        storage[ref_date] = {}
        storage[ref_date]['counts'] = cdata.copy()
        storage[ref_date]['similarities'] = sdata.copy()

        return cdata
コード例 #14
0
    def test_class_ops_pytz(self):
        def compare(x, y):
            assert int((Timestamp(x).value - Timestamp(y).value) / 1e9) == 0

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now("UTC"), datetime.now(timezone("UTC")))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        msg = "timezone-aware Timestamp with UTC"
        with tm.assert_produces_warning(FutureWarning, match=msg):
            # GH#22451
            ts_utc = Timestamp.utcfromtimestamp(current_time)
        compare(
            ts_utc,
            datetime.utcfromtimestamp(current_time),
        )
        compare(
            Timestamp.fromtimestamp(current_time), datetime.fromtimestamp(current_time)
        )
        compare(
            # Support tz kwarg in Timestamp.fromtimestamp
            Timestamp.fromtimestamp(current_time, "UTC"),
            datetime.fromtimestamp(current_time, utc),
        )
        compare(
            # Support tz kwarg in Timestamp.fromtimestamp
            Timestamp.fromtimestamp(current_time, tz="UTC"),
            datetime.fromtimestamp(current_time, utc),
        )

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(
            Timestamp.combine(date_component, time_component),
            datetime.combine(date_component, time_component),
        )
コード例 #15
0
from pandas import Timestamp
from pandas.core.tools.datetimes import DatetimeScalar
from typing import Union
from datetime import date, datetime
from numpy.core import datetime64

Date = Union[DatetimeScalar, Timestamp, date, datetime64]
TODAY = Timestamp.today().date()
fin_data['Home Department Description'] =fin_data.groupby(['Supervisor ID','EEOC Job Classification','Job Title Description'])['Home Department Description'].bfill().ffill()


# In[61]:


# Column that indicates whether this employee is still in Family Services or has been terminated(left)
fin_data['Left'] = np.where(fin_data['Termination Date'].notnull(), 1, 0)


# In[62]:


# Fill null with today's timestamp
from pandas import Timestamp
fin_data['Termination Date'] = fin_data['Termination Date'].fillna(Timestamp.today())


# In[63]:


# Years of service in timedelta
fin_data['timedelta'] = fin_data['Termination Date'] - fin_data['Hire Date']


# In[64]:


# Converting Years of service in timedelta into number of years
fin_data['timedelta'] = (fin_data['timedelta'].dt.days)/365
コード例 #17
0
ファイル: termtime.py プロジェクト: tgadf/utils
 def isFinished(self):
     retval = Timestamp.today() > self.endTime
     if retval is True:
         print("   ====> Terminate Time [{0}] Is Reached <====".format(
             self.endTime))
     return retval
コード例 #18
0
    def update_plot(self):

        today = Timestamp.today().strftime('%Y-%m-%d')
        today_date = to_datetime(today)

        df = self.counts_data
        weights = self.similarities_data.xs(self.school, level='school_name', axis=1)
        df_all = df[df['school_name'].eq(self.school)]
        present_academic_year = df['academic_year'].unique()[0]

        tooltips = '''
        <div style="font-size: 12px;">
        <span style="font-weight: bold;">@school_name</span> (@school_type, @school_age years old)<br>
        Grade @grade enrollment, as of @reference_date_string<br>
        <br>
        <span style="font-weight: bold;">Attrition</span>: @exit_count_present_cumm (@exit_percent_present_cumm{'0.0%'} change from October 1)<br>
        <span style="font-weight: bold;">Backfill</span>: @enter_count_present_cumm (@enter_percent_present_cumm{'0.0%'} change from October 1)<br>
        <span style="font-weight: bold;">Current total enrollment</span>: @total_enrollment
        </div>
        '''

        ticker_ref = DataFrame({'month': date_range('2014-10-01', '2015-06-01', freq='MS')})
        ticker_ref['marker'] = ticker_ref['month']
        ticker_ref['month'] = ticker_ref['month'].apply(lambda x: x.strftime('%B'))
        ticker_ref = ticker_ref.set_index('marker')['month'].to_dict()

        x_range1d = Range1d(-0.05, 290.0)
        y_index = max(
            -df_all['exit_percent_present_cumm'].min(),
            df_all['enter_percent_present_cumm'].max(),
            -df_all['exit_percent_past_cumm'].min(),
            df_all['enter_percent_past_cumm'].max()
        )
        y_range1d = Range1d(-y_index - 0.005, y_index + 0.005)
        plots = []
        focus_cols = ['enter_percent_present_cumm', 'exit_percent_present_cumm']
        unique_grades = sorted(df_all['grade'].unique().astype('int'))
        for grade in unique_grades:
            grade_weight = weights[grade]
            benchmark_df = DataFrame(columns=focus_cols)
            df_copy = df[df['academic_year'].eq(present_academic_year)].copy().set_index(['school_name', 'grade'])

            for rid, label in sorted(ticker_ref.items(), reverse=True):
                df_copy = df_copy[df_copy['reference_date'].le(rid)]
                df_ave = df_copy.groupby(level=['school_name', 'grade'])[focus_cols].tail(1).\
                    mul(grade_weight, axis=0).sum() / grade_weight.sum()
                df_ave.name = label
                benchmark_df = benchmark_df.append(df_ave)
            benchmark_df = benchmark_df.reset_index()
            benchmark_df['reference_date'] = benchmark_df['index'].map({y: x for x, y in ticker_ref.items()})
            benchmark_df['reference_id'] = benchmark_df['reference_date'].apply(lambda x: x.toordinal()) - \
                df_all['reference_date'].min().toordinal()

            source_df = df_all[df_all['grade'].eq(grade)]
            source_df_rev = source_df.sort_values('reference_id', ascending=False)
            source_df_trunc = source_df.loc[source_df['reference_date'].le(today_date), :]
            source = ColumnDataSource(source_df)
            source_trunc = ColumnDataSource(source_df_trunc)
            patch_source = ColumnDataSource(dict(
                x_past=source_df['reference_id'].tolist() + source_df_rev['reference_id'].tolist(),
                y_past=source_df['enter_percent_past_cumm'].tolist() + source_df_rev['exit_percent_past_cumm'].tolist()
            ))

            plot1 = Plot(
                x_range=x_range1d,
                y_range=y_range1d,
                min_border_bottom=5,
                min_border_top=10,
                min_border_right=10,
                plot_width=700,
                plot_height=150,
                title=None,
                title_text_font_size='0pt',
                title_text_color='grey',
                outline_line_alpha=0.0)

            plot1.add_layout(
                LinearAxis(
                    axis_label='Grade ' + str(grade), axis_label_text_font_size='9pt', minor_tick_line_alpha=0.0,
                    axis_label_text_color='grey',
                    axis_line_alpha=0.1, major_tick_line_alpha=0.1, major_label_text_color='grey',
                    major_label_text_font_size='7pt', formatter=NumeralTickFormatter(format='0%')
                ), 'left')

            patch = Patch(x='x_past', y='y_past', fill_color='#AFAFAD', fill_alpha=0.25, line_alpha=0.0)
            plot1.add_glyph(patch_source, patch)

            line1 = Line(
                x='reference_id', y='enter_percent_present_cumm', line_width=2, line_color='#f7910b', line_alpha=1.0)
            plot1.add_glyph(source_trunc, line1)

            line2 = Line(
                x='reference_id', y='exit_percent_present_cumm', line_width=2, line_color='#f7910b', line_alpha=1.0)
            plot1.add_glyph(source_trunc, line2)

            line_h = Line(x='reference_id', y=0, line_width=1, line_color='black', line_alpha=0.1)
            line_renderer = GlyphRenderer(data_source=source, glyph=line_h, name='line')
            plot1.add_glyph(source, line_h)

            for ind, series in benchmark_df.iterrows():
                x = series['reference_id']
                y_enter = series['enter_percent_present_cumm']
                y_exit = series['exit_percent_present_cumm']
                label = series['index']

                line = Segment(x0=x, x1=x, y0=-y_index, y1=y_index, line_width=1, line_color='#165788', line_alpha=0.1)
                plot1.add_glyph(line)

                linec1 = Segment(
                    x0=x - 3, x1=x + 3, y0=y_enter, y1=y_enter, line_width=1, line_color='#ed2939', line_alpha=1.0)
                plot1.add_glyph(linec1)

                linec2 = Segment(
                    x0=x - 3, x1=x + 3, y0=y_exit, y1=y_exit, line_width=1, line_color='#ed2939', line_alpha=1.0)
                plot1.add_glyph(linec2)

                text = Text(x=x+3, y=-y_index, text=[label], text_font_size='8pt', text_color='grey', text_alpha=0.5)
                plot1.add_glyph(text)

            hover_tool = HoverTool(
                plot=plot1, renderers=[line_renderer], tooltips=tooltips, always_active=False, mode='vline',
                point_policy='follow_mouse', line_policy='prev')
            crosshair_tool = CrosshairTool(plot=plot1, dimensions=['height'])
            zoom_tool = BoxZoomTool(plot=plot1, dimensions=['width'])
            reset_tool = ResetTool(plot=plot1)
            save_tool = PreviewSaveTool(plot=plot1)
            pan_tool = PanTool(plot=plot1, dimensions=['width'])
            help_tool = HelpTool(plot=plot1, help_tooltip='App help page', redirect='http://data.successacademies.org/blog/')
            plot1.tools.extend([hover_tool, zoom_tool, pan_tool, reset_tool, save_tool, help_tool, crosshair_tool])
            plot1.renderers.extend([line_renderer])
            plots.append([plot1])

        self.plot.children = plots
コード例 #19
0
    authority = randomCompliantString(4)

    if verbosity > 1:
        print('No authority given, random generated authority is "{}" '.format(
            authority))

if number is None:
    number = randomCompliantString(5)
    # number = str(randint(1, 99999)).zfill(5)

    if verbosity > 1:
        print(
            'No number given, random generated number is "{}" '.format(number))

if birth_year is None and birth_date is None:
    year = Timestamp.today().year
    birth_year = year - randint(19, 99)

    if verbosity > 1:
        print(
            'No birth_year and birth_date given, random generated birth_year is "{}" '
            .format(birth_year))

if birth_month is None and birth_date is None:
    birth_month = randint(1, 12)

    if verbosity > 1:
        print(
            'No birth_month and birth_date given, random generated birth_month is "{}" '
            .format(birth_month))
コード例 #20
0
 def get(self):
     return Timestamp.today().round(self.round)
コード例 #21
0
    def _download(self,
                  start=None,
                  end=None,
                  inseason=False,
                  vars='ALL',
                  stns=260,
                  interval='daily'):
        # Import the necessary modules (optional and not included in the
        # installation of pastas).
        try:
            import requests
        except ImportError:
            raise ImportError('The module requests could not be imported. '
                              'Please install through:'
                              '>>> pip install requests'
                              'or:'
                              '>>> conda install requests')

        from io import StringIO

        if start is None:
            start = Timestamp(Timestamp.today().year, 1, 1)
        else:
            start = to_datetime(start)
        if end is None:
            end = Timestamp.today()
        else:
            end = to_datetime(end)

        if not isinstance(vars, list):
            if isinstance(vars, ndarray):
                vars = list(vars)
            else:
                vars = [vars]

        if not isinstance(stns, list):
            if isinstance(stns, ndarray):
                stns = list(stns)
            else:
                stns = [stns]
        # convert possible integers to string
        stns = [str(i) for i in stns]

        if interval.startswith('hour') and 'RD' in vars:
            message = 'Interval can not be hourly for rainfall-stations'
            raise (ValueError(message))
        if 'RD' in vars and len(vars) > 1:
            message = 'Only daily precipitation can be downloaded from ' \
                      'rainfall-stations'
            raise (ValueError(message))

        if interval.startswith('hour'):
            # hourly data from meteorological stations
            url = 'http://projects.knmi.nl/klimatologie/uurgegevens/getdata_uur.cgi'
        elif 'RD' in vars:
            # daily data from rainfall-stations
            url = 'http://projects.knmi.nl/klimatologie/monv/reeksen/getdata_rr.cgi'
        else:
            # daily data from meteorological stations
            url = 'http://projects.knmi.nl/klimatologie/daggegevens/getdata_dag.cgi'

        vars = ":".join(vars)
        stns = ":".join(stns)
        if interval.startswith('hour'):
            data = {
                'start': start.strftime('%Y%m%d') + '01',
                'end': end.strftime('%Y%m%d') + '24',
                'vars': vars,
                'stns': stns,
            }
        else:
            data = {
                'start': start.strftime('%Y%m%d'),
                'end': end.strftime('%Y%m%d'),
                'inseason': str(int(inseason)),
                'vars': vars,
                'stns': stns,
            }
        result = requests.get(url, params=data).text

        f = StringIO(result)
        self.readdata(f)
コード例 #22
0
from bokeh.models import Plot, ColumnDataSource
from bokeh.models.glyphs import Rect
from bokeh.models.axes import LinearAxis, CategoricalAxis
from bokeh.models.ranges import FactorRange, DataRange1d
from bokeh.models.widgets.tables import DataTable, TableColumn

API_KEY = '<INSERT VALID API KEY HERE>'
ARTICLE_URI = 'http://api.nytimes.com/svc/search/v2/articlesearch.json'
SHARED_URI = 'http://api.nytimes.com/svc/mostpopular/v2/mostshared/{section}/30.json'
EMAILED_URI = 'http://api.nytimes.com/svc/mostpopular/v2/mostemailed/{section}/30.json'
VIEWED_URI = 'http://api.nytimes.com/svc/mostpopular/v2/mostviewed/{section}/30.json'

curstate().autoadd = False

# set up metadata for API query
today = Timestamp.today().strftime('%Y%m%d')
today_minus_thirty = (Timestamp.today().date() -
                      to_timedelta('30 days')).strftime('%Y%m%d')
page = 0

query_params = {
    'q': '"climate change"',
    'begin_date': today_minus_thirty,
    'end_date': today,
    'sort': 'newest',
    'hl': True,
    'page': page,
    'api-key': API_KEY
}

# pull all data for specified time period