本文整理匯總了Python中pandas.util.testing.makeMixedDataFrame方法的典型用法代碼示例。如果您正苦於以下問題:Python testing.makeMixedDataFrame方法的具體用法?Python testing.makeMixedDataFrame怎麽用?Python testing.makeMixedDataFrame使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandas.util.testing
的用法示例。
在下文中一共展示了testing.makeMixedDataFrame方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_upload_data_with_valid_user_schema
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import makeMixedDataFrame [as 別名]
def test_upload_data_with_valid_user_schema(self, project_id):
# Issue #46; tests test scenarios with user-provided
# schemas
df = tm.makeMixedDataFrame()
test_id = "18"
test_schema = [
{"name": "A", "type": "FLOAT"},
{"name": "B", "type": "FLOAT"},
{"name": "C", "type": "STRING"},
{"name": "D", "type": "TIMESTAMP"},
]
destination_table = self.destination_table + test_id
gbq.to_gbq(
df,
destination_table,
project_id,
credentials=self.credentials,
table_schema=test_schema,
)
dataset, table = destination_table.split(".")
assert self.table.verify_schema(
dataset, table, dict(fields=test_schema)
)
示例2: test_upload_data_with_invalid_user_schema_raises_error
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import makeMixedDataFrame [as 別名]
def test_upload_data_with_invalid_user_schema_raises_error(
self, project_id
):
df = tm.makeMixedDataFrame()
test_id = "19"
test_schema = [
{"name": "A", "type": "FLOAT"},
{"name": "B", "type": "FLOAT"},
{"name": "C", "type": "FLOAT"},
{"name": "D", "type": "FLOAT"},
]
destination_table = self.destination_table + test_id
with pytest.raises(gbq.GenericGBQException):
gbq.to_gbq(
df,
destination_table,
project_id,
credentials=self.credentials,
table_schema=test_schema,
)
示例3: test_upload_data_with_missing_schema_fields_raises_error
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import makeMixedDataFrame [as 別名]
def test_upload_data_with_missing_schema_fields_raises_error(
self, project_id
):
df = tm.makeMixedDataFrame()
test_id = "20"
test_schema = [
{"name": "A", "type": "FLOAT"},
{"name": "B", "type": "FLOAT"},
{"name": "C", "type": "FLOAT"},
]
destination_table = self.destination_table + test_id
with pytest.raises(gbq.GenericGBQException):
gbq.to_gbq(
df,
destination_table,
project_id,
credentials=self.credentials,
table_schema=test_schema,
)
示例4: test_isna_isnull
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import makeMixedDataFrame [as 別名]
def test_isna_isnull(self, isna_f):
assert not isna_f(1.)
assert isna_f(None)
assert isna_f(np.NaN)
assert float('nan')
assert not isna_f(np.inf)
assert not isna_f(-np.inf)
# series
for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
tm.makeObjectSeries(), tm.makeTimeSeries(),
tm.makePeriodSeries()]:
assert isinstance(isna_f(s), Series)
# frame
for df in [tm.makeTimeDataFrame(), tm.makePeriodFrame(),
tm.makeMixedDataFrame()]:
result = isna_f(df)
expected = df.apply(isna_f)
tm.assert_frame_equal(result, expected)
# panel
with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
for p in [tm.makePanel(), tm.makePeriodPanel(),
tm.add_nans(tm.makePanel())]:
result = isna_f(p)
expected = p.apply(isna_f)
tm.assert_panel_equal(result, expected)
示例5: test_hash_pandas_object
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import makeMixedDataFrame [as 別名]
def test_hash_pandas_object(self):
for obj in [Series([1, 2, 3]),
Series([1.0, 1.5, 3.2]),
Series([1.0, 1.5, np.nan]),
Series([1.0, 1.5, 3.2], index=[1.5, 1.1, 3.3]),
Series(['a', 'b', 'c']),
Series(['a', np.nan, 'c']),
Series(['a', None, 'c']),
Series([True, False, True]),
Series(),
Index([1, 2, 3]),
Index([True, False, True]),
DataFrame({'x': ['a', 'b', 'c'], 'y': [1, 2, 3]}),
DataFrame(),
tm.makeMissingDataframe(),
tm.makeMixedDataFrame(),
tm.makeTimeDataFrame(),
tm.makeTimeSeries(),
tm.makeTimedeltaIndex(),
tm.makePeriodIndex(),
Series(tm.makePeriodIndex()),
Series(pd.date_range('20130101',
periods=3, tz='US/Eastern')),
MultiIndex.from_product(
[range(5),
['foo', 'bar', 'baz'],
pd.date_range('20130101', periods=2)]),
MultiIndex.from_product(
[pd.CategoricalIndex(list('aabc')),
range(3)])]:
self.check_equal(obj)
self.check_not_equal_with_index(obj)
示例6: test_isna_isnull
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import makeMixedDataFrame [as 別名]
def test_isna_isnull(self, isna_f):
assert not isna_f(1.)
assert isna_f(None)
assert isna_f(np.NaN)
assert float('nan')
assert not isna_f(np.inf)
assert not isna_f(-np.inf)
# series
for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
tm.makeObjectSeries(), tm.makeTimeSeries(),
tm.makePeriodSeries()]:
assert isinstance(isna_f(s), Series)
# frame
for df in [tm.makeTimeDataFrame(), tm.makePeriodFrame(),
tm.makeMixedDataFrame()]:
result = isna_f(df)
expected = df.apply(isna_f)
tm.assert_frame_equal(result, expected)
# panel
with catch_warnings(record=True):
for p in [tm.makePanel(), tm.makePeriodPanel(),
tm.add_nans(tm.makePanel())]:
result = isna_f(p)
expected = p.apply(isna_f)
tm.assert_panel_equal(result, expected)
示例7: test_upload_data_if_table_exists_replace
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import makeMixedDataFrame [as 別名]
def test_upload_data_if_table_exists_replace(self, project_id):
test_id = "4"
test_size = 10
df = make_mixed_dataframe_v2(test_size)
df_different_schema = tm.makeMixedDataFrame()
# Initialize table with sample data
gbq.to_gbq(
df,
self.destination_table + test_id,
project_id,
chunksize=10000,
credentials=self.credentials,
)
# Test the if_exists parameter with the value 'replace'.
gbq.to_gbq(
df_different_schema,
self.destination_table + test_id,
project_id,
if_exists="replace",
credentials=self.credentials,
)
result = gbq.read_gbq(
"SELECT COUNT(*) AS num_rows FROM {0}".format(
self.destination_table + test_id
),
project_id=project_id,
credentials=self.credentials,
dialect="legacy",
)
assert result["num_rows"][0] == 5
示例8: test_create_table
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import makeMixedDataFrame [as 別名]
def test_create_table(gbq_table):
schema = gbq._generate_bq_schema(tm.makeMixedDataFrame())
gbq_table.create("test_create_table", schema)
assert gbq_table.exists("test_create_table")
示例9: test_create_table_already_exists
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import makeMixedDataFrame [as 別名]
def test_create_table_already_exists(gbq_table):
schema = gbq._generate_bq_schema(tm.makeMixedDataFrame())
gbq_table.create("test_create_table_exists", schema)
with pytest.raises(gbq.TableCreationError):
gbq_table.create("test_create_table_exists", schema)
示例10: test_isna_isnull
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import makeMixedDataFrame [as 別名]
def test_isna_isnull(self, isna_f):
assert not isna_f(1.)
assert isna_f(None)
assert isna_f(np.NaN)
assert float('nan')
assert not isna_f(np.inf)
assert not isna_f(-np.inf)
# series
for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
tm.makeObjectSeries(), tm.makeTimeSeries(),
tm.makePeriodSeries()]:
assert isinstance(isna_f(s), Series)
# frame
for df in [tm.makeTimeDataFrame(), tm.makePeriodFrame(),
tm.makeMixedDataFrame()]:
result = isna_f(df)
expected = df.apply(isna_f)
tm.assert_frame_equal(result, expected)
# panel
with catch_warnings(record=True):
for p in [tm.makePanel(), tm.makePeriodPanel(),
tm.add_nans(tm.makePanel())]:
result = isna_f(p)
expected = p.apply(isna_f)
tm.assert_panel_equal(result, expected)
# panel 4d
with catch_warnings(record=True):
for p in [tm.makePanel4D(), tm.add_nans_panel4d(tm.makePanel4D())]:
result = isna_f(p)
expected = p.apply(isna_f)
tm.assert_panel4d_equal(result, expected)
示例11: test_upload_data_if_table_exists_append
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import makeMixedDataFrame [as 別名]
def test_upload_data_if_table_exists_append(self, project_id):
test_id = "3"
test_size = 10
df = make_mixed_dataframe_v2(test_size)
df_different_schema = tm.makeMixedDataFrame()
# Initialize table with sample data
gbq.to_gbq(
df,
self.destination_table + test_id,
project_id,
chunksize=10000,
credentials=self.credentials,
)
# Test the if_exists parameter with value 'append'
gbq.to_gbq(
df,
self.destination_table + test_id,
project_id,
if_exists="append",
credentials=self.credentials,
)
result = gbq.read_gbq(
"SELECT COUNT(*) AS num_rows FROM {0}".format(
self.destination_table + test_id
),
project_id=project_id,
credentials=self.credentials,
dialect="legacy",
)
assert result["num_rows"][0] == test_size * 2
# Try inserting with a different schema, confirm failure
with pytest.raises(gbq.InvalidSchema):
gbq.to_gbq(
df_different_schema,
self.destination_table + test_id,
project_id,
if_exists="append",
credentials=self.credentials,
)