Python pandas.api.types.is_float_dtype() Examples
The following are 9
code examples of pandas.api.types.is_float_dtype().
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.api.types
, or try the search function
.
Example #1
Source File: scales.py From plotnine with GNU General Public License v2.0 | 6 votes |
def make_scale(ae, series, *args, **kwargs): """ Return a proper scale object for the series The scale is for the aesthetic ae, and args & kwargs are passed on to the scale creating class """ if pdtypes.is_float_dtype(series) and np.isinf(series).all(): raise PlotnineError("Cannot create scale for infinite data") stype = scale_type(series) # filter parameters by scale type if stype in ('discrete', 'ordinal'): with suppress(KeyError): del kwargs['trans'] scale_name = 'scale_{}_{}'.format(ae, stype) scale_klass = Registry[scale_name] return scale_klass(*args, **kwargs)
Example #2
Source File: test_create_ingest.py From cooler with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_cload_field(bins_path, pairs_path): kwargs = dict( metadata=None, assembly="toy", chunksize=10, zero_based=False, comment_char="#", input_copy_status="unique", no_symmetric_upper=False, temp_dir=None, no_delete_temp=False, storage_options=None, no_count=True, max_merge=200, chrom1=2, pos1=3, chrom2=4, pos2=5, ) cload_pairs.callback( bins_path, pairs_path, testcool_path, field=("score=8:dtype=float",), **kwargs ) pixels = cooler.Cooler(testcool_path).pixels()[:] assert "count" in pixels.columns and types.is_integer_dtype(pixels.dtypes["count"]) assert "score" in pixels.columns and types.is_float_dtype(pixels.dtypes["score"])
Example #3
Source File: test_integer.py From recruit with Apache License 2.0 | 5 votes |
def _check_op(self, s, op_name, other, exc=None): op = self.get_op_from_name(op_name) result = op(s, other) # compute expected mask = s.isna() # if s is a DataFrame, squeeze to a Series # for comparison if isinstance(s, pd.DataFrame): result = result.squeeze() s = s.squeeze() mask = mask.squeeze() # other array is an Integer if isinstance(other, IntegerArray): omask = getattr(other, 'mask', None) mask = getattr(other, 'data', other) if omask is not None: mask |= omask # 1 ** na is na, so need to unmask those if op_name == '__pow__': mask = np.where(s == 1, False, mask) elif op_name == '__rpow__': mask = np.where(other == 1, False, mask) # float result type or float op if ((is_float_dtype(other) or is_float(other) or op_name in ['__rtruediv__', '__truediv__', '__rdiv__', '__div__'])): rs = s.astype('float') expected = op(rs, other) self._check_op_float(result, expected, mask, s, op_name, other) # integer result type else: rs = pd.Series(s.values._data) expected = op(rs, other) self._check_op_integer(result, expected, mask, s, op_name, other)
Example #4
Source File: test_integer.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def _check_op(self, s, op_name, other, exc=None): op = self.get_op_from_name(op_name) result = op(s, other) # compute expected mask = s.isna() # if s is a DataFrame, squeeze to a Series # for comparison if isinstance(s, pd.DataFrame): result = result.squeeze() s = s.squeeze() mask = mask.squeeze() # other array is an Integer if isinstance(other, IntegerArray): omask = getattr(other, 'mask', None) mask = getattr(other, 'data', other) if omask is not None: mask |= omask # 1 ** na is na, so need to unmask those if op_name == '__pow__': mask = np.where(s == 1, False, mask) elif op_name == '__rpow__': mask = np.where(other == 1, False, mask) # float result type or float op if ((is_float_dtype(other) or is_float(other) or op_name in ['__rtruediv__', '__truediv__', '__rdiv__', '__div__'])): rs = s.astype('float') expected = op(rs, other) self._check_op_float(result, expected, mask, s, op_name, other) # integer result type else: rs = pd.Series(s.values._data) expected = op(rs, other) self._check_op_integer(result, expected, mask, s, op_name, other)
Example #5
Source File: test_dataframe.py From direct-access-py with MIT License | 5 votes |
def test_dataframe(): d2 = DirectAccessV2( api_key=DIRECTACCESS_API_KEY, client_id=DIRECTACCESS_CLIENT_ID, client_secret=DIRECTACCESS_CLIENT_SECRET, access_token=DIRECTACCESS_TOKEN, ) df = d2.to_dataframe("rigs", pagesize=10000, deleteddate="null") # Check index is set to API endpoint "primary key" assert df.index.name == "RigID" # Check datetime64 dtypes assert is_datetime64_ns_dtype(df.CreatedDate) assert is_datetime64_ns_dtype(df.DeletedDate) assert is_datetime64_ns_dtype(df.SpudDate) assert is_datetime64_ns_dtype(df.UpdatedDate) # Check Int64 dtypes assert is_int64_dtype(df.PermitDepth) assert is_int64_dtype(df.FormationDepth) # Check float dtypes assert is_float_dtype(df.RigLatitudeWGS84) assert is_float_dtype(df.RigLongitudeWGS84) return
Example #6
Source File: test_cli_ingest.py From cooler with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_load_field(): runner = CliRunner() with runner.isolated_filesystem(): extra_args = ["--field", "count=7:dtype=float"] result = _run_load(runner, "toy.symm.upper.2.bg2", "bg2", 2, extra_args) assert result.exit_code == 0 pixels1 = cooler.Cooler(op.join(datadir, "toy.symm.upper.2.cool")).pixels()[:] pixels2 = cooler.Cooler("toy.2.cool").pixels()[:] assert "count" in pixels2.columns and types.is_float_dtype( pixels2.dtypes["count"] ) assert np.allclose(pixels1["count"][:], pixels2["count"][:])
Example #7
Source File: test_cli_ingest.py From cooler with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_load_field2(): runner = CliRunner() with runner.isolated_filesystem(): extra_args = ["--count-as-float"] result = _run_load(runner, "toy.symm.upper.2.bg2", "bg2", 2, extra_args) assert result.exit_code == 0 pixels1 = cooler.Cooler(op.join(datadir, "toy.symm.upper.2.cool")).pixels()[:] pixels2 = cooler.Cooler("toy.2.cool").pixels()[:] assert "count" in pixels2.columns and types.is_float_dtype( pixels2.dtypes["count"] ) assert np.allclose(pixels1["count"][:], pixels2["count"][:])
Example #8
Source File: test_integer.py From coffeegrindsize with MIT License | 5 votes |
def _check_op(self, s, op_name, other, exc=None): op = self.get_op_from_name(op_name) result = op(s, other) # compute expected mask = s.isna() # if s is a DataFrame, squeeze to a Series # for comparison if isinstance(s, pd.DataFrame): result = result.squeeze() s = s.squeeze() mask = mask.squeeze() # other array is an Integer if isinstance(other, IntegerArray): omask = getattr(other, 'mask', None) mask = getattr(other, 'data', other) if omask is not None: mask |= omask # 1 ** na is na, so need to unmask those if op_name == '__pow__': mask = np.where(s == 1, False, mask) elif op_name == '__rpow__': mask = np.where(other == 1, False, mask) # float result type or float op if ((is_float_dtype(other) or is_float(other) or op_name in ['__rtruediv__', '__truediv__', '__rdiv__', '__div__'])): rs = s.astype('float') expected = op(rs, other) self._check_op_float(result, expected, mask, s, op_name, other) # integer result type else: rs = pd.Series(s.values._data) expected = op(rs, other) self._check_op_integer(result, expected, mask, s, op_name, other)
Example #9
Source File: test_cli_ingest.py From cooler with BSD 3-Clause "New" or "Revised" License | 4 votes |
def test_cload_field(): runner = CliRunner() with runner.isolated_filesystem(): extra_args = ["--field", "score=8"] result = _run_cload_pairs(runner, 2, extra_args) assert result.exit_code == 0 pixels = cooler.Cooler("toy.2.cool").pixels()[:] assert "count" in pixels.columns and types.is_integer_dtype( pixels.dtypes["count"] ) assert "score" in pixels.columns and types.is_float_dtype( pixels.dtypes["score"] ) extra_args = ["--field", "count=8"] result = _run_cload_pairs(runner, 2, extra_args) assert result.exit_code == 0 pixels = cooler.Cooler("toy.2.cool").pixels()[:] assert "count" in pixels.columns and types.is_integer_dtype( pixels.dtypes["count"] ) assert np.allclose(pixels["count"][:], 0) extra_args = ["--field", "count=8:dtype=float"] result = _run_cload_pairs(runner, 2, extra_args) assert result.exit_code == 0 pixels = cooler.Cooler("toy.2.cool").pixels()[:] assert "count" in pixels.columns and types.is_float_dtype( pixels.dtypes["count"] ) assert np.allclose(pixels["count"][:], 0.2) extra_args = ["--field", "count=8:agg=min,dtype=float"] result = _run_cload_pairs(runner, 2, extra_args) assert result.exit_code == 0 pixels = cooler.Cooler("toy.2.cool").pixels()[:] assert "count" in pixels.columns and types.is_float_dtype( pixels.dtypes["count"] ) assert np.allclose(pixels["count"][:], 0.1) ## don't implement the --no-count for now # extra_args = ['--field', 'score=7:dtype=float', '--no-count'] # result = _run_cload_pairs(runner, 2, extra_args) # assert result.exit_code == 0 # pixels = cooler.Cooler('toy.2.cool').pixels()[:] # assert 'count' not in pixels.columns # assert 'score' in pixels.columns and types.is_float_dtype(pixels.dtypes['score']) # '--metadata', '', # '--zero-based', # '--comment-char', '', # '--storage-options', '',