当前位置: 首页>>代码示例>>Python>>正文


Python pandas.testing方法代码示例

本文整理汇总了Python中pandas.testing方法的典型用法代码示例。如果您正苦于以下问题:Python pandas.testing方法的具体用法?Python pandas.testing怎么用?Python pandas.testing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas的用法示例。


在下文中一共展示了pandas.testing方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_localize_df_with_timestamp_column

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_localize_df_with_timestamp_column(module_under_test):
    df = pandas.DataFrame(
        {
            "integer_col": [1, 2, 3],
            "timestamp_col": pandas.Series(
                [
                    "2011-01-01 01:02:03",
                    "2012-02-02 04:05:06",
                    "2013-03-03 07:08:09",
                ],
                dtype="datetime64[ns]",
            ),
            "float_col": [0.1, 0.2, 0.3],
        }
    )
    expected = df.copy()
    expected["timestamp_col"] = df["timestamp_col"].dt.tz_localize("UTC")
    bq_schema = [
        {"name": "integer_col", "type": "INTEGER"},
        {"name": "timestamp_col", "type": "TIMESTAMP"},
        {"name": "float_col", "type": "FLOAT"},
    ]

    localized = module_under_test.localize_df(df, bq_schema)
    pandas.testing.assert_frame_equal(localized, expected) 
开发者ID:pydata,项目名称:pandas-gbq,代码行数:27,代码来源:test_timestamp.py

示例2: test_get_column_or_index_with_multiindex

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_get_column_or_index_with_multiindex(module_under_test):
    dataframe = pandas.DataFrame(
        {"column_name": [1, 2, 3, 4, 5, 6]},
        index=pandas.MultiIndex.from_tuples(
            [("a", 0), ("a", 1), ("b", 0), ("b", 1), ("c", 0), ("c", 1)],
            names=["letters", "numbers"],
        ),
    )

    series = module_under_test.get_column_or_index(dataframe, "letters")
    expected = pandas.Series(["a", "a", "b", "b", "c", "c"], name="letters")
    pandas.testing.assert_series_equal(series, expected)

    series = module_under_test.get_column_or_index(dataframe, "numbers")
    expected = pandas.Series([0, 1, 0, 1, 0, 1], name="numbers")
    pandas.testing.assert_series_equal(series, expected) 
开发者ID:googleapis,项目名称:python-bigquery,代码行数:18,代码来源:test__pandas_helpers.py

示例3: test_log_model

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_log_model(sequential_model, data, sequential_predicted):
    old_uri = tracking.get_tracking_uri()
    # should_start_run tests whether or not calling log_model() automatically starts a run.
    for should_start_run in [False, True]:
        with TempDir(chdr=True, remove_on_exit=True) as tmp:
            try:
                tracking.set_tracking_uri(tmp.path("test"))
                if should_start_run:
                    mlflow.start_run()

                artifact_path = "pytorch"
                mlflow.pytorch.log_model(sequential_model, artifact_path=artifact_path)
                model_uri = "runs:/{run_id}/{artifact_path}".format(
                    run_id=mlflow.active_run().info.run_id,
                    artifact_path=artifact_path)

                # Load model
                sequential_model_loaded = mlflow.pytorch.load_model(model_uri=model_uri)

                test_predictions = _predict(sequential_model_loaded, data)
                np.testing.assert_array_equal(test_predictions, sequential_predicted)
            finally:
                mlflow.end_run()
                tracking.set_tracking_uri(old_uri) 
开发者ID:mlflow,项目名称:mlflow,代码行数:26,代码来源:test_pytorch_model_export.py

示例4: test_pyfunc_model_serving_with_module_scoped_subclassed_model_and_default_conda_env

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_pyfunc_model_serving_with_module_scoped_subclassed_model_and_default_conda_env(
        module_scoped_subclassed_model, model_path, data):
    mlflow.pytorch.save_model(
        path=model_path,
        pytorch_model=module_scoped_subclassed_model,
        conda_env=None,
        code_paths=[__file__])

    scoring_response = pyfunc_serve_and_score_model(
            model_uri=model_path,
            data=data[0],
            content_type=pyfunc_scoring_server.CONTENT_TYPE_JSON_SPLIT_ORIENTED,
            extra_args=["--no-conda"])
    assert scoring_response.status_code == 200

    deployed_model_preds = pd.DataFrame(json.loads(scoring_response.content))
    np.testing.assert_array_almost_equal(
        deployed_model_preds.values[:, 0],
        _predict(model=module_scoped_subclassed_model, data=data),
        decimal=4) 
