Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deepcopy of CRS Object Fails to Initialize #2361

Closed
moss-xyz opened this issue Mar 26, 2024 · 8 comments
Closed

Deepcopy of CRS Object Fails to Initialize #2361

moss-xyz opened this issue Mar 26, 2024 · 8 comments
Milestone

Comments

@moss-xyz
Copy link

moss-xyz commented Mar 26, 2024

Description

Originally called this out in #1336

Using the deepcopy function from the copy module leads to a TypeError.

Code to reproduce

import cartopy
import copy

crs = cartopy.crs.CRS("3857")
crs_copy = copy.deepcopy(crs)

Traceback

Traceback (most recent call last)
Input In [1], in <cell line: 5>()
      2 import copy
      4 crs = cartopy.crs.CRS(\"3857\")
----> 5 crs_copy = copy.deepcopy(crs)

File c:\\Python\\lib\\copy.py:172, in deepcopy(x, memo, _nil)
    170                 y = x
    171             else:
--> 172                 y = _reconstruct(x, memo, *rv)
    174 # If is its own copy, don't memoize.
    175 if y is not x:

File c:\\Python\\lib\\copy.py:265, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    263 if deep and args:
    264     args = (deepcopy(arg, memo) for arg in args)
--> 265 y = func(*args)
    266 if deep:
    267     memo[id(x)] = y

TypeError: CRS.__init__() missing 1 required positional argument: 'proj4_params'"
Full environment definition

Operating system

Windows 11

Cartopy version

0.22.0

pip list

Don't judge please

Package                       Version
----------------------------- -----------
adagio                        0.2.4
adjustText                    1.0
affine                        2.3.1
aiodns                        3.0.0
aiohttp                       3.8.3
aiohttp-client-cache          0.9.1
aiosignal                     1.3.1
aiosqlite                     0.17.0
alabaster                     0.7.13
antlr4-python3-runtime        4.11.1
anyio                         4.1.0
apify-client                  1.6.0
apify-shared                  1.1.0
appdirs                       1.4.4
argon2-cffi                   21.3.0
argon2-cffi-bindings          21.2.0
asgiref                       3.7.2
asttokens                     2.0.5
async-generator               1.10
async-retriever               0.15.0
async-timeout                 4.0.2
attr                          0.3.1
attrs                         21.4.0
aws-requests-auth             0.4.3
azure-core                    1.29.5
azure-identity                1.10.0
azure-storage-blob            12.19.0
Babel                         2.13.1
backcall                      0.2.0
beautifulsoup4                4.11.1
bioframe                      0.6.1
bleach                        5.0.0
boto                          2.49.0
boto3                         1.33.10
botocore                      1.33.10
boxing                        0.1.4
bqplot                        0.12.39
branca                        0.6.0
Brotli                        1.0.9
build                         0.10.0
cachetools                    5.3.1
Cartopy                       0.22.0
cattrs                        22.2.0
cchardet                      2.1.7
cenpy                         1.0.1
CensusData                    1.15.post1
certifi                       2023.11.17
cffi                          1.15.0
cftime                        1.6.2
chardet                       5.0.0
charset-normalizer            2.0.12
click                         8.1.3
click-plugins                 1.1.1
cligj                         0.7.2
cloudpickle                   2.2.0
cloudscraper                  1.2.60
colorama                      0.4.5
colorlover                    0.3.0
colour                        0.1.5
contextily                    1.3.0
contourpy                     1.2.0
cryptography                  37.0.2
cssselect                     1.2.0
cufflinks                     0.17.3
cycler                        0.11.0
cykhash                       2.0.1
Cython                        0.29.35
cytoolz                       0.12.0
dask                          2022.12.0
datacompy                     0.10.1
debugpy                       1.6.0
decorator                     5.1.1
deepgram-sdk                  2.8.0
defusedxml                    0.7.1
deprecation                   2.1.0
dicttoxml2                    2.1.0
dill                          0.3.8
Django                        3.2.23
django-annoying               0.10.6
django-cors-headers           3.6.0
django-debug-toolbar          3.2.1
django-environ                0.10.0
django-extensions             3.1.0
django-filter                 2.4.0
django-model-utils            4.1.1
django-ranged-fileresponse    0.1.2
django-rq                     2.5.1
django-storages               1.12.3
django-user-agents            0.4.0
djangorestframework           3.13.1
docopt                        0.6.2
docutils                      0.18.1
drf-dynamic-fields            0.3.0
drf-flex-fields               0.9.5
drf-generators                0.3.0
earthengine-api               0.1.355
earthpy                       0.9.4
easyocr                       1.6.2
eerepr                        0.0.4
entrypoints                   0.4
esridump                      1.13.0
et-xmlfile                    1.1.0
exceptiongroup                1.0.4
executing                     0.8.3
expiringdict                  1.2.2
fastjsonschema                2.15.3
feedfinder2                   0.0.4
feedparser                    6.0.10
feltpy                        0.0.4
ffmpeg-python                 0.2.0
filelock                      3.13.1
Fiona                         1.8.21
focal-stats                   0.0.6
folium                        0.14.0
fonttools                     4.33.3
frozenlist                    1.3.3
fs                            2.4.16
fsspec                        2022.11.0
fugue                         0.8.4
fugue-sql-antlr               0.1.6
future                        0.18.2
fuzzywuzzy                    0.18.0
geedim                        1.7.2
geemap                        0.22.1
geetools                      0.6.14
geocoder                      1.38.1
geographiclib                 2.0
geograpy3                     0.2.7
geojson                       3.1.0
geopandas                     0.14.2
geopy                         2.3.0
google                        3.0.0
google-api-core               2.11.0
google-api-python-client      2.88.0
google-auth                   2.25.1
google-auth-httplib2          0.1.0
google-cloud                  0.34.0
google-cloud-core             2.3.2
google-cloud-resource-manager 1.10.2
google-cloud-storage          2.13.0
google-crc32c                 1.5.0
google-resumable-media        2.6.0
googleapis-common-protos      1.59.0
graphviz                      0.20.1
grpc-google-iam-v1            0.12.6
grpcio                        1.56.2
grpcio-status                 1.56.2
gtfs-functions                2.0.8
gtfs-kit                      5.2.3
h11                           0.13.0
h3                            3.7.4
h3pandas                      0.2.4
h5netcdf                      1.1.0
h5py                          3.7.0
htmlmin                       0.1.12
httpcore                      1.0.2
httplib2                      0.22.0
httpx                         0.25.2
humansignal-drf-yasg          1.21.9
hydrosignatures               0.1.1
idna                          3.3
ijson                         3.2.3
imageio                       2.31.5
imagesize                     1.4.1
importlib-metadata            4.13.0
imutils                       0.5.4
inequality                    1.0.0
inflection                    0.5.1
ipumspy                       0.3.0
ipyevents                     2.0.1
ipyfilechooser                0.6.0
ipykernel                     6.15.0
ipyleaflet                    0.17.3
ipython                       8.4.0
ipython-genutils              0.2.0
ipytree                       0.2.2
ipywidgets                    7.7.0
isodate                       0.6.1
isoweek                       1.3.3
itsdangerous                  2.1.2
jaraco.classes                3.3.0
jedi                          0.18.1
jellyfish                     1.0.3
jenkspy                       0.3.3
jieba3k                       0.35.1
Jinja2                        3.1.2
jmespath                      1.0.1
joblib                        1.2.0
Js2Py                         0.71
json2html                     1.3.0
jsonlines                     1.2.0
jsonpickle                    1.5.2
jsonschema                    3.2.0
jupyter                       1.0.0
jupyter-client                7.3.4
jupyter-console               6.4.3
jupyter-core                  4.10.0
jupyterlab-pygments           0.2.2
jupyterlab-widgets            1.1.0
keplergl                      0.3.2
keyring                       24.2.0
kiwisolver                    1.4.3
label-studio                  1.10.0
label-studio-converter        0.0.57
label-studio-tools            0.0.3
launchdarkly-server-sdk       7.5.0
libpysal                      4.9.2
llvmlite                      0.41.1
locket                        1.0.0
lockfile                      0.12.2
loguru                        0.6.0
lxml                          4.9.1
mapclassify                   2.6.1
markdown-it-py                3.0.0
MarkupSafe                    2.1.1
matplotlib                    3.7.4
matplotlib-inline             0.1.3
matplotlib-scalebar           0.8.1
mdurl                         0.1.2
mercantile                    1.2.1
mistune                       0.8.4
momepy                        0.5.4
more-itertools                10.0.0
mpmath                        1.2.1
msal                          1.18.0
msal-extensions               1.0.0
msgraph-core                  0.2.2
multidict                     6.0.3
multiprocess                  0.70.16
munch                         2.5.0
nbclient                      0.6.4
nbconvert                     6.5.0
nbformat                      5.4.0
nest-asyncio                  1.5.5
netCDF4                       1.6.2
networkx                      3.2.1
newspaper3k                   0.2.8
ninja                         1.11.1
nltk                          3.6.7
notebook                      6.4.12
numba                         0.58.1
numpy                         1.24.3
oauth2                        1.9.0.post1
ogr2osm                       1.2.0
onedrivesdk                   2.0.1
openai                        0.27.8
opencv-contrib-python         4.5.5.62
opencv-python-headless        4.5.4.60
openpyxl                      3.0.10
ordered-set                   4.0.2
osmium                        3.6.0
osmnx                         1.9.1
OSMPythonTools                0.3.5
outcome                       1.2.0
OWSLib                        0.27.2
packaging                     21.3
pandas                        1.5.2
pandocfilters                 1.5.0
parso                         0.8.3
partd                         1.3.0
partridge                     1.1.1
patsy                         0.5.3
pdf2image                     1.16.0
pdfminer.six                  20221105
pdfquery                      0.4.3
pendulum                      2.1.2
pickleshare                   0.7.5
Pillow                        10.1.0
pip                           23.3.2
pip-system-certs              4.0
pipwin                        0.5.2
pkginfo                       1.9.6
platformdirs                  2.5.4
plotly                        5.14.1
portalocker                   2.5.1
prometheus-client             0.14.1
prompt-toolkit                3.0.29
proto-plus                    1.22.3
protobuf                      4.23.2
psutil                        5.9.1
psycopg2-binary               2.9.6
PuLP                          2.7.0
pure-eval                     0.2.2
py3dep                        0.15.1
pyan3                         1.1.1
pyarrow                       10.0.1
pyasn1                        0.5.0
pyasn1-modules                0.3.0
pycairo                       1.24.0
pycallgraph2                  1.1.3
pycares                       4.2.2
pyclipper                     1.3.0.post4
pycountry                     22.3.5
pycparser                     2.21
PyCRS                         1.0.2
pydantic                      1.10.13
pydeck                        0.8.0
PyExifTool                    0.5.5
pygeohydro                    0.13.7
pygeoogc                      0.15.1
pygeos                        0.14
pygeoutils                    0.15.0
Pygments                      2.15.1
pygris                        0.1.5
pyjsparser                    2.7.1
PyJWT                         2.4.0
PyKrige                       1.7.1
pylatexenc                    2.10
pyLodStorage                  0.4.14
PyMuPDF                       1.20.2
pynhd                         0.13.7
pyOpenSSL                     22.0.0
pyparsing                     3.0.9
PyPDF2                        2.11.1
pyperclip                     1.8.2
PyPrind                       2.11.3
pyproj                        3.4.1
pyproject_hooks               1.0.0
pyquery                       1.4.3
pyRFC3339                     1.1
pyrobuf                       0.9.3
pyrosm                        0.6.2
pyrsistent                    0.18.1
pyshp                         2.3.1
pySmartDL                     1.3.4
PySocks                       1.7.1
pytesseract                   0.3.10
python-bidi                   0.4.2
python-box                    7.0.1
python-dateutil               2.8.2
python-forge                  18.6.0
python-json-logger            2.0.4
python-Levenshtein            0.12.2
python-rapidjson              1.10
pytz                          2022.1
pytz-deprecation-shim         0.1.0.post0
pytzdata                      2020.1
pyvalhalla                    3.2.0
PyWavelets                    1.4.1
pywin32                       304
pywin32-ctypes                0.2.2
pywinpty                      2.0.5
PyYAML                        6.0.1
pyzmq                         23.2.0
qpd                           0.4.3
qtconsole                     5.3.1
QtPy                          2.1.0
rasterio                      1.3.9
rasterstats                   0.19.0
ratelim                       0.1.6
rdflib                        7.0.0
readme-renderer               40.0
redis                         3.5.3
regex                         2023.6.3
requests                      2.31.0
requests-cache                0.9.7
requests-file                 1.5.1
requests-futures              1.0.0
requests-toolbelt             0.9.1
rfc3986                       2.0.0
rich                          13.4.2
rioxarray                     0.15.0
roman                         3.3
routingpy                     1.2.1
rq                            1.10.1
rsa                           4.9
Rtree                         1.0.0
rules                         2.2
s3transfer                    0.8.2
scalebar                      0.1.1
scikit-image                  0.19.3
scikit-learn                  1.1.3
scipy                         1.9.3
scooby                        0.7.2
scrapetube                    2.5.1
seaborn                       0.12.1
selenium                      4.2.0
semver                        2.13.0
Send2Trash                    1.8.2
sentry-sdk                    1.38.0
setuptools                    68.0.0
sgmllib3k                     1.0.0
shapely                       2.0.1
simplejson                    3.18.0
six                           1.16.0
sklearn                       0.0.post5
sniffio                       1.2.0
snowballstemmer               2.2.0
snuggs                        1.4.7
sortedcontainers              2.4.0
soupsieve                     2.3.2.post1
SPARQLWrapper                 1.8.5
Sphinx                        7.2.6
sphinx-rtd-theme              1.3.0
sphinxcontrib-applehelp       1.0.7
sphinxcontrib-devhelp         1.0.5
sphinxcontrib-htmlhelp        2.0.4
sphinxcontrib-jquery          4.1
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.6
sphinxcontrib-serializinghtml 1.1.9
sqlglot                       16.0.0
sqlparse                      0.4.4
stack-data                    0.3.0
statsmodels                   0.13.5
sympy                         1.11.1
tabulate                      0.9.0
tenacity                      8.1.0
terminado                     0.15.0
thefuzz                       0.19.0
threadpoolctl                 3.1.0
tifffile                      2022.10.10
tiktoken                      0.4.0
tinycss2                      1.1.1
tinysegmenter                 0.3
tldextract                    5.1.1
tomli                         2.0.1
toolz                         0.12.0
torch                         1.13.0
torchaudio                    0.13.0
torchvision                   0.14.0
tornado                       6.1
tqdm                          4.64.0
traitlets                     5.3.0
traittypes                    0.2.1
triad                         0.9.0
trio                          0.21.0
trio-websocket                0.9.2
twine                         4.0.2
typing_extensions             4.8.0
tzdata                        2022.1
tzlocal                       4.2
ua-parser                     0.18.0
ujson                         5.6.0
unicode                       2.9
Unidecode                     1.3.6
uritemplate                   4.1.1
url-normalize                 1.4.3
urllib3                       1.26.18
user-agents                   2.2.0
utm                           0.7.0
wcwidth                       0.2.5
webencodings                  0.5.1
websockets                    11.0.3
wheel                         0.40.0
widgetsnbextension            3.6.0
win32-setctime                1.1.0
wrapt                         1.16.0
wsproto                       1.1.0
xarray                        2023.8.0
xmljson                       0.2.0
xyzservices                   2023.5.0
yarl                          1.8.2
yelp                          1.0.2
zipp                          3.15.0
@dopplershift
Copy link
Contributor

It looks like this is being worked in #2356. Testing that PR and seeing if it addresses your problem would be helpful.

@moss-xyz
Copy link
Author

Ah indeed, I see that we discovered the issue around the same time!

Never tested a dev branch of a module before, mind giving me a quick guide? Should I just download a local copy of the branch and import it manually to my script to see if it works?

@lgolston
Copy link
Contributor

lgolston commented Mar 27, 2024

Hello @moss-xyz, definitely discovered the issue from reading your original report :)

