Skip to content

error "from_cf" with numpy.float32 types #773

@pgamez

Description

@pgamez

Code Sample, a copy-pastable example if possible

import pyproj as pj
import numpy as np

cf = {
    'grid_mapping_name': 'lambert_conformal_conic',
    'standard_parallel': np.array([60, 30], dtype='f4'),
    'longitude_of_central_meridian': np.float32(0),
    'latitude_of_projection_origin': 45,
}

crs = pj.CRS.from_cf(cf)
print(crs.to_proj4())

Problem description

TypeError: Object of type float32 is not JSON serializable

I expect that the library works with numpy types as well

Expected Output

+proj=lcc +lat_0=45 +lon_0=0 +lat_1=60 +lat_2=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +type=crs

Environment Information

pyproj info:
    pyproj: 3.0.0.post1
      PROJ: 7.2.0
  data dir: /home/pgamez/miniconda3/envs/devel/share/proj
user_data_dir: /home/pgamez/.local/share/proj

System:
    python: 3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 23:21:18)  [GCC 9.3.0]
executable: /home/pgamez/miniconda3/envs/devel/bin/python
   machine: Linux-5.10.16-arch1-1-x86_64-with-glibc2.10

Python deps:
       pip: 21.0.1
setuptools: 49.6.0.post20210108
    Cython: None

Installation method

  • conda, pip wheel, from source, etc...

Conda environment information (if you installed with conda):


Environment (conda list):
$ conda list proj
# packages in environment at /home/pgamez/miniconda3/envs/devel:
#
# Name                    Version                   Build  Channel
proj                      7.2.0                h277dcde_2    conda-forge
pyproj                    3.0.0.post1      py38h8df5ac0_0    conda-forge

Details about conda and system ( conda info ):
$ conda info

     active environment : devel
    active env location : /home/pgamez/miniconda3/envs/devel
            shell level : 1
       user config file : /home/pgamez/.condarc
 populated config files : /home/pgamez/.condarc
          conda version : 4.9.2
    conda-build version : not installed
         python version : 3.8.5.final.0
       virtual packages : __glibc=2.33=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /home/pgamez/miniconda3  (writable)
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/pgamez/miniconda3/pkgs
                          /home/pgamez/.conda/pkgs
       envs directories : /home/pgamez/miniconda3/envs
                          /home/pgamez/.conda/envs
               platform : linux-64
             user-agent : conda/4.9.2 requests/2.25.1 CPython/3.8.5 Linux/5.10.16-arch1-1 arch/ glibc/2.33
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions