Exemple #1
0
def test_getter_signal_type():
    """Test if attribute signal type is accessed correctly."""
    signal = Signal([1, 2, 3], 44100, fft_norm='none')
    npt.assert_string_equal(signal.signal_type, 'energy')

    signal = Signal([1, 2, 3], 44100, fft_norm='rms')
    npt.assert_string_equal(signal.signal_type, 'power')
def test_pandas_const_df_prepend():
    dta = longley.load_pandas().exog
    # regression test for #1025
    dta['UNEMP'] /= dta['UNEMP'].std()
    dta = tools.add_constant(dta, prepend=True)
    assert_string_equal('const', dta.columns[0])
    assert_equal(dta.var(0)[0], 0)
Exemple #3
0
def test_fetch_bed():
    import os

    filenames = [
        "chrom22_subsample20_maf0.10.bed",
        "chrom22_subsample20_maf0.10.fam",
        "chrom22_subsample20_maf0.10.bim",
    ]

    with limix.file_example(filenames) as filepaths:
        folder = os.path.dirname(filepaths[0])
        filepath = os.path.join(folder, "chrom22_subsample20_maf0.10")

        specs = [
            f"{filepath}",
            f"{filepath}:bed:row=candidate,col=sample",
            f"{filepath}:bed:col=sample",
            f"{filepath}:bed",
            f"{filepath}",
            f"{filepath}:",
            f"{filepath}::",
            f"{filepath}:bed:",
            f"{filepath}::row=candidate",
        ]

        for spec in specs:
            G = fetch("genotype", spec, verbose=False)

            assert_string_equal(G.name, "genotype")
            assert_array_equal(G["sample"], _samples)
            assert_equal(G.shape, (274, 49008))
            assert_array_equal(G.dims, ["sample", "candidate"])
Exemple #4
0
def test_filter_bad_waveforms():

    CC = dict()

    tr = obspy.Trace(header={'station': 'AAA',
                             'location': '00'})
    st = Stream(traces=tr)
    code = '%s.%s' % (tr.stats.station, tr.stats.location)
    CC[code] = 0.1

    tr = obspy.Trace(header={'station': 'BBB',
                             'location': '00'})
    st.append(tr)
    code = '%s.%s' % (tr.stats.station, tr.stats.location)
    CC[code] = 0.8

    tr = obspy.Trace(header={'station': 'CCC',
                             'location': '00'})
    st.append(tr)
    code = '%s.%s' % (tr.stats.station, tr.stats.location)
    CC[code] = -0.9

    tr = obspy.Trace(header={'station': 'DDD',
                             'location': '00'})
    st.append(tr)
    code = '%s.%s' % (tr.stats.station, tr.stats.location)
    CC[code] = 0.6

    st_filter = st.filter_bad_waveforms(CC=CC, CClim=0.6)

    npt.assert_equal(len(st_filter), 2)
    npt.assert_string_equal(str(st_filter[0].stats.station), 'BBB')
    npt.assert_string_equal(str(st_filter[1].stats.station), 'DDD')
Exemple #5
0
    def test_callback_terminates(self):
        # test that if the callback returns true, then the minimization halts
        bounds = [(0, 2), (0, 2)]
        expected_msg = 'callback function requested stop early by returning True'

        def callback_python_true(param, convergence=0.):
            return True

        result = differential_evolution(rosen,
                                        bounds,
                                        callback=callback_python_true)
        assert_string_equal(result.message, expected_msg)

        def callback_evaluates_true(param, convergence=0.):
            # DE should stop if bool(self.callback) is True
            return [10]

        result = differential_evolution(rosen,
                                        bounds,
                                        callback=callback_evaluates_true)
        assert_string_equal(result.message, expected_msg)

        def callback_evaluates_false(param, convergence=0.):
            return []

        result = differential_evolution(rosen,
                                        bounds,
                                        callback=callback_evaluates_false)
        assert result.success
Exemple #6
0
def test_copy():
    x = tt.dmatrix('x')
    data = np.random.rand(5, 5)
    y = x.copy(name='y')
    f = theano.function([x], y)
    assert_equal(f(data), data)
    assert_string_equal(y.name, 'y')
def test_pandas_const_df_prepend():
    dta = longley.load_pandas().exog
    # regression test for #1025
    dta["UNEMP"] /= dta["UNEMP"].std()
    dta = tools.add_constant(dta, prepend=True)
    assert_string_equal("const", dta.columns[0])
    assert_equal(dta.var(0)[0], 0)
Exemple #8
0
def test_filter_bad_waveforms():

    CC = dict()

    tr = obspy.Trace(header={'station': 'AAA', 'location': '00'})
    st = Stream(traces=tr)
    code = '%s.%s' % (tr.stats.station, tr.stats.location)
    CC[code] = 0.1

    tr = obspy.Trace(header={'station': 'BBB', 'location': '00'})
    st.append(tr)
    code = '%s.%s' % (tr.stats.station, tr.stats.location)
    CC[code] = 0.8

    tr = obspy.Trace(header={'station': 'CCC', 'location': '00'})
    st.append(tr)
    code = '%s.%s' % (tr.stats.station, tr.stats.location)
    CC[code] = -0.9

    tr = obspy.Trace(header={'station': 'DDD', 'location': '00'})
    st.append(tr)
    code = '%s.%s' % (tr.stats.station, tr.stats.location)
    CC[code] = 0.6

    st_filter = st.filter_bad_waveforms(CC=CC, CClim=0.6)

    npt.assert_equal(len(st_filter), 2)
    npt.assert_string_equal(str(st_filter[0].stats.station), 'BBB')
    npt.assert_string_equal(str(st_filter[1].stats.station), 'DDD')
Exemple #9
0
def test_copy():
    x = tt.dmatrix("x")
    data = np.random.rand(5, 5)
    y = x.copy(name="y")
    f = aesara.function([x], y)
    assert_equal(f(data), data)
    assert_string_equal(y.name, "y")
Exemple #10
0
    def test_build_from_halos(self):

        realization_fromhalos = Realization.from_halos(
            self.halos_cdm,
            self.lens_cosmo,
            self.kwargs_cdm,
            self.realization_cdm.apply_mass_sheet_correction,
            self.realization_cdm.rendering_classes,
        )

        for halo_1, halo_2 in zip(realization_fromhalos.halos,
                                  self.realization_cdm.halos):
            npt.assert_equal(halo_1.x, halo_2.x)
            npt.assert_equal(halo_1.y, halo_2.y)
            npt.assert_equal(halo_1.mass, halo_2.mass)
            npt.assert_equal(halo_1.r3d, halo_2.r3d)
            npt.assert_string_equal(halo_1.mdef, halo_2.mdef)
            npt.assert_equal(halo_1.z, halo_2.z)
            npt.assert_equal(halo_1.is_subhalo, halo_2.is_subhalo)
            npt.assert_equal(halo_1.unique_tag, halo_2.unique_tag)

        npt.assert_equal(True, realization_fromhalos == self.realization_cdm)

        npt.assert_equal(realization_fromhalos.apply_mass_sheet_correction,
                         self.realization_cdm.apply_mass_sheet_correction)
Exemple #11
0
    def test_single_halo(self):

        single_halo = SingleHalo(10**8, 0.5, -0.1, 'TNFW', 0.5, 0.5, 1.5)
        lens_model_list, redshift_array, kwargs_lens, kwargs_lensmodel = single_halo.lensing_quantities(
        )
        npt.assert_equal(len(lens_model_list), 1)
        npt.assert_string_equal(lens_model_list[0], 'TNFW')
Exemple #12
0
 def test_pandas_const_series_prepend(self):
     # Check that the constant is added in the expected column location
     dta = longley.load_pandas()
     series = dta.exog['GNP']
     series = tools.add_constant(series, prepend=True)
     assert_string_equal('const', series.columns[0])
     assert_equal(series.var(0)[0], 0)
Exemple #13
0
def test_copy():
    x = tt.dmatrix('x')
    data = np.random.rand(5, 5)
    y = x.copy(name='y')
    f = theano.function([x], y)
    assert_equal(f(data), data)
    assert_string_equal(y.name, 'y')