开发者ID:mlflow,项目名称:mlflow,代码行数:22,代码来源:test_pytorch_model_export.py

示例5: test_pyfunc_model_serving_with_main_scoped_subclassed_model_and_custom_pickle_module

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_pyfunc_model_serving_with_main_scoped_subclassed_model_and_custom_pickle_module(
        main_scoped_subclassed_model, model_path, data):
    mlflow.pytorch.save_model(
        path=model_path,
        pytorch_model=main_scoped_subclassed_model,
        conda_env=None,
        pickle_module=mlflow_pytorch_pickle_module)

    scoring_response = pyfunc_serve_and_score_model(
            model_uri=model_path,
            data=data[0],
            content_type=pyfunc_scoring_server.CONTENT_TYPE_JSON_SPLIT_ORIENTED,
            extra_args=["--no-conda"])
    assert scoring_response.status_code == 200

    deployed_model_preds = pd.DataFrame(json.loads(scoring_response.content))
    np.testing.assert_array_almost_equal(
        deployed_model_preds.values[:, 0],
        _predict(model=main_scoped_subclassed_model, data=data),
        decimal=4) 
开发者ID:mlflow,项目名称:mlflow,代码行数:22,代码来源:test_pytorch_model_export.py

示例6: test_sagemaker_docker_model_scoring_with_sequential_model_and_default_conda_env

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_sagemaker_docker_model_scoring_with_sequential_model_and_default_conda_env(
        model, model_path, data, sequential_predicted):
    mlflow.pytorch.save_model(pytorch_model=model, path=model_path, conda_env=None)

    scoring_response = score_model_in_sagemaker_docker_container(
            model_uri=model_path,
            data=data[0],
            content_type=pyfunc_scoring_server.CONTENT_TYPE_JSON_SPLIT_ORIENTED,
            flavor=mlflow.pyfunc.FLAVOR_NAME,
            activity_polling_timeout_seconds=360)
    deployed_model_preds = pd.DataFrame(json.loads(scoring_response.content))

    np.testing.assert_array_almost_equal(
        deployed_model_preds.values[:, 0],
        sequential_predicted,
        decimal=4) 
开发者ID:mlflow,项目名称:mlflow,代码行数:18,代码来源:test_pytorch_model_export.py

示例7: test_testing

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_testing(self):

        from pandas import testing
        self.check(testing, self.funcs) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_api.py

示例8: test_localize_df_with_empty_dataframe

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_localize_df_with_empty_dataframe(module_under_test):
    df = pandas.DataFrame({"timestamp_col": [], "other_col": []})
    original = df.copy()
    bq_schema = [
        {"name": "timestamp_col", "type": "TIMESTAMP"},
        {"name": "other_col", "type": "STRING"},
    ]

    localized = module_under_test.localize_df(df, bq_schema)

    # Empty DataFrames should be unchanged.
    assert localized is df
    pandas.testing.assert_frame_equal(localized, original) 
开发者ID:pydata,项目名称:pandas-gbq,代码行数:15,代码来源:test_timestamp.py

示例9: test_localize_df_with_no_timestamp_columns

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_localize_df_with_no_timestamp_columns(module_under_test):
    df = pandas.DataFrame(
        {"integer_col": [1, 2, 3], "float_col": [0.1, 0.2, 0.3]}
    )
    original = df.copy()
    bq_schema = [
        {"name": "integer_col", "type": "INTEGER"},
        {"name": "float_col", "type": "FLOAT"},
    ]

    localized = module_under_test.localize_df(df, bq_schema)

    # DataFrames with no TIMESTAMP columns should be unchanged.
    assert localized is df
    pandas.testing.assert_frame_equal(localized, original) 
开发者ID:pydata,项目名称:pandas-gbq,代码行数:17,代码来源:test_timestamp.py

