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

~~Fix warnings~~ Fix numpy 2.0 failures #97

Merged
merged 5 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ updates:
interval: "daily"
labels:
- "Bot"
groups:
github-actions:
patterns:
- '*'
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
os: [windows-latest, ubuntu-latest, macos-latest]
fail-fast: false

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- requirements-dev.txt

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.8
rev: v0.4.9
hooks:
- id: ruff

Expand Down
2 changes: 2 additions & 0 deletions pocean/dsg/trajectoryProfile/cr.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
get_ncdata_from_series,
nativize_times,
normalize_countable_array,
upscale_int8,
)


Expand Down Expand Up @@ -323,6 +324,7 @@ def to_dataframe(self, clean_cols=True, clean_rows=True, **kwargs):
df_data[dnam] = vdata

df = pd.DataFrame(df_data)
df = upscale_int8(df)

# Drop all data columns with no data
if clean_cols:
Expand Down
6 changes: 3 additions & 3 deletions pocean/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_generic_masked_bad_min_max_value(self):
# to make sure it doesn't error
b = ncd.createVariable('imabyte', 'b')
b.valid_min = 0
b.valid_max = 600 # this is over a byte and thus invalid
b.valid_max = np.int16(600) # this is over a byte and thus invalid
b[:] = 3
r = generic_masked(b[:], attrs=ncd.vatts(b.name))
assert np.all(r.mask == False) # noqa
Expand Down Expand Up @@ -203,7 +203,7 @@ def test_normalization_of_string_arrays_netcdf4(self):

# Single str (no dimension)
ncd.createVariable('single_str', str)
ncd.createVariable('single_unicode_', np.unicode_)
ncd.createVariable('single_unicode_', np.str_)
ncd.createVariable('single_U', '<U1')
ncd.createVariable('single_S', 'S1', ('n',))

Expand All @@ -216,7 +216,7 @@ def test_normalization_of_string_arrays_netcdf4(self):

# Array of str
ncd.createVariable('many_str', str, ('n',))
ncd.createVariable('many_unicode_', np.unicode_, ('n',))
ncd.createVariable('many_unicode_', np.str_, ('n',))
ncd.createVariable('many_U', '<U1', ('n',))
ncd.createVariable('many_S', 'S1', ('n', 'n',))

Expand Down
7 changes: 7 additions & 0 deletions pocean/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,13 @@ def dict_update(d, u):
return d


def upscale_int8(df):
"""Numpy 2.0 no linger upcast dtypes.
In order to preserve the data's original dtype we upcast it here after reading it.

"""
return df.astype({col: "int16" for col in df.columns[df.dtypes == "int8"]})

class JSONEncoder(json.JSONEncoder):

def default(self, obj):
Expand Down