Python pandas.__version__() Examples
The following are 30
code examples of pandas.__version__().
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
, or try the search function
.
Example #1
Source File: test_series.py From koalas with Apache License 2.0 | 6 votes |
def test_repeat(self): pser = pd.Series(["a", "b", "c"], name="0", index=np.random.rand(3)) kser = ks.from_pandas(pser) self.assert_eq(kser.repeat(3).sort_index(), pser.repeat(3).sort_index()) self.assert_eq(kser.repeat(0).sort_index(), pser.repeat(0).sort_index()) self.assertRaises(ValueError, lambda: kser.repeat(-1)) self.assertRaises(ValueError, lambda: kser.repeat("abc")) pdf = pd.DataFrame({"a": ["a", "b", "c"], "rep": [10, 20, 30]}, index=np.random.rand(3)) kdf = ks.from_pandas(pdf) if LooseVersion(pyspark.__version__) < LooseVersion("2.4"): self.assertRaises(ValueError, lambda: kdf.a.repeat(kdf.rep)) else: self.assert_eq(kdf.a.repeat(kdf.rep).sort_index(), pdf.a.repeat(pdf.rep).sort_index())
Example #2
Source File: generate_legacy_storage_files.py From recruit with Apache License 2.0 | 6 votes |
def write_legacy_pickles(output_dir): # make sure we are < 0.13 compat (in py3) try: from pandas.compat import zip, cPickle as pickle # noqa except ImportError: import pickle version = pandas.__version__ print("This script generates a storage file for the current arch, system, " "and python version") print(" pandas version: {0}".format(version)) print(" output dir : {0}".format(output_dir)) print(" storage format: pickle") pth = '{0}.pickle'.format(platform_name()) fh = open(os.path.join(output_dir, pth), 'wb') pickle.dump(create_pickle_data(), fh, pickle.HIGHEST_PROTOCOL) fh.close() print("created pickle file: %s" % pth)
Example #3
Source File: generate_legacy_storage_files.py From vnpy_crypto with MIT License | 6 votes |
def write_legacy_pickles(output_dir): # make sure we are < 0.13 compat (in py3) try: from pandas.compat import zip, cPickle as pickle # noqa except: import pickle version = pandas.__version__ print("This script generates a storage file for the current arch, system, " "and python version") print(" pandas version: {0}".format(version)) print(" output dir : {0}".format(output_dir)) print(" storage format: pickle") pth = '{0}.pickle'.format(platform_name()) fh = open(os.path.join(output_dir, pth), 'wb') pickle.dump(create_pickle_data(), fh, pickle.HIGHEST_PROTOCOL) fh.close() print("created pickle file: %s" % pth)
Example #4
Source File: test_pytables.py From Computable with MIT License | 6 votes |
def test_open_args(self): with ensure_clean_path(self.path) as path: df = tm.makeDataFrame() # create an in memory store store = HDFStore(path,mode='a',driver='H5FD_CORE',driver_core_backing_store=0) store['df'] = df store.append('df2',df) tm.assert_frame_equal(store['df'],df) tm.assert_frame_equal(store['df2'],df) store.close() # only supported on pytable >= 3.0.0 if LooseVersion(tables.__version__) >= '3.0.0': # the file should not have actually been written self.assert_(os.path.exists(path) is False)
Example #5
Source File: test_pytables.py From Computable with MIT License | 6 votes |
def test_encoding(self): if LooseVersion(tables.__version__) < '3.0.0': raise nose.SkipTest('tables version does not support proper encoding') if sys.byteorder != 'little': raise nose.SkipTest('system byteorder is not little') with ensure_clean_store(self.path) as store: df = DataFrame(dict(A='foo',B='bar'),index=range(5)) df.loc[2,'A'] = np.nan df.loc[3,'B'] = np.nan _maybe_remove(store, 'df') store.append('df', df, encoding='ascii') tm.assert_frame_equal(store['df'], df) expected = df.reindex(columns=['A']) result = store.select('df',Term('columns=A',encoding='ascii')) tm.assert_frame_equal(result,expected)
Example #6
Source File: test_pytables.py From Computable with MIT License | 6 votes |
def test_legacy_table_write(self): raise nose.SkipTest("skipping for now") store = HDFStore(tm.get_data_path('legacy_hdf/legacy_table_%s.h5' % pandas.__version__), 'a') df = tm.makeDataFrame() wp = tm.makePanel() index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'], ['one', 'two', 'three']], labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]], names=['foo', 'bar']) df = DataFrame(np.random.randn(10, 3), index=index, columns=['A', 'B', 'C']) store.append('mi', df) df = DataFrame(dict(A = 'foo', B = 'bar'),index=lrange(10)) store.append('df', df, data_columns = ['B'], min_itemsize={'A' : 200 }) store.append('wp', wp) store.close()
Example #7
Source File: generate_legacy_storage_files.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def write_legacy_pickles(output_dir): # make sure we are < 0.13 compat (in py3) try: from pandas.compat import zip, cPickle as pickle # noqa except ImportError: import pickle version = pandas.__version__ print("This script generates a storage file for the current arch, system, " "and python version") print(" pandas version: {0}".format(version)) print(" output dir : {0}".format(output_dir)) print(" storage format: pickle") pth = '{0}.pickle'.format(platform_name()) fh = open(os.path.join(output_dir, pth), 'wb') pickle.dump(create_pickle_data(), fh, pickle.HIGHEST_PROTOCOL) fh.close() print("created pickle file: %s" % pth)
Example #8
Source File: utils.py From LearningApacheSpark with MIT License | 6 votes |
def require_minimum_pandas_version(): """ Raise ImportError if minimum version of Pandas is not installed """ # TODO(HyukjinKwon): Relocate and deduplicate the version specification. minimum_pandas_version = "0.19.2" from distutils.version import LooseVersion try: import pandas have_pandas = True except ImportError: have_pandas = False if not have_pandas: raise ImportError("Pandas >= %s must be installed; however, " "it was not found." % minimum_pandas_version) if LooseVersion(pandas.__version__) < LooseVersion(minimum_pandas_version): raise ImportError("Pandas >= %s must be installed; however, " "your version was %s." % (minimum_pandas_version, pandas.__version__))
Example #9
Source File: utils.py From LearningApacheSpark with MIT License | 6 votes |
def require_minimum_pyarrow_version(): """ Raise ImportError if minimum version of pyarrow is not installed """ # TODO(HyukjinKwon): Relocate and deduplicate the version specification. minimum_pyarrow_version = "0.8.0" from distutils.version import LooseVersion try: import pyarrow have_arrow = True except ImportError: have_arrow = False if not have_arrow: raise ImportError("PyArrow >= %s must be installed; however, " "it was not found." % minimum_pyarrow_version) if LooseVersion(pyarrow.__version__) < LooseVersion(minimum_pyarrow_version): raise ImportError("PyArrow >= %s must be installed; however, " "your version was %s." % (minimum_pyarrow_version, pyarrow.__version__))
Example #10
Source File: logic.py From quantipy with MIT License | 6 votes |
def _symmetric_difference(idxs): """ Returns the chained symmetrical difference of the indexes given. Parameters ---------- idxs : list List of pandas.Index objects. Returns ------- idx : pandas.Index The result of the chained symmetrical difference of the indexes given. """ idx = idxs[0] for idx_part in idxs[1:]: if pd.__version__ == '0.19.2': idx = idx.symmetric_difference(idx_part) else: idx = idx.sym_diff(idx_part) return idx
Example #11
Source File: gbq.py From pandas-gbq with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _make_bqstorage_client(use_bqstorage_api, credentials): if not use_bqstorage_api: return None if bigquery_storage_v1beta1 is None: raise ImportError( "Install the google-cloud-bigquery-storage and fastavro/pyarrow " "packages to use the BigQuery Storage API." ) import google.api_core.gapic_v1.client_info import pandas client_info = google.api_core.gapic_v1.client_info.ClientInfo( user_agent="pandas-{}".format(pandas.__version__) ) return bigquery_storage_v1beta1.BigQueryStorageClient( credentials=credentials, client_info=client_info )
Example #12
Source File: test_dataframe.py From koalas with Apache License 2.0 | 6 votes |
def test_rfloordiv(self): pdf = pd.DataFrame( {"angles": [0, 3, 4], "degrees": [360, 180, 360]}, index=["circle", "triangle", "rectangle"], columns=["angles", "degrees"], ) kdf = ks.from_pandas(pdf) if LooseVersion(pd.__version__) < LooseVersion("1.0.0") and LooseVersion( pd.__version__ ) >= LooseVersion("0.24.0"): expected_result = pd.DataFrame( {"angles": [np.inf, 3.0, 2.0], "degrees": [0.0, 0.0, 0.0]}, index=["circle", "triangle", "rectangle"], columns=["angles", "degrees"], ) else: expected_result = pdf.rfloordiv(10) self.assert_eq(kdf.rfloordiv(10), expected_result)
Example #13
Source File: test_reshape.py From koalas with Apache License 2.0 | 6 votes |
def test_get_dummies_dtype(self): pdf = pd.DataFrame( { # "A": pd.Categorical(['a', 'b', 'a'], categories=['a', 'b', 'c']), "A": ["a", "b", "a"], "B": [0, 0, 1], } ) kdf = ks.from_pandas(pdf) if LooseVersion("0.23.0") <= LooseVersion(pd.__version__): exp = pd.get_dummies(pdf, dtype="float64") else: exp = pd.get_dummies(pdf) exp = exp.astype({"A_a": "float64", "A_b": "float64"}) res = ks.get_dummies(kdf, dtype="float64") self.assert_eq(res, exp, almost=True)
Example #14
Source File: generate_legacy_storage_files.py From recruit with Apache License 2.0 | 5 votes |
def write_legacy_msgpack(output_dir, compress): version = pandas.__version__ print("This script generates a storage file for the current arch, " "system, and python version") print(" pandas version: {0}".format(version)) print(" output dir : {0}".format(output_dir)) print(" storage format: msgpack") pth = '{0}.msgpack'.format(platform_name()) to_msgpack(os.path.join(output_dir, pth), create_msgpack_data(), compress=compress) print("created msgpack file: %s" % pth)
Example #15
Source File: test_indexes.py From koalas with Apache License 2.0 | 5 votes |
def test_multi_index_names(self): arrays = [[1, 1, 2, 2], ["red", "blue", "red", "blue"]] idx = pd.MultiIndex.from_arrays(arrays, names=("number", "color")) pdf = pd.DataFrame(np.random.randn(4, 5), idx) kdf = ks.from_pandas(pdf) self.assertEqual(kdf.index.names, pdf.index.names) pidx = pdf.index kidx = kdf.index pidx.names = ["renamed_number", "renamed_color"] kidx.names = ["renamed_number", "renamed_color"] self.assertEqual(kidx.names, pidx.names) pidx.names = ["renamed_number", None] kidx.names = ["renamed_number", None] self.assertEqual(kidx.names, pidx.names) if LooseVersion(pyspark.__version__) < LooseVersion("2.4"): # PySpark < 2.4 does not support struct type with arrow enabled. with self.sql_conf({"spark.sql.execution.arrow.enabled": False}): self.assert_eq(kidx, pidx) else: self.assert_eq(kidx, pidx) with self.assertRaises(PandasNotImplementedError): kidx.name with self.assertRaises(PandasNotImplementedError): kidx.name = "renamed"
Example #16
Source File: testplotting.py From hvplot with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): if LooseVersion(pd.__version__) < '0.25.1': raise SkipTest('entrypoints for plotting.backends was added ' 'in pandas 0.25.1') pd.options.plotting.backend = 'holoviews'
Example #17
Source File: __init__.py From psyplot with GNU General Public License v2.0 | 5 votes |
def _get_versions(requirements=True): if requirements: import matplotlib as mpl import xarray as xr import pandas as pd import numpy as np return {'version': __version__, 'requirements': {'matplotlib': mpl.__version__, 'xarray': xr.__version__, 'pandas': pd.__version__, 'numpy': np.__version__, 'python': ' '.join(sys.version.splitlines())}} else: return {'version': __version__}
Example #18
Source File: test_requirements.py From ebonite with Apache License 2.0 | 5 votes |
def test_installable_requirement__from_module(): import pandas as pd assert InstallableRequirement.from_module(pd).to_str() == f'pandas=={pd.__version__}' import numpy as np assert InstallableRequirement.from_module(np).to_str() == f'numpy=={np.__version__}' import sklearn as sk assert InstallableRequirement.from_module(sk).to_str() == f'scikit-learn=={sk.__version__}' assert InstallableRequirement.from_module(sk, 'xyz').to_str() == f'xyz=={sk.__version__}'
Example #19
Source File: run_test.py From deepchem with MIT License | 5 votes |
def test_rdkit_import(self): import rdkit print(rdkit.__version__)
Example #20
Source File: gbq.py From pandas-gbq with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_client(self): import pandas try: # This module was added in google-api-core 1.11.0. # We don't have a hard requirement on that version, so only # populate the client_info if available. import google.api_core.client_info client_info = google.api_core.client_info.ClientInfo( user_agent="pandas-{}".format(pandas.__version__) ) except ImportError: client_info = None # In addition to new enough version of google-api-core, a new enough # version of google-cloud-bigquery is required to populate the # client_info. if HAS_CLIENT_INFO: return bigquery.Client( project=self.project_id, credentials=self.credentials, client_info=client_info, ) return bigquery.Client( project=self.project_id, credentials=self.credentials )
Example #21
Source File: test_gbq.py From pandas-gbq with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_GbqConnector_get_client_w_new_bq(mock_bigquery_client): gbq._test_google_api_imports() pytest.importorskip( "google.cloud.bigquery", minversion=gbq.BIGQUERY_CLIENT_INFO_VERSION ) pytest.importorskip("google.api_core.client_info") connector = _make_connector() connector.get_client() _, kwargs = mock_bigquery_client.call_args assert kwargs["client_info"].user_agent == "pandas-{}".format( pandas.__version__ )
Example #22
Source File: shibor.py From tushare with BSD 3-Clause "New" or "Revised" License | 5 votes |
def lpr_ma_data(year=None): """ 获取贷款基础利率均值数据 Parameters ------ year:年份(int) Return ------ date:日期 1Y_5:5日均值 1Y_10:10日均值 1Y_20:20日均值 """ year = du.get_year() if year is None else year lab = ct.SHIBOR_TYPE['LPR_Tendency'] lab = lab.encode('utf-8') if ct.PY3 else lab try: clt = Client(url=ct.SHIBOR_DATA_URL%(ct.P_TYPE['http'], ct.DOMAINS['shibor'], ct.PAGES['dw'], 'LPR_Tendency', year, lab, year)) content = clt.gvalue() df = pd.read_excel(StringIO(content), skiprows=[0]) df.columns = ct.LPR_MA_COLS df['date'] = df['date'].map(lambda x: x.date()) if pd.__version__ < '0.21': df['date'] = df['date'].astype(np.datetime64) else: df['date'] = df['date'].astype('datetime64[D]') return df except: return None
Example #23
Source File: shibor.py From tushare with BSD 3-Clause "New" or "Revised" License | 5 votes |
def lpr_data(year=None): """ 获取贷款基础利率(LPR) Parameters ------ year:年份(int) Return ------ date:日期 1Y:1年贷款基础利率 """ year = du.get_year() if year is None else year lab = ct.SHIBOR_TYPE['LPR'] lab = lab.encode('utf-8') if ct.PY3 else lab try: clt = Client(url=ct.SHIBOR_DATA_URL%(ct.P_TYPE['http'], ct.DOMAINS['shibor'], ct.PAGES['dw'], 'LPR', year, lab, year)) content = clt.gvalue() df = pd.read_excel(StringIO(content), skiprows=[0]) df.columns = ct.LPR_COLS df['date'] = df['date'].map(lambda x: x.date()) if pd.__version__ < '0.21': df['date'] = df['date'].astype(np.datetime64) else: df['date'] = df['date'].astype('datetime64[D]') return df except: return None
Example #24
Source File: shibor.py From tushare with BSD 3-Clause "New" or "Revised" License | 5 votes |
def shibor_ma_data(year=None): """ 获取Shibor均值数据 Parameters ------ year:年份(int) Return ------ date:日期 其它分别为各周期5、10、20均价 """ year = du.get_year() if year is None else year lab = ct.SHIBOR_TYPE['Tendency'] lab = lab.encode('utf-8') if ct.PY3 else lab try: clt = Client(url=ct.SHIBOR_DATA_URL%(ct.P_TYPE['http'], ct.DOMAINS['shibor'], ct.PAGES['dw'], 'Shibor_Tendency', year, lab, year)) content = clt.gvalue() df = pd.read_excel(StringIO(content), skiprows=[0]) df.columns = ct.SHIBOR_MA_COLS df['date'] = df['date'].map(lambda x: x.date()) if pd.__version__ < '0.21': df['date'] = df['date'].astype(np.datetime64) else: df['date'] = df['date'].astype('datetime64[D]') return df except: return None
Example #25
Source File: shibor.py From tushare with BSD 3-Clause "New" or "Revised" License | 5 votes |
def shibor_data(year=None): """ 获取上海银行间同业拆放利率(Shibor) Parameters ------ year:年份(int) Return ------ date:日期 ON:隔夜拆放利率 1W:1周拆放利率 2W:2周拆放利率 1M:1个月拆放利率 3M:3个月拆放利率 6M:6个月拆放利率 9M:9个月拆放利率 1Y:1年拆放利率 """ year = du.get_year() if year is None else year lab = ct.SHIBOR_TYPE['Shibor'] lab = lab.encode('utf-8') if ct.PY3 else lab try: clt = Client(url=ct.SHIBOR_DATA_URL%(ct.P_TYPE['http'], ct.DOMAINS['shibor'], ct.PAGES['dw'], 'Shibor', year, lab, year)) content = clt.gvalue() df = pd.read_excel(StringIO(content)) df.columns = ct.SHIBOR_COLS df['date'] = df['date'].map(lambda x: x.date()) if pd.__version__ < '0.21': df['date'] = df['date'].astype(np.datetime64) else: df['date'] = df['date'].astype('datetime64[D]') return df except: return None
Example #26
Source File: embedders.py From nodevectors with MIT License | 5 votes |
def save(self, filename: str): """ Saves model to a custom file format filename : str Name of file to save. Don't include filename extensions Extensions are added automatically File format is a zipfile with joblib dump (pickle-like) + dependency metata Metadata is checked on load. Includes validation and metadata to avoid Pickle deserialization gotchas See here Alex Gaynor PyCon 2014 talk "Pickles are for Delis" for more info on why we introduce this additional check """ if '.zip' in filename: raise UserWarning("The file extension '.zip' is automatically added" + " to saved models. The name will have redundant extensions") sysverinfo = sys.version_info meta_data = { "python_": f'{sysverinfo[0]}.{sysverinfo[1]}', "skl_": sklearn.__version__[:-2], "pd_": pd.__version__[:-2], "csrg_": cg.__version__[:-2] } with tempfile.TemporaryDirectory() as temp_dir: joblib.dump(self, os.path.join(temp_dir, self.f_model), compress=True) with open(os.path.join(temp_dir, self.f_mdata), 'w') as f: json.dump(meta_data, f) filename = shutil.make_archive(filename, 'zip', temp_dir)
Example #27
Source File: query.py From quantipy with MIT License | 5 votes |
def shake(l): """ De-dupe and reorder view keys in l for request_views. """ s = pd.Series(uniquify_list(l)) df = pd.DataFrame(s.str.split('|').tolist()) df.insert(0, 'view', s) if pd.__version__ == '0.19.2': df.sort_values(by=[2, 1], inplace=True) else: df.sort_index(by=[2, 1], inplace=True) return df
Example #28
Source File: prep.py From quantipy with MIT License | 5 votes |
def join_delimited_set_series(ds1, ds2, append=True): """ Item-wise join of two delimited sets. This function takes a mapper of {key: logic} entries and resolves the logic statements using the given meta/data to return a mapper of {key: index}. The indexes returned can be used on data to isolate the cases described by arbitrarily complex logical statements. Parameters ---------- ds1 : pandas.Series First delimited set series to join. ds2 : pandas.Series Second delimited set series to join. append : bool Should the data in ds2 (where found) be appended to items from ds1? If False, data from ds2 (where found) will overwrite whatever was found for that item in ds1 instead. Returns ------- joined : pandas.Series The joined result of ds1 and ds2. """ if pd.__version__ == '0.19.2': df = pd.concat([ds1, ds2], axis=1, ignore_index=True) else: df = pd.concat([ds1, ds2], axis=1) df.fillna('', inplace=True) if append: df['joined'] = df[0] + df[1] else: df['joined'] = df[0].copy() df[1] = df[1].replace('', np.NaN) df['joined'].update(df[1].dropna()) joined = df['joined'].replace('', np.NaN) return joined
Example #29
Source File: run_test.py From deepchem with MIT License | 5 votes |
def test_numpy_import(self): import numpy as np print(np.__version__)
Example #30
Source File: testplotting.py From hvplot with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): if LooseVersion(pd.__version__) < '0.25.1': raise SkipTest('entrypoints for plotting.backends was added ' 'in pandas 0.25.1') pd.options.plotting.backend = 'hvplot'