Python pandas.util.testing.makeMixedDataFrame() Examples
The following are 15
code examples of pandas.util.testing.makeMixedDataFrame().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas.util.testing
, or try the search function
.
Example #1
Source File: test_gbq.py From pandas-gbq with BSD 3-Clause "New" or "Revised" License | 6 votes |
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) )
Example #2
Source File: test_gbq.py From pandas-gbq with BSD 3-Clause "New" or "Revised" License | 6 votes |
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, )
Example #3
Source File: test_gbq.py From pandas-gbq with BSD 3-Clause "New" or "Revised" License | 6 votes |
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, )
Example #4
Source File: test_missing.py From recruit with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: test_hashing.py From vnpy_crypto with MIT License | 5 votes |
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)
Example #6
Source File: test_missing.py From vnpy_crypto with MIT License | 5 votes |
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)
Example #7
Source File: test_missing.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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)
Example #8
Source File: test_gbq.py From pandas-gbq with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #9
Source File: test_gbq.py From pandas-gbq with BSD 3-Clause "New" or "Revised" License | 5 votes |
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")
Example #10
Source File: test_gbq.py From pandas-gbq with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #11
Source File: test_hashing.py From elasticintel with GNU General Public License v3.0 | 5 votes |
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)
Example #12
Source File: test_missing.py From elasticintel with GNU General Public License v3.0 | 5 votes |
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)
Example #13
Source File: test_hashing.py From twitter-stock-recommendation with MIT License | 5 votes |
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)
Example #14
Source File: test_missing.py From twitter-stock-recommendation with MIT License | 5 votes |
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)
Example #15
Source File: test_gbq.py From pandas-gbq with BSD 3-Clause "New" or "Revised" License | 4 votes |
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, )