本文整理匯總了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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例7: test_testing
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import testing [as 別名]
def test_testing(self):
from pandas import testing
self.check(testing, self.funcs)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)