To install the dev branch, the instructions at https://scitools.org.uk/cartopy/docs/latest/installing.html#required-dependencies are good, except adding two lines below to pull/checkout this specific branch for testing:

git clone https://github.com/SciTools/cartopy.git
cd cartopy
git fetch origin pull/2356/head:deepcopy-crs-bug
git checkout deepcopy-crs-bug
conda env create -f environment.yml
conda activate cartopy-dev
pip install -e .

@moss-xyz
Copy link
Author

@lgolston thank you for the guide! I'm relatively new at conda so might be doing something wrong, but running the same code from original post I made at the top^ in the cartopy-dev env seems to still be leading to the same error message, and I believe the traceback is the same too:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\david\miniconda3\envs\cartopy-dev\Lib\copy.py", line 97, in copy
    return _reconstruct(x, None, *rv)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\david\miniconda3\envs\cartopy-dev\Lib\copy.py", line 253, in _reconstruct
    y = func(*args)
        ^^^^^^^^^^^
TypeError: CRS.__init__() missing 1 required positional argument: 'proj4_params'

@greglucas
Copy link
Contributor

@moss-xyz, even easier is to install from the specific git branch into your current environment. pip install git+https://github.com/SciTools/cartopy.git (adding @branch-name to the end if you want to test a specific branch).

When I tested the original code block out at the top with current main there are no warnings, so I think this was fixed by the linked PR.

@QuLogic QuLogic added this to the 0.23 milestone Apr 22, 2024
@moss-xyz
Copy link
Author

@greglucas finally got around to testing this out, seems like it is indeed fixed, thank you for your work on this!

@greglucas
Copy link
Contributor

@greglucas finally got around to testing this out, seems like it is indeed fixed, thank you for your work on this!

Thank you @lgolston who actually did the work!

Glad it solved the issue for you.

@moss-xyz
Copy link
Author

@greglucas @lgolston @dopplershift just wanted to thank you again for all of your help here: I was able to push out the package I was developing that required this functionality yesterday! You can check it out here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants