question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

big integer i/o handling

See original GitHub issue

If I create a GeoDataFrame like this:

import geopandas as gpd
import pandas as pd
from shapely.geometry import Point
d = {'id' : [3694063472, 3694063473],
     'geometry' : [Point((-122.278015,37.868995)),
                   Point((-122.278876,37.868895))]}
gdf = gpd.GeoDataFrame(d)
gdf

Returns:

			     geometry	        id
0	POINT (-122.278015 37.868995)	3694063472
1	POINT (-122.278876 37.868895)	3694063473

If I save to csv as a pandas Dataframe and read it back in:

pd.DataFrame(gdf).to_csv('test.csv', index=False)
pd.read_csv('test.csv')

Returns:

			     geometry	        id
0	POINT (-122.278015 37.868995)	3694063472
1	POINT (-122.278876 37.868895)	3694063473

Everything’s the same. But if I save to disk as a shapefile:

gdf.to_file('test_shp')
gpd.read_file('test_shp')

Returns:

	        id			     geometry
0	2147483647	POINT (-122.278015 37.868995)
1	2147483647	POINT (-122.278876 37.868895)

Writing my GeoDataFrame to disk and reading it back in results in my id field’s values silently being changed to 2147483647, the max value for a 32-bit signed integer. This is in geopandas 0.3.0 with fiona 1.7.11.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
jdmcbrcommented, Aug 4, 2018

This is fixed on fiona master now.

In [1]: gdf = gpd.read_file(gpd.datasets.get_path("nybb"))

In [2]: gdf["big_int"] = arange(5) + 12345678910

In [3]: gdf.to_file("test.shp")

In [4]: gdf_back = gpd.read_file("test.shp")

In [5]: gdf_back["big_int"]
Out[5]: 
0    12345678910
1    12345678911
2    12345678912
3    12345678913
4    12345678914
Name: big_int, dtype: int64
1reaction
sgilliescommented, Mar 28, 2018

@jorisvandenbossche I’ve got a solution (for Fiona 1.8) coming up. Meanwhile, I suggest this mapping of Python/Numpy types to Fiona/GDAL types:

Python/Numpy : Fiona/GDAL
-------------------------
int, int64, long : 'int:18'
int32 : 'int:9'
bool : 'bool' 
Read more comments on GitHub >

github_iconTop Results From Across the Web

BigInteger (Java Platform SE 7 ) - Oracle Help Center
Class BigInteger. Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in two's-complement notation (like Java's ...
Read more >
BigInteger Class in Java - GeeksforGeeks
BigInteger class is used for the mathematical operation which involves very big integer calculations that are outside the limit of all ...
Read more >
Java Scanner nextBigInteger() Method - Javatpoint
This is a Java Scanner class method which is used to scan the next token of the input as a BigInteger in the...
Read more >
Big Int in Go : Handling large numbers is easy - Dev Genius
To solve this problem, Go provides the Package “big” which implements arbitrary-precision arithmetic (big numbers). Description. The following numeric types are ...
Read more >
how to input a BigInteger type in java - Stack Overflow
Scanner scanner = new Scanner(fileOrOther); try{ BigInteger bigint = scanner.nextBigInteger(); } catch(NumberFormatException ex) { //handle Code here }.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found