coercion

MySQL query using 'in' operator: why different results w/ quotes?

让人想犯罪 __ 提交于 2019-12-10 20:20:42
问题 I've tracked down a weird MySQL problem to the two different ways I was performing a query. When you boil everything down, this way returns more results: SELECT DISTINCT <stuff> FROM <tables> WHERE promo_detail_store_id in (8214, 8217, 4952, 8194, ...) This change to the WHERE clause produces a subset of those results: WHERE promo_detail_store_id in ('8214, 8217, 4952, 8194, ...') (promo_detail_store_id is defined as a BIGINT in a MyISAM table.) Originally that list of store_ids was much

Why does Pandas coerce my numpy float32 to float64?

牧云@^-^@ 提交于 2019-12-07 04:11:46
问题 Why does Pandas coerce my numpy float32 to float64 in this piece of code: >>> import pandas as pd >>> import numpy as np >>> df = pd.DataFrame([[1, 2, 'a'], [3, 4, 'b']], dtype=np.float32) >>> A = df.ix[:, 0:1].values >>> df.ix[:, 0:1] = A >>> df[0].dtype dtype('float64') The behavior seems so odd to me that wonder if it is a bug. I am on Pandas version 0.17.1 (updated PyPI version) and I note there has been coercing bugs recently addressed, see https://github.com/pydata/pandas/issues/11847 .

How do I make Binding respect DependencyProperty value coercion?

无人久伴 提交于 2019-12-06 19:21:12
问题 I have a control with a DependencyProperty with a CoerceValueCallback. This property is bound to a property on a model object. When setting the control property to a value that causes coercion the Binding pushes the uncoerced value to the model object. The property value on the control is coerced correctly. How do I get the Binding to push the coerced value to the model object? void Initialize() { UIObject ui = new UIObject(); ModelObject m = new ModelObject(); m.P = 4; Binding b = new

Path::Class::File or ::Dir & Moose initialiazation and coercion

不打扰是莪最后的温柔 提交于 2019-12-06 06:47:16
问题 Currently have: package Local; use warnings; use Moose; use Method::Signatures::Simple; use Path::Class::File; use Path::Class::Dir; method _build_path_class { my $str = $self->pathstr; return Path::Class::Dir->new($str) if (-d $str); return Path::Class::File->new($str); } has 'pathstr' => (is => 'rw', isa => 'Str', required => 1); has 'path' => ( is => 'rw', lazy => 1, #isa => 'Path::Class::File|Path::Class::Dir', #this didn't work isa => 'Object', builder => '_build_path_class', ); no Moose

Symbol string coercion

谁都会走 提交于 2019-12-06 06:30:33
Symbol() + '' throws TypeError: Cannot convert a Symbol value to a string While a known workaround is to use String(Symbol()) . This looks inconsistent with other primitives, including the ones that should almost never be coerced ( undefined and null ). How exactly does String differ from + '' (except it works)? Do specs explicitly specify that String should accept symbols? What were the motives to allow it in one way and disallow it in another? How exactly does String differ from + '' (except it works)? Do specs explicitly specify that String should accept symbols? They differ in the aspect

JavaScript Implicit Coercion

不想你离开。 提交于 2019-12-05 14:28:25
I'm reading a JavaScript tutorial on implicit and explicit coercion. What happens in the background with respect to implicit coercion? var a = "42"; var b = a * 1; //this is implicitly coerced to 42 -- the number Does implicit coercion ALWAYS coerce to a number? What if we wanted to do something a per the below Python example. I'm getting confused because other languages such as Python would give you a result as per below. a = "3"; b = 9; print a * b; //This would print 333333333 -- the string I will leave this here for your convenience to draw some conclusions as far as implicit coercion goes

Path::Class::File or ::Dir & Moose initialiazation and coercion

本秂侑毒 提交于 2019-12-04 09:32:53
Currently have: package Local; use warnings; use Moose; use Method::Signatures::Simple; use Path::Class::File; use Path::Class::Dir; method _build_path_class { my $str = $self->pathstr; return Path::Class::Dir->new($str) if (-d $str); return Path::Class::File->new($str); } has 'pathstr' => (is => 'rw', isa => 'Str', required => 1); has 'path' => ( is => 'rw', lazy => 1, #isa => 'Path::Class::File|Path::Class::Dir', #this didn't work isa => 'Object', builder => '_build_path_class', ); no Moose; __PACKAGE__->meta->make_immutable(); 1; It is working, so my $d = Local->new(pathstr => '/tmp')->path

Are there cases where a typedef is absolutely necessary?

老子叫甜甜 提交于 2019-12-03 10:30:12
问题 Consider the following excerpt from the safe bool idiom: typedef void (Testable::*bool_type)() const; operator bool_type() const; Is it possible to declare the conversion function without the typedef? The following does not compile: operator (void (Testable::*)() const)() const; 回答1: Ah, I just remembered the identity meta-function. It is possible to write operator typename identity<void (Testable::*)() const>::type() const; with the following definition of identity : template <typename T>

Casting vs. coercion in Python

流过昼夜 提交于 2019-12-03 08:14:23
问题 In the Python documentation and on mailing lists I see that values are sometimes "cast", and sometimes "coerced". What is the difference? 回答1: I think "casting" shouldn't be used for Python; there are only type conversion, but no casts (in the C sense). A type conversion is done e.g. through int(o) where the object o is converted into an integer (actually, an integer object is constructed out of o). Coercion happens in the case of binary operations: if you do x+y , and x and y have different

Scala 2.10, its impact on JSON libraries and case class validation/creation

走远了吗. 提交于 2019-12-03 05:40:31
问题 In Scala 2.10 apparently we're getting improved reflection. How will this impact lift-json, jerkson, sjson and friends? Furthermore, can we expect in the not too distant future a built-in JSON language feature a la Groovy's excellent GSON in Scala? The reason I ask is that I would dearly love to do: case class Foo(a: String, b: Int, bar: Bar) case class Bar(c: Int) val foo = Foo("hey", 10, Bar(23)) val json = foo.toJson without hoop jumping (i.e. boilerplate-ish prep work), even with