def test_gate_translation(gate: Tuple[Any, str]):
    """Test gate operations with QASM interface"""
    qasm_operation = qasm_call_operation(operation=gate[0],
                                         number_qubits=2)

    if gate[1] is None:
        assert qasm_operation is None
    else:
        npt.assert_string_equal(qasm_operation, gate[1])
Exemple #15
0
    def test_profile_load(self):

        profile_args = {'amp': 1, 'sigma': 1, 'center_x': 0, 'center_y': 0}

        single_halo = SingleHalo(1e8, 0.5, 0.5, 'GAUSSIAN_KAPPA', 0.5, 0.5,
                                 1.5, None, True, profile_args, None)
        lens_model_list, redshift_array, kwargs_lens, numerical_interp = single_halo.\
            lensing_quantities(add_mass_sheet_correction=False)
        npt.assert_string_equal(lens_model_list[0], 'GAUSSIAN_KAPPA')
Exemple #16
0
def test_getter_signal_type(sine, sine_rms):
    """Test if attribute signal type is accessed correctly."""
    signal = Signal(sine.time, sine.sampling_rate, fft_norm=sine.fft_norm)
    npt.assert_string_equal(signal.signal_type, 'energy')

    signal = Signal(sine_rms.time,
                    sine_rms.sampling_rate,
                    fft_norm=sine_rms.fft_norm)
    npt.assert_string_equal(signal.signal_type, 'power')
Exemple #17
0
def test_enm_names():
    cg_universe = enm.Enm(NCSC)
    testing.assert_string_equal(
        native_str(cg_universe.atoms[0].name),
        native_str("A001"),
    )
    testing.assert_string_equal(
        native_str(cg_universe.residues[0].resname),
        native_str("A001"),
    )
Exemple #18
0
def test_load():
    dummy_file_name = 'dummy.txt'
    dummy_file_contents = 'This is some dummy text.'

    dummy_file = open(os.path.join(fs.SHADERS_DIR, dummy_file_name), 'w')
    dummy_file.write(dummy_file_contents)
    dummy_file.close()

    npt.assert_string_equal(fs.load(dummy_file_name), dummy_file_contents)

    os.remove(os.path.join(fs.SHADERS_DIR, dummy_file_name))
    def test_callback_terminates(self):
        # test that if the callback returns true, then the minimization halts
        bounds = [(0, 2), (0, 2)]

        def callback(param, convergence=0.):
            return True

        result = differential_evolution(rosen, bounds, callback=callback)

        assert_string_equal(result.message,
                                'callback function requested stop early '
                                'by returning True')
Exemple #20
0
    def test_numpy_version_attribute(self):

        # Check that self.module has an attribute named "__f2py_numpy_version__"
        assert_(hasattr(self.module, "__f2py_numpy_version__"),
                msg="Fortran module does not have __f2py_numpy_version__")

        # Check that the attribute __f2py_numpy_version__ is a string
        assert_(isinstance(self.module.__f2py_numpy_version__, str),
                msg="__f2py_numpy_version__ is not a string")

        # Check that __f2py_numpy_version__ has the value numpy.__version__
        assert_string_equal(np.__version__, self.module.__f2py_numpy_version__)
Exemple #21
0
    def test_callback_terminates(self):
        # test that if the callback returns true, then the minimization halts
        bounds = [(0, 2), (0, 2)]

        def callback(param, convergence=0.):
            return True

        result = differential_evolution(rosen, bounds, callback=callback)

        assert_string_equal(
            result.message, 'callback function requested stop early '
            'by returning True')
Exemple #22
0
    def test_profile_load(self):

        # test cored composite profile

        profile_args = {'log10_m_uldm': -22, 'uldm_plaw': 1/3, 'scale_nfw':False}

        single_halo = SingleHalo(1e8, 0.5, 0.5, 'ULDM', 0.5, 0.5, 1.5, None, True, profile_args, None)
        lens_model_list, redshift_array, kwargs_lens, numerical_interp = single_halo.\
            lensing_quantities(add_mass_sheet_correction=False)
        npt.assert_string_equal(lens_model_list[1], 'ULDM')
        npt.assert_string_equal(lens_model_list[0], 'CNFW')
        npt.assert_equal(True, len(kwargs_lens)==2)
        npt.assert_equal(True, len(redshift_array)==2)
