@@ -232,7 +232,7 @@ private[csv] object CSVTypeCast {
232232 nullable : Boolean = true ,
233233 options : CSVOptions = CSVOptions ()): Any = {
234234
235- if (datum == options.nullValue && nullable ) {
235+ if (nullable && datum == options.nullValue) {
236236 null
237237 } else {
238238 castType match {
@@ -241,26 +241,22 @@ private[csv] object CSVTypeCast {
241241 case _ : IntegerType => datum.toInt
242242 case _ : LongType => datum.toLong
243243 case _ : FloatType =>
244- if (datum == options.nanValue) {
245- Float .NaN
246- } else if (datum == options.negativeInf) {
247- Float .NegativeInfinity
248- } else if (datum == options.positiveInf) {
249- Float .PositiveInfinity
250- } else {
251- Try (datum.toFloat)
252- .getOrElse(NumberFormat .getInstance(Locale .getDefault).parse(datum).floatValue())
244+ datum match {
245+ case options.nanValue => Float .NaN
246+ case options.negativeInf => Float .NegativeInfinity
247+ case options.positiveInf => Float .PositiveInfinity
248+ case _ =>
249+ Try (datum.toFloat)
250+ .getOrElse(NumberFormat .getInstance(Locale .getDefault).parse(datum).floatValue())
253251 }
254252 case _ : DoubleType =>
255- if (datum == options.nanValue) {
256- Double .NaN
257- } else if (datum == options.negativeInf) {
258- Double .NegativeInfinity
259- } else if (datum == options.positiveInf) {
260- Double .PositiveInfinity
261- } else {
262- Try (datum.toDouble)
263- .getOrElse(NumberFormat .getInstance(Locale .getDefault).parse(datum).doubleValue())
253+ datum match {
254+ case options.nanValue => Double .NaN
255+ case options.negativeInf => Double .NegativeInfinity
256+ case options.positiveInf => Double .PositiveInfinity
257+ case _ =>
258+ Try (datum.toDouble)
259+ .getOrElse(NumberFormat .getInstance(Locale .getDefault).parse(datum).doubleValue())
264260 }
265261 case _ : BooleanType => datum.toBoolean
266262 case dt : DecimalType =>
0 commit comments