示例10: test_get_column_or_index_with_both_prefers_column

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_get_column_or_index_with_both_prefers_column(module_under_test):
    dataframe = pandas.DataFrame(
        {"some_name": [1, 2, 3]}, index=pandas.Index([0, 1, 2], name="some_name")
    )
    series = module_under_test.get_column_or_index(dataframe, "some_name")
    expected = pandas.Series([1, 2, 3], name="some_name")
    pandas.testing.assert_series_equal(series, expected) 
开发者ID:googleapis,项目名称:python-bigquery,代码行数:9,代码来源:test__pandas_helpers.py

示例11: test_get_column_or_index_with_column

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_get_column_or_index_with_column(module_under_test):
    dataframe = pandas.DataFrame({"column_name": [1, 2, 3], "other_column": [4, 5, 6]})
    series = module_under_test.get_column_or_index(dataframe, "column_name")
    expected = pandas.Series([1, 2, 3], name="column_name")
    pandas.testing.assert_series_equal(series, expected) 
开发者ID:googleapis,项目名称:python-bigquery,代码行数:7,代码来源:test__pandas_helpers.py

示例12: test_get_column_or_index_with_named_index

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_get_column_or_index_with_named_index(module_under_test):
    dataframe = pandas.DataFrame(
        {"column_name": [1, 2, 3]}, index=pandas.Index([4, 5, 6], name="index_name")
    )
    series = module_under_test.get_column_or_index(dataframe, "index_name")
    expected = pandas.Series([4, 5, 6], name="index_name")
    pandas.testing.assert_series_equal(series, expected) 
开发者ID:googleapis,项目名称:python-bigquery,代码行数:9,代码来源:test__pandas_helpers.py

示例13: test_get_column_or_index_with_datetimeindex

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_get_column_or_index_with_datetimeindex(module_under_test):
    datetimes = [
        datetime.datetime(2000, 1, 2, 3, 4, 5, 101),
        datetime.datetime(2006, 7, 8, 9, 10, 11, 202),
        datetime.datetime(2012, 1, 14, 15, 16, 17, 303),
    ]
    dataframe = pandas.DataFrame(
        {"column_name": [1, 2, 3]},
        index=pandas.DatetimeIndex(datetimes, name="index_name"),
    )
    series = module_under_test.get_column_or_index(dataframe, "index_name")
    expected = pandas.Series(datetimes, name="index_name")
    pandas.testing.assert_series_equal(series, expected) 
开发者ID:googleapis,项目名称:python-bigquery,代码行数:15,代码来源:test__pandas_helpers.py

示例14: test_save_and_load_model

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_save_and_load_model(sequential_model, model_path, data, sequential_predicted):
    mlflow.pytorch.save_model(sequential_model, model_path)

    # Loading pytorch model
    sequential_model_loaded = mlflow.pytorch.load_model(model_path)
    np.testing.assert_array_equal(_predict(sequential_model_loaded, data), sequential_predicted)

    # Loading pyfunc model
    pyfunc_loaded = mlflow.pyfunc.load_pyfunc(model_path)
    np.testing.assert_array_almost_equal(
        pyfunc_loaded.predict(data[0]).values[:, 0], sequential_predicted, decimal=4) 
开发者ID:mlflow,项目名称:mlflow,代码行数:13,代码来源:test_pytorch_model_export.py

示例15: test_load_model_from_remote_uri_succeeds

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import testing [as 别名]
def test_load_model_from_remote_uri_succeeds(
        sequential_model, model_path, mock_s3_bucket, data, sequential_predicted):
    mlflow.pytorch.save_model(sequential_model, model_path)

    artifact_root = "s3://{bucket_name}".format(bucket_name=mock_s3_bucket)
    artifact_path = "model"
    artifact_repo = S3ArtifactRepository(artifact_root)
    artifact_repo.log_artifacts(model_path, artifact_path=artifact_path)

    model_uri = artifact_root + "/" + artifact_path
    sequential_model_loaded = mlflow.pytorch.load_model(model_uri=model_uri)
    np.testing.assert_array_equal(_predict(sequential_model_loaded, data), sequential_predicted) 
开发者ID:mlflow,项目名称:mlflow,代码行数:14,代码来源:test_pytorch_model_export.py


注:本文中的pandas.testing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。