Exemple #23
0
    def testQFTGateSequenceWithSwapping(self):
        """
        qft: Inspect swap gates added to gate sequences if
        swapping is enabled.
        """
        for N in range(1, 6):
            circuit = qft_gate_sequence(N, swapping=True)

            phases = int(N * (N + 1) / 2)
            swaps = int(N // 2)
            assert_equal(len(circuit.gates), phases + swaps)

            for i in range(phases, phases + swaps):
                assert_string_equal(circuit.gates[i].name, "SWAP")
Exemple #24
0
    def testQFTGateSequenceWithSwapping(self):
        """
        qft: Inspect swap gates added to gate sequences if
        swapping is enabled.
        """
        for N in range(1, 6):
            circuit = qft_gate_sequence(N, swapping=True)

            phases = int(N * (N + 1) / 2)
            swaps = int(N // 2)
            assert_equal(len(circuit.gates), phases + swaps)

            for i in range(phases, phases + swaps):
                assert_string_equal(circuit.gates[i].name, "SWAP")
Exemple #25
0
def test_load_text():
    with InTemporaryDirectory() as tdir:
        test_file_name = 'test.txt'

        # Test file does not exist
        npt.assert_raises(IOError, load_text, test_file_name)

        # Saving file with content
        test_file_contents = 'This is some test text.'
        test_fname = os.path.join(tdir, test_file_name)
        test_file = open(test_fname, 'w')
        test_file.write(test_file_contents)
        test_file.close()

        npt.assert_string_equal(load_text(test_fname), test_file_contents)
Exemple #26
0
def test_load_shader():
    fname_test = 'test.text'

    # Test invalid file extension
    npt.assert_raises(IOError, load_shader, fname_test)

    with InTemporaryDirectory() as tdir:
        fname_test = 'test.frag'
        fname_test = os.path.join(tdir, fname_test)
        str_test = 'Test1'
        test_file = open(fname_test, 'w')
        test_file.write(str_test)
        test_file.close()

        npt.assert_string_equal(load_shader(fname_test), str_test)
    def test_core_collapsed_halo(self):

        single_halo = SingleHalo(10**8,
                                 0.5,
                                 -0.1,
                                 'TNFW',
                                 0.5,
                                 0.5,
                                 1.5,
                                 subhalo_flag=True)
        ext = RealizationExtensions(single_halo)
        new = ext.add_core_collapsed_halos([0],
                                           log_slope_halo=3.,
                                           x_core_halo=0.05)
        lens_model_list = new.lensing_quantities()[0]
        npt.assert_string_equal(lens_model_list[0], 'SPL_CORE')
Exemple #28
0
    def test_lenstronomy_ID(self):

        ID = self.fieldhalo.lenstronomy_ID
        npt.assert_string_equal(ID[0], 'CNFW')
        npt.assert_string_equal(ID[1], 'ULDM')

        ID = self.subhalo.lenstronomy_ID
        npt.assert_string_equal(ID[0], 'CNFW')
        npt.assert_string_equal(ID[1], 'ULDM')
    def test_callback_terminates(self):
        # test that if the callback returns true, then the minimization halts
        bounds = [(0, 2), (0, 2)]

        def callback(param, convergence=0.):
            # This is a very round-about way to 
            # check this property, but it helps
            # to ensure the code is tested like
            # it will be used: ie, with a numpy
            # bool (which, notably, will not be
            # the same identity so `is`  cannot
            # be used.
            return (np.array([1]) == 1).astype(bool)[0]

        result = differential_evolution(rosen, bounds, callback=callback)

        assert_string_equal(result.message,
                                'callback function requested stop early '
                                'by returning True')
Exemple #30
0
    def test_dipy_home():
        test_path = 'TEST_PATH'
        if 'DIPY_HOME' in os.environ:
            old_home = os.environ['DIPY_HOME']
            del os.environ['DIPY_HOME']
        else:
            old_home = None

        reload(fetcher)

        npt.assert_string_equal(fetcher.dipy_home,
                                op.join(os.path.expanduser('~'), '.dipy'))
        os.environ['DIPY_HOME'] = test_path
        reload(fetcher)
        npt.assert_string_equal(fetcher.dipy_home, test_path)

        # return to previous state
        if old_home:
            os.environ['DIPY_HOME'] = old_home
Exemple #31
0
    def test_dipy_home():
        test_path = 'TEST_PATH'
        if 'DIPY_HOME' in os.environ:
            old_home = os.environ['DIPY_HOME']
            del os.environ['DIPY_HOME']
        else:
            old_home = None

        reload(fetcher)

        npt.assert_string_equal(fetcher.dipy_home,
                                op.join(os.path.expanduser('~'), '.dipy'))
        os.environ['DIPY_HOME'] = test_path
        reload(fetcher)
        npt.assert_string_equal(fetcher.dipy_home, test_path)

        # return to previous state
        if old_home:
            os.environ['DIPY_HOME'] = old_home
Exemple #32
0
def test_fetch_csv():

    with limix.file_example("expr.csv") as filepath:

        spec = f"{filepath}:csv:row=trait,trait[gene1]"
        y = fetch("trait", spec, verbose=False)

        assert_string_equal(y.name, "trait")
        assert_array_equal(y["sample"], _samples)
        assert_equal(y.shape, (274, 1))
        assert_allclose(y.values[:2, 0],
                        [-3.752_345_147_31, -0.421_128_991_488])
        assert_array_equal(y.coords, ["trait", "sample"])

        spec = f"{filepath}:csv:row=trait,trait[gene11]"
        y = fetch("trait", spec, verbose=False)

        assert_string_equal(y.name, "trait")
        assert_array_equal(y["sample"], _samples)
        assert_equal(y.shape, (274, 1))
        assert_allclose(y.values[:2, 0], [0.798_312_717_19, 0.237_496_587_19])

        spec = f"{filepath}:csv:row=trait"
        y = fetch("trait", spec, verbose=False)

        assert_string_equal(y.name, "trait")
        assert_array_equal(y["sample"], _samples)
        assert_equal(y.shape, (274, 11))

        spec = f"{filepath}:csv:row=trait,col=sample"
        y = fetch("trait", spec, verbose=False)
        assert_equal(y.shape, (274, 11))
        assert_equal(y.dims, ("sample", "trait"))

        spec = f"{filepath}:csv:row=sample,col=trait"
        y = fetch("trait", spec, verbose=False)
        assert_equal(y.shape, (11, 274))
        assert_equal(y.dims, ("sample", "trait"))

        spec = f"{filepath}:csv:"
        y = fetch("trait", spec, verbose=False)

        spec = f"{filepath}:csv"
        y = fetch("trait", spec, verbose=False)

        spec = f"{filepath}:csv:row=samples"
        with pytest.raises(ValueError):
            y = fetch("trait", spec, verbose=False)

        spec = "wrong_filepath:csv:row=sample"
        with pytest.raises(FileNotFoundError):
            y = fetch("trait", spec, verbose=False)

        spec = f"{filepath}:csv:row=sample,col=trait"
        with pytest.raises(ValueError):
            y = fetch("traits", spec, verbose=False)

        spec = f"{filepath}:csvs:row=sample,col=trait"
        with pytest.raises(ValueError):
            y = fetch("trait", spec, verbose=False)
Exemple #33
0
def test_get_synthetics():
    # Try to load 3 stations, out of which 2 are in range for P
    db = instaseis.open_db('syngine://prem_a_20s')
    cat = obspy.read_events('./stfinv/data/virginia.xml')
    st = read('./stfinv/data/dis.II.BFO.00.BHZ')
    st += read('./stfinv/data/dis.GE.DAG..BHZ')
    st += read('./stfinv/data/dis.G.CRZF.00.BHZ')
    st_data, st_syn = st.get_synthetics(db=db,
                                        origin=cat[0].origins[0],
                                        out_dir='/tmp')

    npt.assert_equal(len(st_data), 2)
    npt.assert_equal(len(st_syn), 12)

    for istat in range(0, 2):
        channels = ['MPP', 'MRP', 'MRR', 'MRT', 'MTP', 'MTT']
        for channel in channels:
            st_test = st_syn.select(station=st_data[istat].stats.station,
                                    network=st_data[istat].stats.network,
                                    location=st_data[istat].stats.location,
                                    channel=channel)
            npt.assert_equal(len(st_test), 1)

        for tr in st_syn[istat * 6:(istat + 1) * 6]:
            npt.assert_string_equal(str(tr.stats.station),
                                    str(st_data[istat].stats.station))
            npt.assert_string_equal(str(tr.stats.location),
                                    str(st_data[istat].stats.location))
            npt.assert_string_equal(str(tr.stats.network),
                                    str(st_data[istat].stats.network))

            npt.assert_equal(tr.stats.npts, st_data[istat].stats.npts)
            npt.assert_allclose(tr.stats.delta, st_data[istat].stats.delta)
            npt.assert_allclose(float(tr.stats.starttime),
                                float(st_data[istat].stats.starttime))
Exemple #34
0
def test_get_synthetics():
    # Try to load 3 stations, out of which 2 are in range for P
    db = instaseis.open_db('syngine://prem_a_20s')
    cat = obspy.read_events('./stfinv/data/virginia.xml')
    st = read('./stfinv/data/dis.II.BFO.00.BHZ')
    st += read('./stfinv/data/dis.GE.DAG..BHZ')
    st += read('./stfinv/data/dis.G.CRZF.00.BHZ')
    st_data, st_syn = st.get_synthetics(db=db, origin=cat[0].origins[0],
                                        out_dir='/tmp')

    npt.assert_equal(len(st_data), 2)
    npt.assert_equal(len(st_syn), 12)

    for istat in range(0, 2):
        channels = ['MPP', 'MRP', 'MRR', 'MRT', 'MTP', 'MTT']
        for channel in channels:
            st_test = st_syn.select(station=st_data[istat].stats.station,
                                    network=st_data[istat].stats.network,
                                    location=st_data[istat].stats.location,
                                    channel=channel)
            npt.assert_equal(len(st_test), 1)

        for tr in st_syn[istat * 6:(istat + 1) * 6]:
            npt.assert_string_equal(str(tr.stats.station),
                                    str(st_data[istat].stats.station))
            npt.assert_string_equal(str(tr.stats.location),
                                    str(st_data[istat].stats.location))
            npt.assert_string_equal(str(tr.stats.network),
                                    str(st_data[istat].stats.network))

            npt.assert_equal(tr.stats.npts, st_data[istat].stats.npts)
            npt.assert_allclose(tr.stats.delta, st_data[istat].stats.delta)
            npt.assert_allclose(float(tr.stats.starttime),
                                float(st_data[istat].stats.starttime))
Exemple #35
0
    def test_simple(self):
        assert_string_equal("hello", "hello")
        assert_string_equal("hello\nmultiline", "hello\nmultiline")

        try:
            assert_string_equal("foo\nbar", "hello\nbar")
        except AssertionError as exc:
            assert_equal(str(exc), "Differences in strings:\n- foo\n+ hello")
        else:
            raise AssertionError("exception not raised")

        self.assertRaises(AssertionError, lambda: assert_string_equal("foo", "hello"))
Exemple #36
0
    def test_simple(self):
        assert_string_equal("hello", "hello")
        assert_string_equal("hello\nmultiline", "hello\nmultiline")

        try:
            assert_string_equal("foo\nbar", "hello\nbar")
        except AssertionError as exc:
            assert_equal(str(exc), "Differences in strings:\n- foo\n+ hello")
        else:
            raise AssertionError("exception not raised")

        self.assertRaises(AssertionError,
                          lambda: assert_string_equal("foo", "hello"))
Exemple #37
0
def test_obj_src():
    string_result = scrape.obj_src(eat_porridge)
    initial_txt_should_be = str(
        'def eat_porridge(this_sucks, temperature, wtf):')
    initial_txt_actual = str(string_result.split('\n')[0])
    assert_string_equal(initial_txt_actual, initial_txt_should_be)
Exemple #38
0
def test_obj_src():
    string_result = wrap_lib.obj_src(interp)
    initial_txt_should_be = str('def interp(x, xp, fp, left=None, right=None)')
    initial_txt_actual = string_result[0:44]
    assert_string_equal(initial_txt_actual, initial_txt_should_be)
Exemple #39
0
def test_pandas_const_df_prepend():
    dta = longley.load_pandas().exog
    dta = tools.add_constant(dta, prepend=True)
    assert_string_equal('const', dta.columns[0])
    assert_equal(dta.var(0)[0], 0)
Exemple #40
0
def test_infer_freq():
    from pandas import DateRange
    d1 = datetime(2008, 12, 31)
    d2 = datetime(2012, 9, 30)

    b = DateRange(d1, d2, offset=_freq_to_pandas['B']).values
    d = DateRange(d1, d2, offset=_freq_to_pandas['D']).values
    w = DateRange(d1, d2, offset=_freq_to_pandas['W']).values
    m = DateRange(d1, d2, offset=_freq_to_pandas['M']).values
    a = DateRange(d1, d2, offset=_freq_to_pandas['A']).values
    q = DateRange(d1, d2, offset=_freq_to_pandas['Q']).values

    npt.assert_string_equal(_infer_freq(b), 'B')
    npt.assert_string_equal(_infer_freq(d), 'D')
    npt.assert_string_equal(_infer_freq(w), 'W')
    npt.assert_string_equal(_infer_freq(m), 'M')
    npt.assert_string_equal(_infer_freq(a), 'A')
    npt.assert_string_equal(_infer_freq(q), 'Q')
    npt.assert_string_equal(_infer_freq(b[2:4]), 'B')
    npt.assert_string_equal(_infer_freq(b[:2]), 'D')
    npt.assert_string_equal(_infer_freq(d[:2]), 'D')
    npt.assert_string_equal(_infer_freq(w[:2]), 'W')
    npt.assert_string_equal(_infer_freq(m[:2]), 'M')
    npt.assert_string_equal(_infer_freq(a[:2]), 'A')
    npt.assert_string_equal(_infer_freq(q[:2]), 'Q')
def test_pandas_const_series_prepend():
    dta = longley.load_pandas()
    series = dta.exog['GNP']
    series = tools.add_constant(series, prepend=True)
    assert_string_equal('const', series.columns[0])
    assert_equal(series.var(0)[0], 0)
def test_pandas_const_df():
    dta = longley.load_pandas().exog
    dta = tools.add_constant(dta, prepend=False)
    assert_string_equal('const', dta.columns[-1])
    assert_equal(dta.var(0)[-1], 0)
Exemple #43
0
def test_get_data_path():
    fn = 'parrot'
    path = os.path.dirname(os.path.abspath(__file__))
    data_path = os.path.join(path, 'data', fn)
    data_path_2 = get_data_path(fn)
    npt.assert_string_equal(data_path_2, data_path)
Exemple #44
0
    def test_regex(self):
        assert_string_equal("a+*b", "a+*b")

        assert_raises(AssertionError,
                      lambda: assert_string_equal("aaa", "a+b"))
def test_pandas_const_df():
    dta = longley.load_pandas().exog
    dta = tools.add_constant(dta, prepend=False)
    assert_string_equal("const", dta.columns[-1])
    assert_equal(dta.var(0)[-1], 0)
def test_pandas_const_series_prepend():
    dta = longley.load_pandas()
    series = dta.exog["GNP"]
    series = tools.add_constant(series, prepend=True)
    assert_string_equal("const", series.columns[0])
    assert_equal(series.var(0)[0], 0)
def test_name(bj84_pc):
    assert_string_equal(bj84_pc.name, 'Boore & Joyner (1984)')
def test_abbrev(bj84_pc):
    assert_string_equal(bj84_pc.abbrev, 'BJ84')
Exemple #49
0
def test_pandas_const_series():
    dta = longley.load_pandas()
    series = dta.exog['GNP']
    series = tools.add_constant(series, prepend=False)
    assert_string_equal('const', series.columns[1])
    assert_equal(series.var(0)[1], 0)