Python pandas.util.testing.rands() Examples
The following are 30
code examples of pandas.util.testing.rands().
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_format.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_repr_truncation(self): max_len = 20 with option_context("display.max_colwidth", max_len): df = DataFrame({'A': np.random.randn(10), 'B': [tm.rands(np.random.randint( max_len - 1, max_len + 1)) for i in range(10) ]}) r = repr(df) r = r[r.find('\n') + 1:] adj = fmt._get_adjustment() for line, value in lzip(r.split('\n'), df['B']): if adj.len(value) + 1 > max_len: assert '...' in line else: assert '...' not in line with option_context("display.max_colwidth", 999999): assert '...' not in repr(df) with option_context("display.max_colwidth", max_len + 2): assert '...' not in repr(df)
Example #2
Source File: test_common.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_nonexistent_path(all_parsers): # gh-2428: pls no segfault # gh-14086: raise more helpful FileNotFoundError parser = all_parsers path = "%s.csv" % tm.rands(10) msg = ("does not exist" if parser.engine == "c" else r"\[Errno 2\]") with pytest.raises(compat.FileNotFoundError, match=msg) as e: parser.read_csv(path) filename = e.value.filename filename = filename.decode() if isinstance( filename, bytes) else filename assert path == filename
Example #3
Source File: test_format.py From recruit with Apache License 2.0 | 6 votes |
def test_repr_truncation(self): max_len = 20 with option_context("display.max_colwidth", max_len): df = DataFrame({'A': np.random.randn(10), 'B': [tm.rands(np.random.randint( max_len - 1, max_len + 1)) for i in range(10) ]}) r = repr(df) r = r[r.find('\n') + 1:] adj = fmt._get_adjustment() for line, value in lzip(r.split('\n'), df['B']): if adj.len(value) + 1 > max_len: assert '...' in line else: assert '...' not in line with option_context("display.max_colwidth", 999999): assert '...' not in repr(df) with option_context("display.max_colwidth", max_len + 2): assert '...' not in repr(df)
Example #4
Source File: test_common.py From recruit with Apache License 2.0 | 6 votes |
def test_nonexistent_path(all_parsers): # gh-2428: pls no segfault # gh-14086: raise more helpful FileNotFoundError parser = all_parsers path = "%s.csv" % tm.rands(10) msg = ("does not exist" if parser.engine == "c" else r"\[Errno 2\]") with pytest.raises(compat.FileNotFoundError, match=msg) as e: parser.read_csv(path) filename = e.value.filename filename = filename.decode() if isinstance( filename, bytes) else filename assert path == filename
Example #5
Source File: test_format.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_repr_truncation(self): max_len = 20 with option_context("display.max_colwidth", max_len): df = DataFrame({'A': np.random.randn(10), 'B': [tm.rands(np.random.randint( max_len - 1, max_len + 1)) for i in range(10) ]}) r = repr(df) r = r[r.find('\n') + 1:] adj = fmt._get_adjustment() for line, value in lzip(r.split('\n'), df['B']): if adj.len(value) + 1 > max_len: assert '...' in line else: assert '...' not in line with option_context("display.max_colwidth", 999999): assert '...' not in repr(df) with option_context("display.max_colwidth", max_len + 2): assert '...' not in repr(df)
Example #6
Source File: test_operators.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_timestamp_compare(self): # make sure we can compare Timestamps on the right AND left hand side # GH4982 df = DataFrame({'dates1': date_range('20010101', periods=10), 'dates2': date_range('20010102', periods=10), 'intcol': np.random.randint(1000000000, size=10), 'floatcol': np.random.randn(10), 'stringcol': list(tm.rands(10))}) df.loc[np.random.rand(len(df)) > 0.5, 'dates2'] = pd.NaT ops = {'gt': 'lt', 'lt': 'gt', 'ge': 'le', 'le': 'ge', 'eq': 'eq', 'ne': 'ne'} for left, right in ops.items(): left_f = getattr(operator, left) right_f = getattr(operator, right) # no nats expected = left_f(df, Timestamp('20010109')) result = right_f(Timestamp('20010109'), df) assert_frame_equal(result, expected) # nats expected = left_f(df, Timestamp('nat')) result = right_f(Timestamp('nat'), df) assert_frame_equal(result, expected)
Example #7
Source File: test_operators.py From vnpy_crypto with MIT License | 6 votes |
def test_timestamp_compare(self): # make sure we can compare Timestamps on the right AND left hand side # GH4982 df = DataFrame({'dates1': date_range('20010101', periods=10), 'dates2': date_range('20010102', periods=10), 'intcol': np.random.randint(1000000000, size=10), 'floatcol': np.random.randn(10), 'stringcol': list(tm.rands(10))}) df.loc[np.random.rand(len(df)) > 0.5, 'dates2'] = pd.NaT ops = {'gt': 'lt', 'lt': 'gt', 'ge': 'le', 'le': 'ge', 'eq': 'eq', 'ne': 'ne'} for left, right in ops.items(): left_f = getattr(operator, left) right_f = getattr(operator, right) # no nats expected = left_f(df, Timestamp('20010109')) result = right_f(Timestamp('20010109'), df) assert_frame_equal(result, expected) # nats expected = left_f(df, Timestamp('nat')) result = right_f(Timestamp('nat'), df) assert_frame_equal(result, expected)
Example #8
Source File: test_format.py From vnpy_crypto with MIT License | 6 votes |
def test_repr_truncation(self): max_len = 20 with option_context("display.max_colwidth", max_len): df = DataFrame({'A': np.random.randn(10), 'B': [tm.rands(np.random.randint( max_len - 1, max_len + 1)) for i in range(10) ]}) r = repr(df) r = r[r.find('\n') + 1:] adj = fmt._get_adjustment() for line, value in lzip(r.split('\n'), df['B']): if adj.len(value) + 1 > max_len: assert '...' in line else: assert '...' not in line with option_context("display.max_colwidth", 999999): assert '...' not in repr(df) with option_context("display.max_colwidth", max_len + 2): assert '...' not in repr(df)
Example #9
Source File: test_operators.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_timestamp_compare(self): # make sure we can compare Timestamps on the right AND left hand side # GH4982 df = DataFrame({'dates1': date_range('20010101', periods=10), 'dates2': date_range('20010102', periods=10), 'intcol': np.random.randint(1000000000, size=10), 'floatcol': np.random.randn(10), 'stringcol': list(tm.rands(10))}) df.loc[np.random.rand(len(df)) > 0.5, 'dates2'] = pd.NaT ops = {'gt': 'lt', 'lt': 'gt', 'ge': 'le', 'le': 'ge', 'eq': 'eq', 'ne': 'ne'} for left, right in ops.items(): left_f = getattr(operator, left) right_f = getattr(operator, right) # no nats expected = left_f(df, Timestamp('20010109')) result = right_f(Timestamp('20010109'), df) assert_frame_equal(result, expected) # nats expected = left_f(df, Timestamp('nat')) result = right_f(Timestamp('nat'), df) assert_frame_equal(result, expected)
Example #10
Source File: test_format.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_repr_truncation(self): max_len = 20 with option_context("display.max_colwidth", max_len): df = DataFrame({'A': np.random.randn(10), 'B': [tm.rands(np.random.randint( max_len - 1, max_len + 1)) for i in range(10) ]}) r = repr(df) r = r[r.find('\n') + 1:] adj = fmt._get_adjustment() for line, value in lzip(r.split('\n'), df['B']): if adj.len(value) + 1 > max_len: assert '...' in line else: assert '...' not in line with option_context("display.max_colwidth", 999999): assert '...' not in repr(df) with option_context("display.max_colwidth", max_len + 2): assert '...' not in repr(df)
Example #11
Source File: test_pickle.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def get_random_path(): return u'__%s__.pickle' % tm.rands(10)
Example #12
Source File: test_common.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_internal_eof_byte_to_file(all_parsers): # see gh-16559 parser = all_parsers data = b'c1,c2\r\n"test \x1a test", test\r\n' expected = DataFrame([["test \x1a test", " test"]], columns=["c1", "c2"]) path = "__%s__.csv" % tm.rands(10) with tm.ensure_clean(path) as path: with open(path, "wb") as f: f.write(data) result = parser.read_csv(path) tm.assert_frame_equal(result, expected)
Example #13
Source File: test_pickle.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def get_random_path(): return u'__%s__.pickle' % tm.rands(10)
Example #14
Source File: test_packers.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def setup_method(self, method): self.path = '__%s__.msg' % tm.rands(10)
Example #15
Source File: test_dtypes.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_astype_unicode(self): # see gh-7758: A bit of magic is required to set # default encoding to utf-8 digits = string.digits test_series = [ Series([digits * 10, tm.rands(63), tm.rands(64), tm.rands(1000)]), Series([u('データーサイエンス、お前はもう死んでいる')]), ] former_encoding = None if not compat.PY3: # In Python, we can force the default encoding for this test former_encoding = sys.getdefaultencoding() reload(sys) # noqa sys.setdefaultencoding("utf-8") if sys.getdefaultencoding() == "utf-8": test_series.append(Series([u('野菜食べないとやばい') .encode("utf-8")])) for s in test_series: res = s.astype("unicode") expec = s.map(compat.text_type) tm.assert_series_equal(res, expec) # Restore the former encoding if former_encoding is not None and former_encoding != "utf-8": reload(sys) # noqa sys.setdefaultencoding(former_encoding)
Example #16
Source File: test_util.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_rands(): r = tm.rands(10) assert(len(r) == 10)
Example #17
Source File: common.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_nonexistent_path(self): # gh-2428: pls no segfault # gh-14086: raise more helpful FileNotFoundError path = '%s.csv' % tm.rands(10) pytest.raises(compat.FileNotFoundError, self.read_csv, path)
Example #18
Source File: common.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_internal_eof_byte_to_file(self): # see gh-16559 data = b'c1,c2\r\n"test \x1a test", test\r\n' expected = pd.DataFrame([["test \x1a test", " test"]], columns=["c1", "c2"]) path = '__%s__.csv' % tm.rands(10) with tm.ensure_clean(path) as path: with open(path, "wb") as f: f.write(data) result = self.read_csv(path) tm.assert_frame_equal(result, expected)
Example #19
Source File: test_dtypes.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_astype_unicode(self): # see gh-7758: A bit of magic is required to set # default encoding to utf-8 digits = string.digits test_series = [ Series([digits * 10, tm.rands(63), tm.rands(64), tm.rands(1000)]), Series([u('データーサイエンス、お前はもう死んでいる')]), ] former_encoding = None if not compat.PY3: # In Python, we can force the default encoding for this test former_encoding = sys.getdefaultencoding() reload(sys) # noqa sys.setdefaultencoding("utf-8") if sys.getdefaultencoding() == "utf-8": test_series.append(Series([u('野菜食べないとやばい') .encode("utf-8")])) for s in test_series: res = s.astype("unicode") expec = s.map(compat.text_type) tm.assert_series_equal(res, expec) # Restore the former encoding if former_encoding is not None and former_encoding != "utf-8": reload(sys) # noqa sys.setdefaultencoding(former_encoding)
Example #20
Source File: test_packers.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def setup_method(self, method): self.path = '__%s__.msg' % tm.rands(10)
Example #21
Source File: test_dtypes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_astype_unicode(self): # see gh-7758: A bit of magic is required to set # default encoding to utf-8 digits = string.digits test_series = [ Series([digits * 10, tm.rands(63), tm.rands(64), tm.rands(1000)]), Series([u('データーサイエンス、お前はもう死んでいる')]), ] former_encoding = None if not compat.PY3: # In Python, we can force the default encoding for this test former_encoding = sys.getdefaultencoding() reload(sys) # noqa sys.setdefaultencoding("utf-8") if sys.getdefaultencoding() == "utf-8": test_series.append(Series([u('野菜食べないとやばい') .encode("utf-8")])) for s in test_series: res = s.astype("unicode") expec = s.map(compat.text_type) tm.assert_series_equal(res, expec) # Restore the former encoding if former_encoding is not None and former_encoding != "utf-8": reload(sys) # noqa sys.setdefaultencoding(former_encoding)
Example #22
Source File: test_util.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_rands(): r = tm.rands(10) assert(len(r) == 10)
Example #23
Source File: common.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_nonexistent_path(self): # gh-2428: pls no segfault # gh-14086: raise more helpful FileNotFoundError path = '%s.csv' % tm.rands(10) pytest.raises(compat.FileNotFoundError, self.read_csv, path)
Example #24
Source File: common.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_internal_eof_byte_to_file(self): # see gh-16559 data = b'c1,c2\r\n"test \x1a test", test\r\n' expected = pd.DataFrame([["test \x1a test", " test"]], columns=["c1", "c2"]) path = '__%s__.csv' % tm.rands(10) with tm.ensure_clean(path) as path: with open(path, "wb") as f: f.write(data) result = self.read_csv(path) tm.assert_frame_equal(result, expected)
Example #25
Source File: test_pickle.py From vnpy_crypto with MIT License | 5 votes |
def get_random_path(): return u'__%s__.pickle' % tm.rands(10)
Example #26
Source File: test_arithmetic.py From recruit with Apache License 2.0 | 5 votes |
def test_timestamp_compare(self): # make sure we can compare Timestamps on the right AND left hand side # GH#4982 df = pd. DataFrame({'dates1': pd.date_range('20010101', periods=10), 'dates2': pd.date_range('20010102', periods=10), 'intcol': np.random.randint(1000000000, size=10), 'floatcol': np.random.randn(10), 'stringcol': list(tm.rands(10))}) df.loc[np.random.rand(len(df)) > 0.5, 'dates2'] = pd.NaT ops = {'gt': 'lt', 'lt': 'gt', 'ge': 'le', 'le': 'ge', 'eq': 'eq', 'ne': 'ne'} for left, right in ops.items(): left_f = getattr(operator, left) right_f = getattr(operator, right) # no nats if left in ['eq', 'ne']: expected = left_f(df, pd.Timestamp('20010109')) result = right_f(pd.Timestamp('20010109'), df) tm.assert_frame_equal(result, expected) else: with pytest.raises(TypeError): left_f(df, pd.Timestamp('20010109')) with pytest.raises(TypeError): right_f(pd.Timestamp('20010109'), df) # nats expected = left_f(df, pd.Timestamp('nat')) result = right_f(pd.Timestamp('nat'), df) tm.assert_frame_equal(result, expected)
Example #27
Source File: test_util.py From recruit with Apache License 2.0 | 5 votes |
def test_rands(): r = tm.rands(10) assert len(r) == 10
Example #28
Source File: test_common.py From recruit with Apache License 2.0 | 5 votes |
def test_internal_eof_byte_to_file(all_parsers): # see gh-16559 parser = all_parsers data = b'c1,c2\r\n"test \x1a test", test\r\n' expected = DataFrame([["test \x1a test", " test"]], columns=["c1", "c2"]) path = "__%s__.csv" % tm.rands(10) with tm.ensure_clean(path) as path: with open(path, "wb") as f: f.write(data) result = parser.read_csv(path) tm.assert_frame_equal(result, expected)
Example #29
Source File: test_pickle.py From recruit with Apache License 2.0 | 5 votes |
def get_random_path(): return u'__%s__.pickle' % tm.rands(10)
Example #30
Source File: test_packers.py From recruit with Apache License 2.0 | 5 votes |
def setup_method(self, method): self.path = '__%s__.msg' % tm.rands(10)